Skip to content

Commit

Permalink
fix: detect bootloader in more difficult cases (#7325)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Oct 27, 2024
1 parent 9acbad5 commit 5cd50f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions packages/serial/src/serialport/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

0 comments on commit 5cd50f5

Please sign in to comment.