Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/crc16-xmodem/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function crc16XModem(data: ArrayLike<unknown>): number;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ const CRC16TABLE = new Uint16Array([
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
]);

export default function crc16(data: ArrayLike<number>): number {
/**
* CRC-16/XMODEM (poly 0x1021, init 0x0000, no reflection, xorout 0x0000)
*
* @param {ArrayLike<*>} data
* @returns {number}
*/
export default function crc16XModem(data) {
let crc = 0;
const l = data.length;
for (let i = 0; i < l; i++) {
Expand Down
13 changes: 13 additions & 0 deletions packages/crc16-xmodem/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions packages/crc16-xmodem/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "crc16-xmodem",
"private": true,
"type": "module",
"version": "1.0.0",
"description": "Some filesystem helper function",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "Ultimate Gadget Laboratories",
"repository": {
"type": "git",
"url": "git@github.com:UltimateHackingKeyboard/agent.git"
},
"scripts": {
"build:user-config": "tsx ./scripts/generate-user-configs.ts",
"clean": "rimraf ./node_modules",
"test": "node --test",
"lint": "eslint"
},
"license": "GPL-3.0"
}
26 changes: 26 additions & 0 deletions packages/crc16-xmodem/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {it, test} from 'node:test';

import crc16XModem from "../lib/index.js";

test('standard check vector "123456789" → 0x31C3', ({ assert }) => {
assert.strictEqual(crc16XModem(Buffer.from('123456789')), 0x31C3);
});

test('empty buffer returns init value', ({ assert }) => {
assert.strictEqual(crc16XModem([]), 0x0000); // XModem init is 0
});

test('single byte', ({ assert }) => {
assert.strictEqual(crc16XModem([0x00]), 0x0000);
assert.strictEqual(crc16XModem([0xFF]), 0x1EF0);
});

it('uhk command', ({ assert }) => {
const crc = crc16XModem([
0x02, 0x00, 0x00, 0x09, 0x00, 0x00, 0x09, 0x00,
0xA1, 0x61, 0x64, 0x65, 0x68, 0x65, 0x6C, 0x6C,
0x6F,
]);

assert.strictEqual(crc, 24488);
});
31 changes: 31 additions & 0 deletions packages/mcumgr/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/mcumgr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"scripts": {
"build": "tsc --project ./src/tsconfig.json",
"clean": "rimraf ./node_modules ./dist",
"lint": "eslint",
"test": "node --loader=ts-node/esm --test \"**/*.test.ts\""
"lint": "eslint"
},
"keywords": [
"mcu",
Expand All @@ -19,6 +18,7 @@
"license": "See in LICENSE",
"description": "Micro controller manager utility",
"dependencies": {
"crc16-xmodem": "file:../crc16-xmodem",
"debug": "^4.4.1",
"tslib": "^2.8.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mcumgr/src/serial-peripheral.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import debug from 'debug';
import {setTimeout} from 'node:timers/promises';
import crc16 from 'crc16-xmodem';
import {SerialPort} from 'serialport';

import { Peripheral } from './peripheral.js';
import crc16 from './util/crc16.js';
import toUint16 from './util/to-uint16.js';
import convertToHex from './util/convert-to-hex.js';
import fromUint16 from "./util/from-uint16.js";
Expand Down
15 changes: 0 additions & 15 deletions packages/mcumgr/test/util/crc16.test.ts

This file was deleted.

Loading
Loading