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

fix: detect bootloader in more difficult cases #7327

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
22 changes: 19 additions & 3 deletions packages/serial/src/ZWaveSerialPortBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,25 @@ export class ZWaveSerialPortBase extends PassThrough {
const str = (data as Buffer).toString("ascii")
// like .trim(), but including null bytes
.replaceAll(/^[\s\0]+|[\s\0]+$/g, "");
this.mode = str.startsWith(bootloaderMenuPreamble)
? ZWaveSerialMode.Bootloader
: ZWaveSerialMode.SerialAPI;

if (str.startsWith(bootloaderMenuPreamble)) {
// We're sure we're in bootloader mode
this.mode = ZWaveSerialMode.Bootloader;
} else if (
(data as Buffer).every((b) =>
b === 0x00
|| b === 0x0a
|| b === 0x0d
|| (b >= 0x20 && b <= 0x7e)
) && (data as Buffer).some((b) => b >= 0x20 && b <= 0x7e)
) {
// Only printable line breaks, null bytes and at least one printable ASCII character
// --> We're pretty sure we're in bootloader mode
this.mode = ZWaveSerialMode.Bootloader;
} else {
// We're in Serial API mode
this.mode = ZWaveSerialMode.SerialAPI;
}
}

// On Windows, writing to the parsers immediately seems to lag the event loop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ integrationTest(
// ctrl.length === 1
// && (ctrl[0] === MessageHeaders.NAK || ctrl[0] === 0x32)
// ) {
// I've seen logs with as few as 5 bytes in the first chunk
self.serial.emitData(
Buffer.from("\0\r\nGecko Bootloa", "ascii"),
Buffer.from("\0\r\nGeck", "ascii"),
);
await wait(20);
self.serial.emitData(Buffer.from(
`der v2.05.01
`o Bootloader v2.05.01
1. upload gbl
2. run
3. ebl info
Expand Down
Loading