in smart-mirror-full/extracted/device/script/src/agt/bt_classic/adapter.py [0:0]
def _state_get_data(self, c):
"""
Accept payload. This could be an escaped character (state_get_escaped()
Will drop back to start if STX is found, and validate checksum and send payload if ETX is found.
:param c: Char to parse
"""
if c == _STX:
self._start_packet()
elif c == _ESC:
self._state = self._state_get_escaped
elif c == _ETX:
# Last two bytes are checksum
if len(self._packet.payload) >= 2:
found_checksum = self._packet.payload.pop() + (self._packet.payload.pop() << 8)
# Then get actual
calc_checksum = self._packet._calc_checksum()
if found_checksum == calc_checksum:
self._payload_cb(self._packet.payload)
self._state = self._state_find_stx
else:
self._packet.payload.append(c)