Domanda

I am trying to create a byte array that has a certain BCC (Block Check Character) result (=0).

The array will have the preamble of:

32 02 31 1F 31 1E 32 1F T  E  S  T  :  
32 02 31 1F 31 1E 32 1F 54 45 53 54 3A 20

With a variable text message (msg) in the middle:

T  e  s  t  2
54 65 73 74 32

Followed by a postamble of:

1E 37 1F 33 03

The BCC I get for this string is: 0x11

Here's the algorithm that returns this value (C++):

unsigned char bcc=0;
int index = block.Find(0x03); //ETX
for (int i=0; i<= index;i++)
    bcc ^= block[i];
return bcc;

I'm trying to come up with a method of finding a middle message section that will result in the BCC of 0.

I am currently using trial and error, but I'm pretty sure there's a better way to do this - I just haven't come up with one that works. I've taken a swing at a tool that replicates the BCC method in use above (in C#) and that disagrees with the results I get (sigh).

È stato utile?

Soluzione

You can set the checksum to zero by replacing any single character with the character xor ed with the current checksum.

For example, change test2 to test#

0x32(#) = 0x23(2)^0x11

You may need to take care to avoid certain special characters (it looks like 0x03 is significant in some way, and often 0x00 should also be avoided in case strings are using null termination). For example, if you wanted to make a character into 0x03 you might instead prefer to add two characters whose xor is 0x03, such as 'a' and 'b'

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top