From 46bd6f71613fad27ccfd8eaea9ac1a6943eb54a8 Mon Sep 17 00:00:00 2001 From: chopster44 Date: Mon, 1 Dec 2025 20:47:48 +0000 Subject: [PATCH] track recieved data size to avoid false branching --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index cc02db3..2996b55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -247,11 +247,11 @@ export default class Updater { (rawData: ArrayBuffer): void => { let dataView = new Uint8Array(rawData); console.log(dataView); - if (dataView[0] == 1) { + if (dataView[0] == 1 && dataView.length == 1) { // send file this.sendNextPacket(); progressCallback(`MTU: ${this._packetSize}; Sending (${Math.floor((this._fileProgress *100)/this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`); - } else if (dataView[0] == 2) { + } else if (dataView[0] == 2 && dataView.length == 1) { // done logic console.log(`progress >= filesize: ${this._fileProgress} vs ${this._fileSize}`); if (this._fileProgress >= (this._fileSize - this._packetSize)) { @@ -276,11 +276,11 @@ export default class Updater { progressCallback(`Error, starting over: ${this._fileProgress} / ${this._fileSize}`); this._fileProgress = 0; } - } else if (dataView[0] == 15) { + } else if (dataView[0] == 15 && dataView.length == 1) { // error cmd progressCallback(`Error on remote: ${this._fileProgress} / ${this._fileSize}`); reject("Error on remote"); - } else if (dataView[0] == 0) { + } else if (dataView[0] == 0 && dataView.length == 1) { // ignore no command progressCallback(`Board is on`); }