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.

crc16_xmodem.js 912B

1234567891011121314151617181920212223242526272829303132333435
  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)('xmodem', function (buf, previous) {
  9. if (!_buffer.Buffer.isBuffer(buf)) buf = (0, _create_buffer2.default)(buf);
  10. var crc = typeof previous !== 'undefined' ? ~~previous : 0x0;
  11. for (var index = 0; index < buf.length; index++) {
  12. var byte = buf[index];
  13. var code = crc >>> 8 & 0xFF;
  14. code ^= byte & 0xFF;
  15. code ^= code >>> 4;
  16. crc = crc << 8 & 0xFFFF;
  17. crc ^= code;
  18. code = code << 5 & 0xFFFF;
  19. crc ^= code;
  20. code = code << 7 & 0xFFFF;
  21. crc ^= code;
  22. }
  23. return crc;
  24. });