javascript - CRC calculation over 26 bytes -


i'm implementing simple protocol , need calculate crc following structure:

type    (1 byte, unsigned) address (1 byte, unsigned) dataid  (4 bytes, unsigned, little-endian) data    (4 bytes, unsigned, little-endian) data    (4 bytes, unsigned, little-endian) data    (4 bytes, unsigned, little-endian) data    (4 bytes, unsigned, little-endian) data    (4 bytes, unsigned, little-endian) ----------------- =       (26 bytes) 

you can imagine simple javascript object:

var message = {   type:    0x11,   address: 0x01,   dataid:  0xffffffff,   data: [     0xffffffff,     0xffffffff,     0xffffffff,     0xffffffff,     0xffffffff   ] } 

from object need calculate crc. unfortunately, in manual crc calculation includes message type, slave address data-id's , data values. crc calculation performed on 26 bytes. i'm not sure should do.

crc calculated using crc16-ccit function. downloaded crc package npm has function implemented.

it great if post me code, because have no idea (you can use undeclared crc function equivalent this).

you can start this:

var crc16ccitt = require('crc').crc16ccitt;  function checksum(message) {   var buf = new buffer(26);   buf.writeuint8(message.type,      0);   buf.writeuint8(message.address,   1);   buf.writeuint32le(message.dataid, 2);   (var = 0; < 5; i++) {     buf.writeuint32le(message.data[i], 6 + * 4);   }   return crc16ccitt(buf); } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -