CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How make a checksum?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

How make a checksum?
PostPosted: Tue Mar 23, 2021 5:51 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 24, 2021 12:48 am     Reply with quote

Tell us the manufacturer and model number of the device that produces this
message and checksum. Always do this.
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Wed Mar 24, 2021 1:59 am     Reply with quote

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.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 24, 2021 4:21 am     Reply with quote

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.
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Wed Mar 24, 2021 4:35 am     Reply with quote

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.
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Wed Mar 24, 2021 10:47 pm     Reply with quote

Thanks for answers...

I want use the fifo protocol, i need "simulate" this device in one server that work with this device, so I need make a real checksum.
http://www.fifotrack.com/download/protocol/FIFOTRACK%20A300%20and%20A500%20GPRS%20Protocol%20and%20Command%20List%20V1.3.pdf

So the protocol is A01, in page 6 show every space... I don't undertand how yo get checksum of 2 bytes with a sum of more size.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: How make a checksum?
PostPosted: Thu Mar 25, 2021 1:43 am     Reply with quote

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.
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Thu Mar 25, 2021 3:52 am     Reply with quote

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..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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