Skip to content

Commit

Permalink
Converting data to byte array before calculating the CRC value
Browse files Browse the repository at this point in the history
  • Loading branch information
mgm8 committed Dec 12, 2022
1 parent 954ccb0 commit e61787d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyngham/pyngham.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def encode(self, pl, flags=0):
pkt = pkt + pl

# Insert checksum
checksum = Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).checksum(pkt[codeword_start:])
checksum = Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).checksum(bytes(pkt[codeword_start:]))
pkt = pkt + [(checksum >> 8) & 0xFF, checksum & 0xFF]

# Insert padding
Expand Down Expand Up @@ -242,7 +242,7 @@ def decode_byte(self, byte):
pl = pl[:_PYNGHAM_PL_SIZES[self._decoder_size_nr] - (self._decoder_buf[0] & _PYNGHAM_PADDING_BM)]

# Check if the packet is decodeable and then if CRC is OK
if Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).verify(self._decoder_buf[:len(pl)+1], (self._decoder_buf[len(pl)+1] << 8) | self._decoder_buf[len(pl)+2]):
if Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).verify(bytes(self._decoder_buf[:len(pl)+1]), (self._decoder_buf[len(pl)+1] << 8) | self._decoder_buf[len(pl)+2]):
return pl, errors, err_pos
else:
return list(), -1, list()
Expand Down
4 changes: 2 additions & 2 deletions pyngham/spp.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def encode(self, pkt_type, pl):
# Payload
pkt = pkt + pl

crc_val = Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).checksum(pkt)
crc_val = Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).checksum(bytes(pkt))
checksum = [(crc_val >> 8) & 0xFF, crc_val & 0xFF]

# Start byte and CRC
Expand Down Expand Up @@ -213,7 +213,7 @@ def decode_byte(self, c):
# If received length has met target length (set in STATE_HEADER)
if len(self._rx_buffer) == (2 + 1 + 1 + self._rx_buffer[3]):
# Check checksum
crc_val = Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).checksum(self._rx_buffer[2:])
crc_val = Calculator(Configuration(16, 0x1021, 0xFFFF, 0xFFFF, True, True)).checksum(bytes(self._rx_buffer[2:]))

self._state = SPPState.START

Expand Down
2 changes: 1 addition & 1 deletion pyngham/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
__copyright__ = "Copyright (C) 2022, Gabriel Mariano Marcelino"
__credits__ = ["Gabriel Mariano Marcelino - PU5GMA"]
__license__ = "LGPLv3"
__version__ = "1.0.2"
__version__ = "1.0.3"
__maintainer__ = "Gabriel Mariano Marcelino - PU5GMA"
__email__ = "[email protected]"
__status__ = "Production"

0 comments on commit e61787d

Please sign in to comment.