Skip to content

Commit 5501e78

Browse files
committed
Improve serial Service thanks @rondlh
Bump version due to latest fixes
1 parent 8104887 commit 5501e78

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

esp3d/src/include/esp3d_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define _VERSION_ESP3D_H
2323

2424
// version and sources location
25-
#define FW_VERSION "3.0.0.3b1"
25+
#define FW_VERSION "3.0.0.4b1"
2626
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
2727

2828
#endif //_VERSION_ESP3D_H

esp3d/src/modules/serial/serial_service_esp32.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,35 @@ void ESP3DSerialService::receiveCb() {
8686
if (!started()) {
8787
return;
8888
}
89+
//take mutex
8990
if (xSemaphoreTake(_mutex, portMAX_DELAY)) {
90-
uint32_t now = millis();
91-
while ((millis() - now) < SERIAL_COMMUNICATION_TIMEOUT) {
92-
if (Serials[_serialIndex]->available()) {
93-
_buffer[_buffer_size] = Serials[_serialIndex]->read();
94-
now = millis();
95-
if (esp3d_string::isRealTimeCommand(_buffer[_buffer_size])) {
96-
flushChar(_buffer[_buffer_size]);
97-
_buffer[_buffer_size] = '\0'; //remove realtime command from buffer
98-
} else {
99-
_buffer_size++;
100-
if (_buffer_size > ESP3D_SERIAL_BUFFER_SIZE ||
101-
_buffer[_buffer_size - 1] == '\n') {
102-
flushBuffer();
103-
}
91+
// Get expected len of data
92+
size_t count = Serials[_serialIndex]->available();
93+
94+
//loop until each byte is handled
95+
while (count > 0) {
96+
int data = Serials[_serialIndex]->read();
97+
98+
// If read() failed we leave
99+
if (data == -1) {
100+
esp3d_log_e("Serial read failed unexpectedly");
101+
break; // only break to release mutex
102+
}
103+
//take the char
104+
count--;
105+
_buffer[_buffer_size] = (uint8_t)data;
106+
//check what next step is
107+
if (esp3d_string::isRealTimeCommand(_buffer[_buffer_size])) {
108+
flushChar(_buffer[_buffer_size]);
109+
_buffer[_buffer_size] = '\0'; //remove realtime command from buffer
110+
} else {
111+
_buffer_size++;
112+
if (_buffer_size > ESP3D_SERIAL_BUFFER_SIZE || _buffer[_buffer_size - 1] == '\n') {
113+
flushBuffer();
104114
}
105115
}
106116
}
107-
117+
//release mutex
108118
xSemaphoreGive(_mutex);
109119
} else {
110120
esp3d_log_e("Mutex not taken");
@@ -256,4 +266,4 @@ bool ESP3DSerialService::reset() {
256266

257267
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL ||
258268
// defined(ESP_SERIAL_BRIDGE_OUTPUT)
259-
#endif // ARDUINO_ARCH_ESP32
269+
#endif // ARDUINO_ARCH_ESP32

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "3.0.0.3b1"
2+
"version": "3.0.0.4b1"
33
}

0 commit comments

Comments
 (0)