c# - 16bit CRC-ITU calculation for Concox tracker -


i creating c# code server program receives data concox tr06 gps tracker via tcp:

http://www.iconcox.com/uploads/soft/140920/1-140920023130.pdf

when first starting up, tracker sends login message, needs acknowledged before send position data. first problem that, according documentation, acknowledge message 18 bytes long, yet example provide 10 bytes long:

enter image description here

p.s. in table above, "bits" column i'm pretty sure should labelled "bytes" instead...

now, main problem in calculating error check. according documentation:

the check code generated crc-itu checking method. check codes of data in structure of protocol, packet length information serial number (including "packet length" , "information serial number"), values of crc-itu.

ok, in above example, need calculate crc on 0x05 0x01 0x00 0x01

now, i'm guessing it's 16 bit crc, according diagram above, crc 2 bytes long. i've implemented 2 different crc implementations found online @ http://www.sanity-free.org/134/standard_crc_16_in_csharp.html , http://www.sanity-free.org/133/crc_16_ccitt_in_csharp.html neither give me answer that, according diagram above supposed getting - 0xd9 0xdc. i've used site - https://www.lammertbies.nl/comm/info/crc-calculation.html - manually enter 4 bytes, nothing gives me result i'm supposed getting according diagram above...

any ideas might going wrong? pointers/hints appreciated. thank you

the itu crc-16 called x-25 crc. can find specification here, is:

width=16 poly=0x1021 init=0xffff refin=true refout=true xorout=0xffff check=0x906e name="x-25" 

my crcany code take specification , generate c code compute crc.

here bit-wise (slow) code thusly generated:

#include <stddef.h>  unsigned crc16x_25_bit(unsigned crc, void const *data, size_t len) {     if (data == null)         return 0;     crc = ~crc;     crc &= 0xffff;     while (len--) {         crc ^= *(unsigned char const *)data++;         (unsigned k = 0; k < 8; k++)             crc = crc & 1 ? (crc >> 1) ^ 0x8408 : crc >> 1;     }     crc ^= 0xffff;     return crc; } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -