Skip to content

Commit 2c9ab5d

Browse files
committed
feat: use kboot native firmare upgrade
1 parent 31d4106 commit 2c9ab5d

15 files changed

Lines changed: 279 additions & 143 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function crc16XModem(data: ArrayLike<unknown>): number;
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TODO: eliminate the duplication of the uhk-usb-module
21
const CRC16TABLE = new Uint16Array([
32
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
43
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
@@ -34,7 +33,13 @@ const CRC16TABLE = new Uint16Array([
3433
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
3534
]);
3635

37-
export default function crc16(data: ArrayLike<number>): number {
36+
/**
37+
* CRC-16/XMODEM (poly 0x1021, init 0x0000, no reflection, xorout 0x0000)
38+
*
39+
* @param {ArrayLike<*>} data
40+
* @returns {number}
41+
*/
42+
export default function crc16XModem(data) {
3843
let crc = 0;
3944
const l = data.length;
4045
for (let i = 0; i < l; i++) {

packages/crc16-xmodem/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/crc16-xmodem/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "crc16-xmodem",
3+
"private": true,
4+
"type": "module",
5+
"version": "1.0.0",
6+
"description": "Some filesystem helper function",
7+
"main": "lib/index.js",
8+
"types": "lib/index.d.ts",
9+
"author": "Ultimate Gadget Laboratories",
10+
"repository": {
11+
"type": "git",
12+
"url": "git@github.com:UltimateHackingKeyboard/agent.git"
13+
},
14+
"scripts": {
15+
"build:user-config": "tsx ./scripts/generate-user-configs.ts",
16+
"clean": "rimraf ./node_modules",
17+
"test": "node --test",
18+
"lint": "eslint"
19+
},
20+
"license": "GPL-3.0"
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {it, test} from 'node:test';
2+
3+
import crc16XModem from "../lib/index.js";
4+
5+
test('standard check vector "123456789" → 0x31C3', ({ assert }) => {
6+
assert.strictEqual(crc16XModem(Buffer.from('123456789')), 0x31C3);
7+
});
8+
9+
test('empty buffer returns init value', ({ assert }) => {
10+
assert.strictEqual(crc16XModem([]), 0x0000); // XModem init is 0
11+
});
12+
13+
test('single byte', ({ assert }) => {
14+
assert.strictEqual(crc16XModem([0x00]), 0x0000);
15+
assert.strictEqual(crc16XModem([0xFF]), 0x1EF0);
16+
});
17+
18+
it('uhk command', ({ assert }) => {
19+
const crc = crc16XModem([
20+
0x02, 0x00, 0x00, 0x09, 0x00, 0x00, 0x09, 0x00,
21+
0xA1, 0x61, 0x64, 0x65, 0x68, 0x65, 0x6C, 0x6C,
22+
0x6F,
23+
]);
24+
25+
assert.strictEqual(crc, 24488);
26+
});

packages/mcumgr/package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mcumgr/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"scripts": {
88
"build": "tsc --project ./src/tsconfig.json",
99
"clean": "rimraf ./node_modules ./dist",
10-
"lint": "eslint",
11-
"test": "node --loader=ts-node/esm --test \"**/*.test.ts\""
10+
"lint": "eslint"
1211
},
1312
"keywords": [
1413
"mcu",
@@ -19,6 +18,7 @@
1918
"license": "See in LICENSE",
2019
"description": "Micro controller manager utility",
2120
"dependencies": {
21+
"crc16-xmodem": "file:../crc16-xmodem",
2222
"debug": "^4.4.1",
2323
"tslib": "^2.8.1"
2424
},

packages/mcumgr/src/serial-peripheral.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import debug from 'debug';
22
import {setTimeout} from 'node:timers/promises';
3+
import crc16 from 'crc16-xmodem';
34
import {SerialPort} from 'serialport';
45

56
import { Peripheral } from './peripheral.js';
6-
import crc16 from './util/crc16.js';
77
import toUint16 from './util/to-uint16.js';
88
import convertToHex from './util/convert-to-hex.js';
99
import fromUint16 from "./util/from-uint16.js";

packages/mcumgr/test/util/crc16.test.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)