diff --git a/dist/index.cjs.js b/dist/index.cjs.js index 6e5e0fa..cd9bdb1 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -198,13 +198,10 @@ class Updater { // check for error // write file length return new Promise(async (resolve, reject) => { - const buffer = new ArrayBuffer(4); - let view = new Int32Array(buffer); - view[0] = this._fileSize; - await this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer); // start notify this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, async (rawData) => { - let dataView = new Int8Array(rawData); + let dataView = new Uint8Array(rawData); + console.log(dataView); if (dataView[0] == 1) { // send file await this.sendNextPacket(); @@ -235,6 +232,10 @@ class Updater { progressCallback(`Error on remote`); reject("Error on remote"); } + else if (dataView[0] == 0) { + // ignore no command + progressCallback(`Board is on`); + } else { // no command progressCallback(`Error on remote`); @@ -244,6 +245,10 @@ class Updater { reject("Error: Failed to start notify"); console.error(error); }); + const buffer = new ArrayBuffer(4); + let view = new Int32Array(buffer); + view[0] = this._fileSize; + await this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer); }); } } diff --git a/dist/index.es.js b/dist/index.es.js index 12793bb..f04eb23 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -196,13 +196,10 @@ class Updater { // check for error // write file length return new Promise(async (resolve, reject) => { - const buffer = new ArrayBuffer(4); - let view = new Int32Array(buffer); - view[0] = this._fileSize; - await this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer); // start notify this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, async (rawData) => { - let dataView = new Int8Array(rawData); + let dataView = new Uint8Array(rawData); + console.log(dataView); if (dataView[0] == 1) { // send file await this.sendNextPacket(); @@ -233,6 +230,10 @@ class Updater { progressCallback(`Error on remote`); reject("Error on remote"); } + else if (dataView[0] == 0) { + // ignore no command + progressCallback(`Board is on`); + } else { // no command progressCallback(`Error on remote`); @@ -242,6 +243,10 @@ class Updater { reject("Error: Failed to start notify"); console.error(error); }); + const buffer = new ArrayBuffer(4); + let view = new Int32Array(buffer); + view[0] = this._fileSize; + await this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer); }); } } diff --git a/package.json b/package.json index d61a7e5..5fc93c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "updaterweblibrary", - "version": "1.0.15", + "version": "1.0.16", "description": "OTA Updater App frontend library", "repository": { "type": "git",