Improve serial Service thanks @rondlh
Some checks failed
build-ci / build (push) Failing after 3h9m56s

Bump version due to latest fixes
This commit is contained in:
Luc 2025-03-19 11:37:34 +08:00
parent 8104887442
commit 5501e78bcb
3 changed files with 28 additions and 18 deletions

View File

@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H #define _VERSION_ESP3D_H
// version and sources location // version and sources location
#define FW_VERSION "3.0.0.3b1" #define FW_VERSION "3.0.0.4b1"
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
#endif //_VERSION_ESP3D_H #endif //_VERSION_ESP3D_H

View File

@ -86,25 +86,35 @@ void ESP3DSerialService::receiveCb() {
if (!started()) { if (!started()) {
return; return;
} }
//take mutex
if (xSemaphoreTake(_mutex, portMAX_DELAY)) { if (xSemaphoreTake(_mutex, portMAX_DELAY)) {
uint32_t now = millis(); // Get expected len of data
while ((millis() - now) < SERIAL_COMMUNICATION_TIMEOUT) { size_t count = Serials[_serialIndex]->available();
if (Serials[_serialIndex]->available()) {
_buffer[_buffer_size] = Serials[_serialIndex]->read(); //loop until each byte is handled
now = millis(); while (count > 0) {
if (esp3d_string::isRealTimeCommand(_buffer[_buffer_size])) { int data = Serials[_serialIndex]->read();
flushChar(_buffer[_buffer_size]);
_buffer[_buffer_size] = '\0'; //remove realtime command from buffer // If read() failed we leave
} else { if (data == -1) {
_buffer_size++; esp3d_log_e("Serial read failed unexpectedly");
if (_buffer_size > ESP3D_SERIAL_BUFFER_SIZE || break; // only break to release mutex
_buffer[_buffer_size - 1] == '\n') { }
flushBuffer(); //take the char
} count--;
_buffer[_buffer_size] = (uint8_t)data;
//check what next step is
if (esp3d_string::isRealTimeCommand(_buffer[_buffer_size])) {
flushChar(_buffer[_buffer_size]);
_buffer[_buffer_size] = '\0'; //remove realtime command from buffer
} else {
_buffer_size++;
if (_buffer_size > ESP3D_SERIAL_BUFFER_SIZE || _buffer[_buffer_size - 1] == '\n') {
flushBuffer();
} }
} }
} }
//release mutex
xSemaphoreGive(_mutex); xSemaphoreGive(_mutex);
} else { } else {
esp3d_log_e("Mutex not taken"); esp3d_log_e("Mutex not taken");
@ -256,4 +266,4 @@ bool ESP3DSerialService::reset() {
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || #endif // COMMUNICATION_PROTOCOL == RAW_SERIAL ||
// defined(ESP_SERIAL_BRIDGE_OUTPUT) // defined(ESP_SERIAL_BRIDGE_OUTPUT)
#endif // ARDUINO_ARCH_ESP32 #endif // ARDUINO_ARCH_ESP32

View File

@ -1,3 +1,3 @@
{ {
"version": "3.0.0.3b1" "version": "3.0.0.4b1"
} }