![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
How make a checksum? |
Posted: Tue Mar 23, 2021 5:51 pm |
|
|
Hi, I have this data and I should simulate a device so I need make the checksum:
Code: | $$<pack-len>,<ID>,<work-no>,<cmd-code>,<cmd-para>*<checksum>
$$121,864376048180995,12,A01,,210320022750,A,6.162546,-75.569028,0,249,1744,210,0,90000058,00,0,732|101|5FF|50EB,19D|5FB|51,1,*28
|
How i can get the checksum?
Checksum of package, 2 bytes hexadecimal string format, XOR of {<pack-len>,<ID>,<work-no>,<cmd-code>,<cmd-para>}.
XOR
121
864376048180995
12
A01
0
so the result is 28. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 24, 2021 12:48 am |
|
|
Tell us the manufacturer and model number of the device that produces this
message and checksum. Always do this. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Wed Mar 24, 2021 1:59 am |
|
|
Thing to understand, is that there are thousands of different checksums.
Simple XOR, then polynomial ones. These than have individual parameters
on the terms used and the seed values. Actually probably _billions_ of
possible sums. This is why we need to know what device is involved....
With a single example, there are still an almost infinite number of ways
of getting this value. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Wed Mar 24, 2021 4:21 am |
|
|
I haven't needed to make CRC generators in decades so..
gee, the first thing I saw was that the <ID> appears to be a 64 bit number!
I don't know if the current compiler can do 64 bit 'math' and as others have said we need to know the device mfr. They will(should) supply an application note on 'CRC generation' for this device, whtever it is. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Wed Mar 24, 2021 4:35 am |
|
|
He actually talks as if the checksum could be a simple XOR of every
byte after the second $, up to where the checksum is output, and then
is simply a 2 byte hex value of this XOR. If so probably starts from zero. |
|
![](templates/subSilver/images/spacer.gif) |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: How make a checksum? |
Posted: Thu Mar 25, 2021 1:43 am |
|
|
cvargcal wrote: | Hi, I have this data and I should simulate a device so I need make the checksum:
[code]$$<pack-len>,<ID>,<work-no>,<cmd-code>,<cmd-para>*<checksum>
$$121,864376048180995,12,A01,,210320022750,A,6.162546,-75.569028,0,249,1744,210,0,90000058,00,0,732|101|5FF|50EB,19D|5FB|51,1,*28
|
This looks like a Position/Alarm message, which is shown on page 10
of your pdf document link.
Where did you get the sample message, starting with $$121 ?
It's not from that pdf. I searched for it. I can't find $$121 anywhere
in the pdf.
2nd thing. You say that the CRC is calculated only on these bytes:
Quote: |
XOR
121
864376048180995
12
A01
0 |
But in the section on the checksum for the Position/Alarm Data on page 13
of the pdf, it says:
Quote: | checksum of package, 2 bytes hexadecimal string format, XOR of
{<pack-len>,<ID>,<work-no>,A01,<alm-code|alm-para>,<date-time>,<fix_flag>,<l
atitude>,<longitude>,<speed>,<course>,<altitude>,<odometer>,<runtime>,<statu
s>,<input-st>,<output-st>,MCC|MNC|LAC|CI,bat-ad|ext-ad|ad1…adN,<rfid_data
>,< digital-sensor>}. |
So the checksum is not calculated, as you say, on the first few bytes, but
instead on nearly the whole message. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Thu Mar 25, 2021 3:52 am |
|
|
It's wrong really to think of it in terms of a 'sum'. It isn't. It's a bitwise parity.
If you have (say) 'abcd', these have ascii values of 0x61, 0x62, 0x63 & 0x64.
Now in C the XOR operator is ^.
0x61^0x62^0x63^0x64 gives 4.
The result will always be an 8bit value if all the source bytes are 8bit.
This would be output as hex, in the format required with:
printf("*%02X", val);
Which would print *04.
Like PCM, I read it as XORing every byte after the $$, including the comma
before the checkbyte.
It is a very poor check value. It can detect any single bit error, but not
ones with two bits, 4 bit, 6 bits, 8bits etc.. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|