Skip to content

Commit

Permalink
Fix crcHeader for python
Browse files Browse the repository at this point in the history
Signed-off-by: Cervenka Dusan <[email protected]>
  • Loading branch information
Hadatko committed Oct 24, 2023
1 parent 42c8cb2 commit 145ff7e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions erpc_python/erpc/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def send(self, message):

crcBody = self._Crc16.computeCRC16(message)
messageLength = len(message)
crcHeader = self._Crc16.computeCRC16(messageLength) + self._Crc16.computeCRC16(crcBody)
crcHeader = self._Crc16.computeCRC16(bytearray(struct.pack('<H', messageLength))) + self._Crc16.computeCRC16(bytearray(struct.pack('<H', crcBody)))
crcHeader &= 0xFFFF # 2bytes

header = bytearray(struct.pack('<HHH', crcHeader, messageLength, crcBody))
assert len(header) == self.HEADER_LEN
Expand All @@ -88,7 +89,8 @@ def receive(self):
headerData = self._base_receive(self.HEADER_LEN)
crcHeader, messageLength, crcBody = struct.unpack('<HHH', headerData)

computedCrc = self._Crc16.computeCRC16(messageLength) + self._Crc16.computeCRC16(crcBody)
computedCrc = self._Crc16.computeCRC16(bytearray(struct.pack('<H', messageLength))) + self._Crc16.computeCRC16(bytearray(struct.pack('<H', crcBody)))
computedCrc &= 0xFFFF # 2bytes
if computedCrc != crcHeader:
raise RequestError("invalid header CRC")

Expand Down

0 comments on commit 145ff7e

Please sign in to comment.