Revert "fix(lightware): consume exactly the parsed frame (#29167)" (#29219)

This reverts commit 1341c655e7.
This commit is contained in:
Andrew Brahim authored and GitHub committed 2026-10-14 09:38:35 -06:00
1 parent 7635d64f97
commit c06973172f
2 files changed
+10 -16

No files matched your search

@@ -345,7 +345,6 @@ void GRFLaserSerial::grf_get_and_handle_request(const int payload_length, const
}
int index = 0;
int frame_end = 0;
while (index <= _linebuf_size - payload_length && _crc_valid == false) {
bool restart_flag = false;
@@ -456,8 +455,6 @@ void GRFLaserSerial::grf_get_and_handle_request(const int payload_length, const
_parsed_state = GRF_PARSED_STATE::START;
_calc_crc = 0;
restart_flag = true;
// the whole frame: start byte, two flag bytes, data_len payload bytes (id included), two crc bytes
frame_end = index + rx_field.data_len + 5;
break;
} else {
@@ -477,11 +474,11 @@ void GRFLaserSerial::grf_get_and_handle_request(const int payload_length, const
index++;
}
// Remove the parsed frame from the buffer, also when it ends the buffer, so it is not parsed and
// published again on the next poll and the start byte of the next frame is kept
if (_crc_valid && frame_end > 0 && frame_end <= _linebuf_size) {
memmove(&_linebuf[0], &_linebuf[frame_end], _linebuf_size - frame_end);
_linebuf_size -= frame_end;
// If we parsed successfully, remove the parsed part from the buffer if it is still large enough
if (_crc_valid && index + payload_length < _linebuf_size) {
unsigned next_after_index = index + payload_length;
memmove(&_linebuf[0], &_linebuf[next_after_index], _linebuf_size - next_after_index);
_linebuf_size -= next_after_index;
}
// The buffer is filled. Either we can't keep up with the stream and/or it contains only invalid data. Reset to try again.
@@ -341,7 +341,6 @@ void SF45LaserSerial::sf45_get_and_handle_request(const int payload_length, cons
}
int index = 0;
int frame_end = 0;
while (index <= _linebuf_size - payload_length && _crc_valid == false) {
bool restart_flag = false;
@@ -454,8 +453,6 @@ void SF45LaserSerial::sf45_get_and_handle_request(const int payload_length, cons
_parsed_state = SF45_PARSED_STATE::START;
_calc_crc = 0;
restart_flag = true;
// the whole frame: start byte, two flag bytes, data_len payload bytes (id included), two crc bytes
frame_end = index + rx_field.data_len + 5;
break;
} else {
@@ -475,11 +472,11 @@ void SF45LaserSerial::sf45_get_and_handle_request(const int payload_length, cons
index++;
}
// Remove the parsed frame from the buffer, also when it ends the buffer, so it is not parsed and
// published again on the next poll and the start byte of the next frame is kept
if (_crc_valid && frame_end > 0 && frame_end <= _linebuf_size) {
memmove(&_linebuf[0], &_linebuf[frame_end], _linebuf_size - frame_end);
_linebuf_size -= frame_end;
// If we parsed successfully, remove the parsed part from the buffer if it is still large enough
if (_crc_valid && index + payload_length < _linebuf_size) {
unsigned next_after_index = index + payload_length;
memmove(&_linebuf[0], &_linebuf[next_after_index], _linebuf_size - next_after_index);
_linebuf_size -= next_after_index;
}
// The buffer is filled. Either we can't keep up with the stream and/or it contains only invalid data. Reset to try again.