Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rework NVM access, support incremental NVM modification over serial #7153

Merged
merged 19 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions packages/core/src/error/ZWaveError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export enum ZWaveErrorCodes {
NVM_InvalidFormat,
/** Not enough space in the NVM */
NVM_NoSpace,
/** The NVM hasn't been opened yet */
NVM_NotOpen,

CC_Invalid = 300,
CC_NoNodeID,
Expand Down
8 changes: 4 additions & 4 deletions packages/nvmedit/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
jsonToNVM500,
migrateNVM,
nvm500ToJSON,
nvmToJSON,
nvmToJSONOld,
} from "./convert";
import "./index";

Expand Down Expand Up @@ -47,7 +47,7 @@ void yargs
const buffer = await fs.readFile(argv.in);
let json: any;
try {
json = nvmToJSON(buffer, argv.verbose);
json = nvmToJSONOld(buffer, argv.verbose);
} catch (e) {
try {
json = nvm500ToJSON(buffer);
Expand Down Expand Up @@ -119,7 +119,7 @@ Create a backup of the target stick, use the nvm2json command to convert it to J

const nvm = versionIs500
? jsonToNVM500(json, protocolVersion)
: jsonToNVM(json, protocolVersion);
: await jsonToNVM(json, protocolVersion);
await fs.writeFile(argv.out, nvm);
console.error(`NVM (binary) written to ${argv.out}`);

Expand Down Expand Up @@ -217,7 +217,7 @@ Create a backup of the target stick, use the nvm2json command to convert it to J
async (argv) => {
const source = await fs.readFile(argv.source);
const target = await fs.readFile(argv.target);
const output = migrateNVM(source, target);
const output = await migrateNVM(source, target);
await fs.writeFile(argv.out, output);
console.error(`Converted NVM written to ${argv.out}`);

Expand Down
14 changes: 7 additions & 7 deletions packages/nvmedit/src/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { NVM500JSON } from "./nvm500/NVMParser";
for (const file of files) {
test(`${suite} -> ${file}`, async (t) => {
const data = await fs.readFile(path.join(fixturesDir, file));
const json = nvmToJSON(data);
const json = await nvmToJSON(data);
t.snapshot(json);
});
}
Expand All @@ -36,14 +36,14 @@ import type { NVM500JSON } from "./nvm500/NVMParser";

for (const file of files) {
test(`${suite} -> ${file}`, async (t) => {
const jsonInput: Required<NVMJSON> = await fs.readJson(
const jsonInput: NVMJSON = await fs.readJson(
path.join(fixturesDir, file),
);
const nvm = jsonToNVM(
const nvm = await jsonToNVM(
jsonInput,
jsonInput.controller.applicationVersion,
);
const jsonOutput = nvmToJSON(nvm);
const jsonOutput = await nvmToJSON(nvm);
// @ts-expect-error
if (!("meta" in jsonInput)) delete jsonOutput.meta;

Expand All @@ -66,8 +66,8 @@ import type { NVM500JSON } from "./nvm500/NVMParser";
const nvmIn = await fs.readFile(path.join(fixturesDir, file));

const version = /_(\d+\.\d+\.\d+)[_.]/.exec(file)![1];
const json = nvmToJSON(nvmIn);
const nvmOut = jsonToNVM(json, version);
const json = await nvmToJSON(nvmIn);
const nvmOut = await jsonToNVM(json, version);

t.deepEqual(nvmOut, nvmIn);
});
Expand Down Expand Up @@ -190,7 +190,7 @@ test("700 to 700 migration shortcut", async (t) => {
const nvmTarget = await fs.readFile(
path.join(fixturesDir, "ctrlr_backup_700_7.16_1.bin"),
);
const converted = migrateNVM(nvmSource, nvmTarget);
const converted = await migrateNVM(nvmSource, nvmTarget);

t.deepEqual(converted, nvmSource);
});
1 change: 1 addition & 0 deletions packages/nvmedit/src/convert.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6984,6 +6984,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

{
applicationFileFormat: 4,
controller: {
applicationData: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
applicationName: null,
Expand Down
Binary file modified packages/nvmedit/src/convert.test.ts.snap
Binary file not shown.
Loading
Loading