Controlling Elk via Java app

chrisexv6

Active Member
I know its been done before, but I figured Id play around myself programming communication to my Elk M1 through the M1EXP.

Ive been able to successfully open the port and send a command, that all works fine. Where Im stuck is writing a function to determine the checksum portion of the message string.

Im following Elks protocol doc, and cutting the C code over to Java (it should be the same/similar) but for the life of me the check digits arent coming out correct. On top of that, I took a look at the Elk::M1 Perl module, and they seem to be computing the check digit differently than the Elk protocol doc. Either version I cannot get to work for some reason. Im basically adding up the ASCII codes of the message (tried it with and without the first two characters denoting the length of the string), bitwise AND-ing it and adding 1 (per the Elk doc). I think the disconnect is in the "NibToAsc" portion, which incidentally doesnt seem to be anywhere in the Elk::M1 Perl module......which makes me wonder what I might be doing wrong.

Anyone out there gone through this and had similar issues? Or maybe example code that DOES work?

Thanks in advance.

-Chris
 
Chris,

I whipped up a Java routine that can add the length at the beginning and the checksum at the end of an Elk command.

It's wrapped up as a console application for testing that can be executed like this:

java ElkCmd RP0000

The output for that command should be:

08RP000036

Chris
 

Attachments

  • ElkCmd.java.txt
    857 bytes · Views: 37
You rock, thanks!!

Incidentally, I was able to figure it out (in a different way than you did).

In the beginning of the protocol doc it explains the checksum as the twos complement of the modulo-256 of the sum of the ASCII codes in the string. Their code doesnt really make it that simple, but it really was.....just mod the sum by 256 THEN take the upper and lower nibbles and convert to ASCII.

Your code is also different than their example, and seems even more elegant than the modulo code I got working.

Im surprised their example seems to much more complicated than necessary, I suppose it could be because the document is so old but I dunno for sure.

Thanks again!

-Chris
 
Back
Top