Refactor SerialCommand to support Stream interface and improve command handling

- Added readSerial(Stream &stream) method to allow reading from any Stream-compatible transport.
- Introduced readChar(char inChar) method for processing individual characters.
- Updated command matching logic to enhance debugging output.
- Improved buffer handling and command execution flow.

Enhance platformio.ini for better compatibility and added libraries

- Added NimBLE-Arduino and WebSockets libraries for BLE and WiFi support.
- Updated upload and monitor ports for better compatibility with macOS.

Integrate WiFi and BLE protocol interfaces

- Implemented startWebInterface() to initialize WiFi protocol alongside existing web server.
- Added BLE support with a new EggBot BLE Serial Protocol for command handling over BLE.
- Created WebSocket server for WiFi communication, maintaining compatibility with existing command protocols.

Refactor command handling in Functions.cpp

- Replaced direct Serial.print calls with protocolWrite for consistent output handling.
- Updated command registration to use a lambda function for better readability and maintainability.

Add documentation for EggBot protocols

- Created separate markdown files for BLE, WiFi, and Serial protocols detailing command structures and usage.
- Provided examples of command transactions for better developer guidance.

Implement BLE and WiFi protocol handling in respective source files

- Developed BLE_Interface.cpp for managing BLE connections and data transmission.
- Created WiFi_Protocol.cpp for handling WebSocket communication and data reception.
This commit is contained in:
2026-02-24 22:00:26 +01:00
parent 3487d7c263
commit a1ffcb08ca
15 changed files with 1115 additions and 83 deletions

View File

@@ -0,0 +1,46 @@
# EggBot BLE Serial Protocol
## Scope
This transport exposes the same EggBot command protocol as serial, but over BLE GATT.
- Protocol commands and responses are unchanged.
- Framing is unchanged (`\r` command terminator, `\r\n` response lines).
## BLE GATT Profile
- Device name: `EggDuino`
- Service UUID: `6e400001-b5a3-f393-e0a9-e50e24dcca9e`
- RX characteristic (host -> EggDuino): `6e400002-b5a3-f393-e0a9-e50e24dcca9e`
- Properties: `Write`, `Write Without Response`
- TX characteristic (EggDuino -> host): `6e400003-b5a3-f393-e0a9-e50e24dcca9e`
- Properties: `Notify`, `Read`
## Data Model
- Host writes plain ASCII command bytes to RX.
- Firmware parses bytes with the same EggBot command parser used for USB serial.
- Firmware sends responses via TX notifications.
- Long responses are segmented into BLE-sized notification chunks; host must reassemble by bytes and parse lines by `\r\n`.
## Compatibility Rules
- A BLE client must send commands exactly as serial hosts do.
- Each command must end with `\r`.
- Data-returning commands (`QP`, `QB`, `QN`, `QL`) return a value line before final status (`OK\r\n`).
- Unknown/invalid command format returns `unknown CMD\r\n`.
## Example BLE Transactions
Version query:
- Write RX: `v\r`
- Notify TX: `EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.6a\r\n`
Move command:
- Write RX: `SM,100,0,200\r`
- Notify TX: `OK\r\n`
Query node count:
- Write RX: `QN\r`
- Notify TX: `<number>\r\n`
- Notify TX: `OK\r\n`
## Operational Notes
- BLE receive bytes are queued and parsed in the main firmware loop.
- If the BLE RX queue overruns, excess bytes are dropped and a log entry is generated.
- BLE and USB serial can coexist; each command response is routed to the transport that received that command.