Skip to content

Commit

Permalink
fix: shorten preamble, skip empty screens
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 24, 2024
1 parent bdbe73a commit 68aedf6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/serial/src/ZWaveSerialPortBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ export class ZWaveSerialPortBase extends PassThrough {
if (this.mode == undefined) {
// If we haven't figured out the startup mode yet,
// inspect the chunk to see if it contains the bootloader preamble
const str = (data as Buffer).toString("ascii").trim();
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;
Expand Down
7 changes: 5 additions & 2 deletions packages/serial/src/parsers/BootloaderParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export class BootloaderScreenParser extends Transform {
const screen = this.receiveBuffer.slice(0, nulCharIndex).trim();
this.receiveBuffer = this.receiveBuffer.slice(nulCharIndex + 1);

this.logger?.bootloaderScreen(screen);
if (screen === "") continue;

this.logger?.bootloaderScreen(screen);
this.push(screen);
}

Expand All @@ -107,7 +108,9 @@ export class BootloaderScreenParser extends Transform {
}
}

export const bootloaderMenuPreamble = "Gecko Bootloader";
// Sometimes the first chunk of the bootloader screen is relatively short,
// so we consider the following enough to detect the bootloader menu:
export const bootloaderMenuPreamble = "Gecko Boo";
const preambleRegex = /^Gecko Bootloader v(?<version>\d+\.\d+\.\d+)/;
const menuSuffix = "BL >";
const optionsRegex = /^(?<num>\d+)\. (?<option>.+)/gm;
Expand Down

0 comments on commit 68aedf6

Please sign in to comment.