Hi,
how to calculate a Roland checksum in lua? Imagine the command looks like :
midi.sendSysex (devPort, commandArray, payLoadArray,checkSum)
and I need to calculate the checkSum based on the payLoadArray.
What’s a good way to do that?
Hi,
how to calculate a Roland checksum in lua? Imagine the command looks like :
midi.sendSysex (devPort, commandArray, payLoadArray,checkSum)
and I need to calculate the checkSum based on the payLoadArray.
What’s a good way to do that?
I assume the checksum is calculated using data in the payLoadArray. If I were you, I would:
checksumByte = calculateChecksum(payLoadArray)
commandArray
, payLoadArray
, and checksumByte
to form byteArray
byteArray
with midi.sendSysex(devPort, byteArray)
To actually calculate it, the standard is something like sum all the bytes in the array and truncate to 7 bits, or sum all the bytes and subtract from 256, or …
The Roland manuals are usually pretty good about telling you somewhere how it’s done.
Alternatively, if you have an editor like HexEdit, you can take a dump with a checksum and calculate various ways across the data bytes until you match what is there
It works!
Here’s the function (payLoad = a table)
function calcChecksum(payLoad)
local result = 0
for i= 1, #payLoad do
result = result+payLoad[i]
end
result = (128-result)%128
return result
end