Need help in correcting issues in CRC-ITU check method written in Javascript (node.js)

后端 未结 5 1893
甜味超标
甜味超标 2021-01-06 05:15

We are trying to code GPS device listener on Javascript.

While doing this, we are unable to develop the right script for the CRC-ITU error check. The explanation for

5条回答
  •  情歌与酒
    2021-01-06 05:52

    There are some crc packages on npm, but they may not work for you, I create a new one that is just a copy of c code from your link to document.

    Install crc-itu from terminal:

    npm install crc-itu
    

    app.js

    var crc16 = require('crc-itu').crc16;
    
    var crcInHex = crc16('0d0103588990501766460026', 'hex').toString(16);
    console.log(crcInHex); // will print 7bf9
    

    you can also try with these values, note: crc16(data).toString(16) => crc

    start          data              crc   end
    -------------------------------------------
    7878   0d0103588990501766460026  7bf9  0d0a
    7878   0d010358899050176646002a  b195  0d0a
    7878   0d010358899050176646002b  a01c  0d0a
    

提交回复
热议问题