Checksums for the novice
zooeyl
Posts: 13
Hi guys,
I'm trying to find a way to calculate the checksum for strings I need to send to a Yamaha DME32. I can do it manually, but I have to calculate each one and it's a bit time consuming. I have a bit of code from a friend of mine who does this Loop thing to get it, but I don't quite understand it.
Here is a typical string I have to send:
SEND_STRING DME,"$D0,$0B,$50,$30,$10,$30,$02,$01,$00,$0B,$00,$00,$31,$D1"
To calculate the Checksum you ignore the $D0,$0B at the front and the $D1 at the end. In this string the Checksum is the $31 which is the 1s Complement, I think, the NOT of the Hex numbers added together. Any suggestions on doing the math automatically?
Thanks
I'm trying to find a way to calculate the checksum for strings I need to send to a Yamaha DME32. I can do it manually, but I have to calculate each one and it's a bit time consuming. I have a bit of code from a friend of mine who does this Loop thing to get it, but I don't quite understand it.
Here is a typical string I have to send:
SEND_STRING DME,"$D0,$0B,$50,$30,$10,$30,$02,$01,$00,$0B,$00,$00,$31,$D1"
To calculate the Checksum you ignore the $D0,$0B at the front and the $D1 at the end. In this string the Checksum is the $31 which is the 1s Complement, I think, the NOT of the Hex numbers added together. Any suggestions on doing the math automatically?
Thanks
0
Comments
I wrote some code for the first revision of the DME64 (not sure if this is applicable to the DME32, but you had to repackage into 7bit bytes, rather than 8bit bytes then calculate the checksum on these... so you'd end up with an extra 7bit byte, with the leading bits from the older 8bit bytes (it still makes my head hurt).
I've tried looking around for the protocol manual for the 32, but can't find it anywhere. If you could link to it or post it here I'll take a look at it.
-Trav
CMD = "$50,$30,$10,$30,$02,$01,$00,$0B,$00,$00"
You can do:
Does that make sense? I'm assuming the bytes in the command would never be able to add up to more than 255, otherwise the protocol would say what to do in the case of overflow, or only using the lower byte, or somesuch...
BTW, I got = $50 + $30 + $10 + $30 + $02 + $01 + $0B = $CE. ~$CE = $31
- Chip
Thinking about it, it shouldn't matter... If the value goes above $FF, you still get the negation of the lower 8 bits when using it in a SEND_STRING like that - the upper bits are ignored.
- Chip
Nothing new there.
Ahh I see, gg me for not reading the question.. I was adding in the $31 that was the checksum. Nice.
-Trav