Losing my fricken mind - BXOR
ericmedley
Posts: 4,177
Someone please check my math...
I'm working on comms with a BlU100 (I'd rather ram a flaming sharp stick in my eye)
They use a really janky hex protocol with a checsum.
here's the string in their example:
"0x02, 0x88, 0x01, 0x0F, 0x1B, 0x83, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x84, 0x03"
what I'm supposed to do to make a checksum is XOR the charactors in the "body" of the message which is the following part of the previous message:
" 0x88, 0x01, 0x0F, 0x1B, 0x83, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00"
The first char ($02) is the message header, the last char ($03) is the termination. The penultimate char (($84) is supposed to be the check sum. I have done the XOR in code and on a calculator and come up with $1F. The answer according to the documentation is supposed to be $84. My method (according to the documentation) of XOR-ing is:
result =$88 BXOR $01
result= result BXOR $01
result= result BXOR $0F
result=result BXOR $1B
etc...
any hints as to what I'm doing wrong? Or is the documentation wrong? anyone have experience with the BLU100?
I'm working on comms with a BlU100 (I'd rather ram a flaming sharp stick in my eye)
They use a really janky hex protocol with a checsum.
here's the string in their example:
"0x02, 0x88, 0x01, 0x0F, 0x1B, 0x83, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x84, 0x03"
what I'm supposed to do to make a checksum is XOR the charactors in the "body" of the message which is the following part of the previous message:
" 0x88, 0x01, 0x0F, 0x1B, 0x83, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00"
The first char ($02) is the message header, the last char ($03) is the termination. The penultimate char (($84) is supposed to be the check sum. I have done the XOR in code and on a calculator and come up with $1F. The answer according to the documentation is supposed to be $84. My method (according to the documentation) of XOR-ing is:
result =$88 BXOR $01
result= result BXOR $01
result= result BXOR $0F
result=result BXOR $1B
etc...
any hints as to what I'm doing wrong? Or is the documentation wrong? anyone have experience with the BLU100?
0
Comments
If I only had the actual unit here I could test against reality. I can tell you this is the worst thought out protocol I've ever seen. The best part is the message IDs are 5 values
0x02 STX
0x03 ETX
0x06 ACK
0x15 NAK
0x1B Escape
However, if these values occur withing the body of the message (which they often do) then they have a set of replacement values you have to sub in AFTER you do the checksum. ANNNNNND if the checksum happens to work out to be one of these reserved values, IT needs to be subbed in. c'mon folks, it's the fricken 21st century. wake up and smell the 16+ bit word length. It's okay to use plain text stuff. All the cool kids are nowadays...
Create the command,
Create the checksum via XOR,
Do the extra special "Escape Out" for certain values (add $80 to the byte and preface it with $1B),
Append with STX and ETX
This is a little subroutine I wrote, I hope it helps:
Also remember if you're using live feedback from the device, you NEED to REVERSE all those "ESCAPED OUT" bytes the BLU sends you back. It's like the process above only reversed:
I hope this helps madman.
Andrew,
What a guy! Thanks! it's amazing how close our code is. I even named some of my stack_vars the same... I seem to remember a guy like you helping out with another DSP a while back...