28 lines
708 B
JavaScript
28 lines
708 B
JavaScript
|
'use strict';
|
||
|
|
||
|
var _buffer = require('buffer');
|
||
|
|
||
|
var _create_buffer = require('./create_buffer');
|
||
|
|
||
|
var _create_buffer2 = _interopRequireDefault(_create_buffer);
|
||
|
|
||
|
var _define_crc = require('./define_crc');
|
||
|
|
||
|
var _define_crc2 = _interopRequireDefault(_define_crc);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
module.exports = (0, _define_crc2.default)('crc1', function (buf, previous) {
|
||
|
if (!_buffer.Buffer.isBuffer(buf)) buf = (0, _create_buffer2.default)(buf);
|
||
|
|
||
|
var crc = ~~previous;
|
||
|
var accum = 0;
|
||
|
|
||
|
for (var index = 0; index < buf.length; index++) {
|
||
|
var byte = buf[index];
|
||
|
accum += byte;
|
||
|
}
|
||
|
|
||
|
crc += accum % 256;
|
||
|
return crc % 256;
|
||
|
});
|