SLIP bug: reading too fast from serial

when the escape char was read from serial, then the escaped char was
read immediately after, but it was not available, thus resulting in
no proper escape; now fixed
This commit is contained in:
giomba 2019-12-23 21:45:25 +01:00
parent aa4a347bfb
commit 895206a046

View File

@ -3,7 +3,7 @@ namespace slip {
void send(const char* buffer, int len) { void send(const char* buffer, int len) {
// Serial.write(END); /* frame-out any possible noise on the line */ // Serial.write(END); /* frame-out any possible noise on the line */
for (uint8_t i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
switch (buffer[i]) { switch (buffer[i]) {
case END: case END:
Serial.write(ESC); Serial.write(ESC);
@ -24,7 +24,7 @@ namespace slip {
int recv(char* buffer, int len) { int recv(char* buffer, int len) {
char r; char r;
uint8_t i = 0; int i = 0;
while (i < len) { while (i < len) {
if (Serial.available()) { if (Serial.available()) {
@ -32,6 +32,7 @@ namespace slip {
switch (r) { switch (r) {
case ESC: case ESC:
while (Serial.available() <= 0);
r = Serial.read(); r = Serial.read();
if (r == ESC_END) { if (r == ESC_END) {
buffer[i++] = END; buffer[i++] = END;