Skip to content
Snippets Groups Projects
Commit 4b67dc97 authored by Peter Švihra's avatar Peter Švihra
Browse files

fixed wrong packet reading

- could happen if started reading random trailing packet and first got stop flag
parent 785dfca7
Branches
No related merge requests found
......@@ -74,8 +74,8 @@ void CommsControl::receiver() {
// find the boundary of frames
if (_last_trans[current_trans_index] == COMMS_FRAME_BOUNDARY) {
// if not found start or if read the same byte as last time
if (!_found_start || _start_trans_index == current_trans_index) {
// if not found start or if read the same byte as last time or if read a random end first
if (!_found_start || current_trans_index < _start_trans_index + 6 ) {
_found_start = true;
_start_trans_index = current_trans_index;
} else {
......
......@@ -36,6 +36,7 @@ class CommsControl():
# needed to find packet frames
self._received = []
self._receivedStart = 0
self._foundStart = False
self._timeLastTransmission = int(round(time.time() * 1000))
......@@ -136,9 +137,9 @@ class CommsControl():
# TODO: this could be written in more pythonic way
# force read byte by byte
self._received.append(byte)
# logging.debug(byte)
# logging.info(byte)
# find starting flag of the packet
if not self._foundStart and byte == bytes([0x7E]):
if byte == bytes([0x7E]) and ((len(self._received) < self._receivedStart + 6) or not self._foundStart ):
self._foundStart = True
self._receivedStart = len(self._received)
# find ending flag of the packet
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment