Home AMX User Forum NetLinx Studio
Options

Checksums for the novice

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

Comments

  • Options
    travtrav Posts: 188
    Well, If I do the calculation on that string with the sum of the 1's compliment, or even the sum of the values and the ~ of them, I don't get $31

    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
  • Options
    If you have something like this:

    CMD = "$50,$30,$10,$30,$02,$01,$00,$0B,$00,$00"

    You can do:
    CHK = 0
    X = 1
    WHILE (X <= LENGTH_STRING(CMD))
    {
      CHK = CHK + CMD[X]
      X = X + 1
    }
    CHK = ~CHK
    
    SEND_STRING Proj,"$50,$30,CMD,CHK,$D1"
    

    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
  • Options
    zooeylzooeyl Posts: 13
    Thanks Chip, let me give that a try. I should have noted that it was just the lower byte they are looking for in the checksum.
  • Options
    zooeyl wrote:
    Thanks Chip, let me give that a try. I should have noted that it was just the lower byte they are looking for in the checksum.

    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
  • Options
    travtrav Posts: 188
    My maths must suck then ^_^
    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
Sign In or Register to comment.