Skip to content

Commit

Permalink
[refaceDX] Simplify the code that calculates the checksum, makes it m…
Browse files Browse the repository at this point in the history
…atch the specification better #324.
  • Loading branch information
christofmuc committed Aug 1, 2024
1 parent 1689e40 commit 81c367e
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions adaptations/YamahaRefaceDX.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,12 @@ def dataBlockFromMessage(message):
if isOwnSysex(message):
data_len = message[5] << 7 | message[6]
if len(message) == data_len + 9:
data_block = message[8:-2]
check_sum = -0x05
for d in data_block:
check_sum -= d
if (check_sum & 0x7f) == message[-2]:
# Check sum passed
return data_block
else:
raise Exception("Checksum error in reface DX data")
# The Check-sum is the value that results in a value of 0 for the
# lower 7 bits when the Model ID, Start Address, Data and Check sum itself are added.
checksum_block = message[0x07:-1]
if (sum(checksum_block) & 0x7f) == 0:
# return "Data" block
return message[0x08:-2]
raise Exception("Got corrupt data block in refaceDX data")


Expand Down

0 comments on commit 81c367e

Please sign in to comment.