Basic Checksum Question
deepforestgreen
Junior Member
After three years of programming in AMX, I'm working with Checksum for the first time. It seems like a cumbersome ordeal. Anyway, I need someone to tell me if I've got the concept down.
If (for example) it wants me to turn the device ON with the command '$01,$01,CHECKSUM', would I send '$01,$01,$02'?
I know it's a simple question, but it's just one of those things I've never had to work with in any programming language I've worked with. Don't ask me how I avoided it. Thanks for your advice.
If (for example) it wants me to turn the device ON with the command '$01,$01,CHECKSUM', would I send '$01,$01,$02'?
I know it's a simple question, but it's just one of those things I've never had to work with in any programming language I've worked with. Don't ask me how I avoided it. Thanks for your advice.
Comments
-
Usually a protocol's documentation will tell you how the checksum is to be calculated (some even provide a sample C program that does it). In general, a checksum is found by adding up some or all of the bytes before the checksum and BANDing with $FF (that is, discarding the most significant bits if the sum is more than a byte.) Your query is awfully abstract - if you want more advice you should post what the protocol says regarding checksum.deepforestgreen wrote: »After three years of programming in AMX, I'm working with Checksum for the first time. It seems like a cumbersome ordeal. Anyway, I need someone to tell me if I've got the concept down.
If (for example) it wants me to turn the device ON with the command '$01,$01,CHECKSUM', would I send '$01,$01,$02'?
I know it's a simple question, but it's just one of those things I've never had to work with in any programming language I've worked with. Don't ask me how I avoided it. Thanks for your advice. -
I can understand how it wants me to calculate the checksum - that part is self-evident. But I'm unfamiliar with the syntax. I suppose it just wants another hexadecimal byte with the sum, but I've never seen it in code so I'm just unsure.
-
DEFINE_VARIABLE char stringsToSend[] char stringWithChecksum = [] integer counter integer checksum = 0 DEFINE_START stringsToSend[1] = $01 stringsToSend[2] = $F1 //... etc FOR(counter = 1; counter <= LENGTH_STRING(stringsToSend); i++) { checksum = checksum + stringsToSend[i] stringWithChecksum = "stringWithChecksum, ITOA(stringsToSend[i]),','" } stringWithChecksum = "stringWithChecksum, ITOA(checksum)" send_string myDevice, stringWithChecksum
I wrote this without compiling it, this can be an idea that you can start from
regards
m.
[/code] -
Thanks, I think this will help. I really don't care for the Checksum process, but I'm sure there's a good reason for it. Since most devices don't use it, I'm not sure why I'm bothering. Thanks, again!
-
deepforestgreen wrote: »Thanks, I think this will help. I really don't care for the Checksum process, but I'm sure there's a good reason for it. Since most devices don't use it, I'm not sure why I'm bothering. Thanks, again!
With Checksum you are sure that the messages which you receive from the device are correct and complete, and the same when you send to the device, so they are important ! -
With Checksum you are sure that the messages which you receive from the device are correct and complete, and the same when you send to the device, so they are important !
That's what I've read, but I've never needed it for anything else. I suppose the other devices I've worked with didn't have as much potential for problems with that sort of thing. -
deepforestgreen wrote: »I can understand how it wants me to calculate the checksum - that part is self-evident. But I'm unfamiliar with the syntax. I suppose it just wants another hexadecimal byte with the sum, but I've never seen it in code so I'm just unsure.
It still depends on the device's protocol, some of them put it in as another byte in the command, some ASCII-fy it and split it into high and low nibbles across two bytes, and some require escaping it if the checksum comes out to certain values! There is no standard for calculating or including checksums, that's why we're asking for the protocol manual in order to answer your question. -
I did the BatiBus checksum in this way
Message from the device : $40$07$03$03$4E$02$FA$A2
Last to bytes are the check sum $FA$A2
So I had to BXOR the data $40$07$03$03$4E$02 -> $BF$F8$FC$FC$B1$FD
and then I sum the data -> $05$5D
then I BXOR the sum $05$5D->$FA$A2 -
deepforestgreen wrote: »Thanks, I think this will help. I really don't care for the Checksum process, but I'm sure there's a good reason for it. Since most devices don't use it, I'm not sure why I'm bothering. Thanks, again!
With two communicating devices that are connected by a short serial cable, I would debate the necessity of a checksum.
However, with communication paths such as RF or powerline carriers, checksums are valuable.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums