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
// 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"
#endif //_VERSION_ESP3D_H

View File

@ -86,25 +86,35 @@ void ESP3DSerialService::receiveCb() {
if (!started()) {
return;
}
//take mutex
if (xSemaphoreTake(_mutex, portMAX_DELAY)) {
uint32_t now = millis();
while ((millis() - now) < SERIAL_COMMUNICATION_TIMEOUT) {
if (Serials[_serialIndex]->available()) {
_buffer[_buffer_size] = Serials[_serialIndex]->read();
now = millis();
// Get expected len of data
size_t count = Serials[_serialIndex]->available();
//loop until each byte is handled
while (count > 0) {
int data = Serials[_serialIndex]->read();
// If read() failed we leave
if (data == -1) {
esp3d_log_e("Serial read failed unexpectedly");
break; // only break to release mutex
}
//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') {
if (_buffer_size > ESP3D_SERIAL_BUFFER_SIZE || _buffer[_buffer_size - 1] == '\n') {
flushBuffer();
}
}
}
}
//release mutex
xSemaphoreGive(_mutex);
} else {
esp3d_log_e("Mutex not taken");

View File

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