From 68aedf6969856f62891fcd3e33f3879cbac77bbf Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 24 Oct 2024 23:19:04 +0200 Subject: [PATCH] fix: shorten preamble, skip empty screens --- packages/serial/src/ZWaveSerialPortBase.ts | 4 +++- packages/serial/src/parsers/BootloaderParsers.ts | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/serial/src/ZWaveSerialPortBase.ts b/packages/serial/src/ZWaveSerialPortBase.ts index 803b6e4465e9..0f445df97f77 100644 --- a/packages/serial/src/ZWaveSerialPortBase.ts +++ b/packages/serial/src/ZWaveSerialPortBase.ts @@ -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; diff --git a/packages/serial/src/parsers/BootloaderParsers.ts b/packages/serial/src/parsers/BootloaderParsers.ts index 18836aa1f0a5..c97d2be2efe2 100644 --- a/packages/serial/src/parsers/BootloaderParsers.ts +++ b/packages/serial/src/parsers/BootloaderParsers.ts @@ -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); } @@ -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(?\d+\.\d+\.\d+)/; const menuSuffix = "BL >"; const optionsRegex = /^(?\d+)\. (?