Skip to content

Add protobuf support and refactor WebSocket message handling#40

Merged
74th merged 5 commits intodevelopfrom
feat/nanopb
Apr 19, 2026
Merged

Add protobuf support and refactor WebSocket message handling#40
74th merged 5 commits intodevelopfrom
feat/nanopb

Conversation

@74th
Copy link
Copy Markdown
Owner

@74th 74th commented Apr 19, 2026

This pull request migrates the CoreS3 firmware and server communication protocol from a custom binary format to a Protocol Buffers (protobuf)-based WebSocket protocol. It updates both documentation and code to reflect the new protobuf message structure, replaces legacy enums and message handling with generated protobuf types, and adds build tooling for protobuf code generation for both Python and firmware. The changes standardize and modernize the protocol, improving maintainability and interoperability.

Protocol migration to protobuf:

  • The WebSocket protocol now uses a single protobuf WebSocketMessage per binary frame, replacing the previous hand-written binary header and enums. All message kinds (audio, state, servo, etc.) are now defined in protobuf/websocket-message.proto and referenced in code via generated types. [1] [2] [3] [4] [5]
  • Documentation (AGENTS.md, docs/websocket_protocols_ja.md) is updated to describe the protobuf-based protocol, including message structures, enums, and field names, with legacy binary protocol references removed. [1] [2] [3] [4] [5] [6]

Firmware and codebase updates:

  • All protocol enums, message types, and payload parsing in the firmware (protocols.hpp, listening.hpp, speaking.hpp, servo.hpp) are replaced with generated protobuf types (e.g., stackchan_websocket_v1_MessageType, stackchan_websocket_v1_ServoOperation). Helper functions for encoding/decoding protobuf messages and handling audio/servo messages are introduced. [1] [2] [3] [4] [5] [6]
  • Sequence numbers for messages are expanded from uint16_t to uint32_t to match the protobuf field definition. [1] [2]

Build and tooling improvements:

  • A new Makefile workflow is added for protobuf code generation for both Python server (protobuf-python) and firmware (protobuf-firmware), including cleaning targets. The firmware uses nanopb for C/C++ protobuf support.
  • The generated protobuf C source (websocket-message.pb.c) is added for firmware compilation.

74th added 5 commits April 19, 2026 14:56
…ket handling

- Updated `pyproject.toml` to include `grpcio-tools` and `protobuf` dependencies.
- Added generated protobuf files for WebSocket messages in `stackchan_server/generated_protobuf`.
- Implemented `protobuf_ws.py` for encoding and parsing WebSocket messages.
- Refactored `speak.py` to utilize new protobuf message encoding for audio WAV messages.
- Updated `ws_proxy.py` to handle protobuf messages and removed legacy struct-based message handling.
- Enhanced error handling for invalid protobuf messages in WebSocket communication.
@74th 74th merged commit 122e82a into develop Apr 19, 2026
1 check passed
@74th 74th deleted the feat/nanopb branch April 19, 2026 06:36
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