lizijie
2021-09-18 7069042cf6f6484a59c134547f8f8d54bb201662
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function crc16_checkout(puchMsg, usDataLen) {
    let crc_reg=0xFFFF;
    let check;
    for(let i =0; i<usDataLen;i++){
        crc_reg = (crc_reg>>8) ^ puchMsg.charCodeAt(i);
        for(let j =0; j<8; j++){
            check = crc_reg & 0x0001;
            crc_reg >>= 1;
            if(check == 0x0001){
                crc_reg ^= 0xA001;
            }
        }
    }
 
    return crc_reg.toString(16).toUpperCase();
}
 
 
// let b = 'QN=20160801085857223;ST=32;CN=1062;PW=100000;MN=010000A8900016F000169DC0;Flag=5;CP=&&RtdInterval=30&&';
// let a = crc16_checkout(b, b.length);
// console.log(a.toString(16).toUpperCase());
 
module.exports = crc16_checkout;