Basic Checksum Question
deepforestgreen
Posts: 51
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.
0
Comments
I wrote this without compiling it, this can be an idea that you can start from
regards
m.
[/code]
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.
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.
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
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.