Skip to content

Add WebSocket ultrasonic JSON parsing and preserve raw WS send behavior#7

Draft
musfaagv wants to merge 1 commit into
codex/add-usewebsocket-hook-implementationfrom
codex/task-title-18x8u2
Draft

Add WebSocket ultrasonic JSON parsing and preserve raw WS send behavior#7
musfaagv wants to merge 1 commit into
codex/add-usewebsocket-hook-implementationfrom
codex/task-title-18x8u2

Conversation

@musfaagv
Copy link
Copy Markdown
Owner

Motivation

  • Enable first-class support for devices that send JSON over WebSocket (specifically ultrasonic sensor payloads) while keeping existing line-based serial parsing intact.
  • Keep raw incoming messages logged to the console store for debugging and provide a non-blocking UX hint when WS JSON looks invalid.
  • Allow sending exact JSON commands (e.g. LED control) over WebSocket without auto-appending a newline, while preserving newline behavior for serial connections.

Description

  • Add src/utils/wsPayload.ts with parseUltrasonicPayload() to parse { "type": "ultrasonic", "cm": number, "inch": number } payloads and return numeric values.
  • Update src/App.tsx to always call consoleStore.addIncoming(line), detect ultrasonic JSON via parseUltrasonicPayload(), auto-set series to ['cm','inch'] on the first valid ultrasonic message, append [cm, inch] to the chart, and otherwise fall back to parseHeaderLine/parseDataLine line parsing.
  • Update console components: add connectionType prop to SerialConsole and ConsoleInput; in WebSocket mode outgoing messages are sent verbatim (no appended \n), while serial mode retains existing newline behavior; ConsoleInput shows a non-blocking WS JSON validation hint when the input looks like invalid JSON.
  • Add unit tests src/utils/__tests__/wsPayload.test.ts covering valid ultrasonic payloads, non-ultrasonic JSON, missing numeric fields, and invalid JSON.

Testing

  • Ran static type check with npm run typecheck and it completed successfully.
  • Ran lint with npm run lint and it completed successfully.
  • Ran unit tests for the new parser with npm run test -- src/utils/__tests__/wsPayload.test.ts and all tests passed (4 tests).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant