Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

crc1.js 709B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var _buffer = require('buffer');
  3. var _create_buffer = require('./create_buffer');
  4. var _create_buffer2 = _interopRequireDefault(_create_buffer);
  5. var _define_crc = require('./define_crc');
  6. var _define_crc2 = _interopRequireDefault(_define_crc);
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. module.exports = (0, _define_crc2.default)('crc1', function (buf, previous) {
  9. if (!_buffer.Buffer.isBuffer(buf)) buf = (0, _create_buffer2.default)(buf);
  10. var crc = ~~previous;
  11. var accum = 0;
  12. for (var index = 0; index < buf.length; index++) {
  13. var byte = buf[index];
  14. accum += byte;
  15. }
  16. crc += accum % 256;
  17. return crc % 256;
  18. });