How to use the crc16xmodem function from crc
Find comprehensive JavaScript crc.crc16xmodem code examples handpicked from public code repositorys.
crc.crc16xmodem is a method used to calculate the CRC-16 checksum of a buffer or string using the XMODEM algorithm.
GitHub: exsilium/xmodem.js
368 369 370 371 372 373 374 375 376 377
blockData ]); log.info('SENDBLOCK! Data length: ' + blockData.length); log.info(sendBuffer); if(mode === 'crc') { var crcString = crc.crc16xmodem(blockData).toString(16); // Need to avoid odd string for Buffer creation if(crcString.length % 2 == 1) { crcString = '0'.concat(crcString); }
GitHub: GridSpace/carve-control
389 390 391 392 393 394 395 396 397 398
blockData ]); log.info('SENDBLOCK! Data length: ' + blockData.length); log.info(sendBuffer); if (mode === 'crc') { let crcString = crc.crc16xmodem(blockData).toString(16); // avoid odd string buffer lengths if (crcString.length % 2 == 1) { crcString = '0'.concat(crcString); }
+ 3 other calls in file
How does crc.crc16xmodem work?
The crc.crc16xmodem function calculates a 16-bit cyclic redundancy check (CRC) using the XMODEM polynomial algorithm on the input data, which can be a string, buffer, or array. The algorithm is based on a generator polynomial of x^16 + x^12 + x^5 + 1 (0x1021) and processes the data byte-by-byte in a serial manner, producing a 16-bit checksum at the end. The checksum is commonly used to detect data transmission errors.
93 94 95 96 97 98 99 100 101 102
}, 500); }); socket.on('buffer', (iButtonsString)=>{ let iButtonsBuffer = Buffer.alloc(iButtonsString.length/2, iButtonsString, 'hex'); let crc = crc16xmodem(iButtonsBuffer).toString(16); if(crc.length < 4){ switch(crc.length){ case 1: crc = `000${crc}`;
+ 5 other calls in file
881 882 883 884 885 886 887 888 889 890
} output() { var message = this._messageType.value + this._messageType.format(this._sourceDevice, this._param); return PlugwiseMessageConst.HEADER.value + message + crc.crc16xmodem(message).toString(16).toUpperCase().pad(4) + PlugwiseMessageConst.FOOTER.value; } toString(){ return "date d'envoi : " + this.dateEmitted + ", date acceptation : " + this.dateAccepted + ", source : " + this._sourceDevice.getMac() + ", nbreEssai : " + this.getTryCount() + ", output : " + this.output();
+ 7 other calls in file
Ai Example
1 2 3 4 5 6 7
const crc = require("crc"); const buffer = Buffer.from("Hello, world!", "utf8"); const checksum = crc.crc16xmodem(buffer); console.log(checksum); // Output: 14319
In this example, the crc.crc16xmodem method is imported from the crc package, and used to calculate the CRC-16 XMODEM checksum for a buffer that contains the string "Hello, world!" encoded as UTF-8. The resulting checksum value is then logged to the console.
96 97 98 99 100 101 102 103 104 105 106 107
/*setTimeout(() => {sendToJeedom({eventType: 'changeState', state : 'On', mac: '000D6F0000D3595D'})},1000) ; setTimeout(() => {sendToJeedom({eventType: 'changeState', state : 'Off', mac: '000D6F0000D3595D'})},1000) ;*/ //Test de class //var crc = require('crc'); //test = crc.crc16xmodem('00240707000D6F00002367151004973C0005F9C801850000047300074E0843A901').toString(16).toUpperCase(); //Logger.log("Test de crc : " + test.pad(4), LogType.INFO); /*var test = require('./plugwisejs/testdvt.js') var test2 = require('./plugwisejs/plugwiseMessage.js')
+ 3 other calls in file
crc.crcjam is the most popular function in crc (280 examples)