Split logic for adding char to buffer and sending

the buffer, to make sure the char doesn't get
lost when the buffer is full
This commit is contained in:
Matthijs Abma 2020-05-23 17:30:48 +02:00
parent 2626345662
commit 7f18e1e8e3
2 changed files with 12 additions and 4 deletions

View File

@ -1299,11 +1299,15 @@ void SerialInput(void)
if ((serial_in_byte_counter < INPUT_BUFFER_SIZE -1) && // Add char to string if it still fits and ...
!in_byte_is_delimiter) { // Char is not a delimiter
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
serial_polling_window = millis();
} else {
}
if ((serial_in_byte_counter >= INPUT_BUFFER_SIZE -1) || // Send message when buffer is full or ...
in_byte_is_delimiter) { // Char is delimiter
serial_polling_window = 0; // Reception done - send mqtt
break;
}
serial_polling_window = millis(); // Wait for next char
}
}

View File

@ -62,11 +62,15 @@ void SerialBridgeInput(void)
if ((serial_bridge_in_byte_counter < SERIAL_BRIDGE_BUFFER_SIZE -1) && // Add char to string if it still fits and ...
!in_byte_is_delimiter) { // Char is not a delimiter
serial_bridge_buffer[serial_bridge_in_byte_counter++] = serial_in_byte;
serial_bridge_polling_window = millis(); // Wait for more data
} else {
}
if ((serial_bridge_in_byte_counter >= SERIAL_BRIDGE_BUFFER_SIZE -1) || // Send message when buffer is full or ...
in_byte_is_delimiter) { // Char is delimiter
serial_bridge_polling_window = 0; // Publish now
break;
}
serial_bridge_polling_window = millis(); // Wait for more data
}
}