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

@@ -36,6 +36,16 @@ FastAccelStepper *g_pStepperPen = NULL;
// make Objects
Servo penServo;
SerialCommand SCmd;
#ifdef ESP32
SerialCommand g_BLECmd;
SerialCommand g_WifiCmd;
#endif
namespace
{
SerialCommand *g_pActiveParser = &SCmd;
ProtocolTransport g_activeTransport = PROTOCOL_TRANSPORT_SERIAL;
}
// create Buttons
#ifdef prgButton
@@ -63,6 +73,52 @@ float fROT_STEP_CORRECTION = 16.0 / rotMicrostep; // devide EBB-Coordinates by t
float fPEN_STEP_CORRECTION = 16.0 / penMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
boolean g_bMotorsEnabled = 0;
void setActiveProtocolContext(SerialCommand *parser, ProtocolTransport transport)
{
if (parser != NULL)
{
g_pActiveParser = parser;
}
g_activeTransport = transport;
}
char *nextCommandArg()
{
return g_pActiveParser->next();
}
void protocolWrite(const char *message)
{
if (message == NULL)
{
return;
}
#ifdef ESP32
if (g_activeTransport == PROTOCOL_TRANSPORT_BLE)
{
if (bleProtocolWrite(message))
{
return;
}
}
if (g_activeTransport == PROTOCOL_TRANSPORT_WIFI)
{
if (wifiProtocolWrite(message))
{
return;
}
}
#endif
Serial.print(message);
}
void protocolWrite(const String &message)
{
protocolWrite(message.c_str());
}
// Stepper Test
#ifdef TEST
// #define dirPinStepper 16
@@ -77,6 +133,7 @@ void setup()
Log("Starting...");
makeComInterface();
initHardware();
startBleInterface();
startWebInterface();
}
@@ -134,8 +191,11 @@ void loop()
}
#else
// moveOneStep();
setActiveProtocolContext(&SCmd, PROTOCOL_TRANSPORT_SERIAL);
SCmd.readSerial();
handleBleInterface();
handleWebInterface();
handleWifiProtocolInterface();
#endif
#ifdef penToggleButton