control-freak-ide/server/nodejs/nxapp/protocols/utils/lrc.js
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

16 lines
323 B
JavaScript

"use strict";
/**
* Calculates the buffers LRC.
*
* @param {Buffer} buffer the data buffer.
* @return {number} the calculated LRC.
*/
module.exports = function lrc(buffer) {
var lrc = 0;
for (var i = 0; i < buffer.length; i++) {
lrc += buffer[i] & 0xFF;
}
return ((lrc ^ 0xFF) + 1) & 0xFF;
};