Skip to content

Conversation

@SJ7F
Copy link
Contributor

@SJ7F SJ7F commented Oct 30, 2025

Summary

This pull request adds support for decoding float32 values encoded with COBS. Each COBS packet can contain any number of float32 values, each updating a different channel.

Motivation & Context

Allows for faster data logging.
COBS support was listed on the roadmap.

Changes

  • Added dropdown in ConnectModal to select between the ascii (original mode, default) and cobs-f32 modes.
  • Added COBS decoding logic

How to Test

Run the following code (requires Arduino.h) on a microcontroller (such as the esp32), and then connect to it using this serial plotter in COBS float32 mode. It should plot three sine waves.

(disclaimer: this test code was written by GPT-5)
#include <Arduino.h>

// Simple COBS encoder
size_t cobsEncode(const uint8_t *input, size_t length, uint8_t *output) {
  size_t read_index = 0, write_index = 1, code_index = 0;
  uint8_t code = 1;

  while (read_index < length) {
    if (input[read_index] == 0) {
      output[code_index] = code;
      code_index = write_index++;
      code = 1;
      read_index++;
    } else {
      output[write_index++] = input[read_index++];
      code++;
      if (code == 0xFF) {
        output[code_index] = code;
        code_index = write_index++;
        code = 1;
      }
    }
  }

  output[code_index] = code;
  return write_index;
}

void setup() {
  Serial.begin(115200);
  while (!Serial);
}

void loop() {
  static uint32_t t = 0;

  // Generate three float values varying with sine waves
  float f1 = sinf(t * 0.01f) * 1.0f;       // amplitude 1.0
  float f2 = sinf(t * 0.008f + 1.0f) * 2.0f; // amplitude 2.0, phase shifted
  float f3 = sinf(t * 0.012f + 2.0f) * 0.5f; // amplitude 0.5, phase shifted

  // Pack floats into a contiguous buffer
  uint8_t rawData[12];
  memcpy(rawData, &f1, 4);
  memcpy(rawData + 4, &f2, 4);
  memcpy(rawData + 8, &f3, 4);

  // Encode with COBS
  uint8_t encoded[16];
  size_t encodedLength = cobsEncode(rawData, sizeof(rawData), encoded);

  // Append COBS frame delimiter
  encoded[encodedLength++] = 0x00;

  // Transmit over Serial
  Serial.write(encoded, encodedLength);

  // Wait 100ms
  delay(100);
  t++;
}

Checklist

  • I ran npm run lint and fixed any issues
  • I ran npm run typecheck (TypeScript) with no errors
  • I ran npm test and tests pass
  • I ran npm run test:coverage if code paths changed significantly
  • I added/updated tests where appropriate
  • I updated docs/README if needed
  • No breaking changes without clear migration notes

Additional Notes

GPT-5 was used to help write cobsDecoder.ts
handleIncomingLine (in src/App.tsx) ought to be refactored at some point to remove the hack I added on line 194 of src/hooks/userSerial.ts

@SJ7F SJ7F changed the title Add COBS-encoded float32 support Feature: Add COBS-encoded float32 support Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant