Compare commits

...

45 Commits

Author SHA1 Message Date
6447692d4c (1.0.37) bump 2025-12-01 21:21:05 +00:00
855eb07d89 set file progress rather than adding 2025-12-01 21:20:55 +00:00
8e840c0966 (1.0.36) bump 2025-12-01 21:07:05 +00:00
5ab862d703 loading the file progress correctly 2025-12-01 21:06:56 +00:00
7c6f0e8a3e (1.0.35) bump 2025-12-01 20:59:49 +00:00
bda9dddd4f more logging 2025-12-01 20:59:41 +00:00
95709e0285 (1.0.34) bump 2025-12-01 20:56:24 +00:00
4c4b896978 more logging 2025-12-01 20:56:15 +00:00
c20c0b02cf (1.0.33) bump 2025-12-01 20:47:55 +00:00
46bd6f7161 track recieved data size to avoid false branching 2025-12-01 20:47:48 +00:00
eeb90f630d (1.0.32) bump 2025-12-01 20:45:31 +00:00
bccbd61ad5 log recieved file progress 2025-12-01 20:44:27 +00:00
2017847b9e (1.0.31) bump 2025-12-01 20:30:50 +00:00
b471d0e20f trying file progress from remote, due to packet loss 2025-12-01 20:30:37 +00:00
a7d5880057 (1.0.30) bump 2025-12-01 18:40:16 +00:00
e5ce96adcf only add to progress the number of bytes written 2025-12-01 18:40:08 +00:00
27403e0aed (1.0.29) bump 2025-12-01 18:33:57 +00:00
faf4e377d7 trying a different way to confirm mtu size 2025-12-01 18:33:48 +00:00
ed4890818f (1.0.28) bump 2025-12-01 18:24:51 +00:00
0f61fd26c5 mtu logging 2025-12-01 18:24:40 +00:00
d1927bc24e (1.0.27) bump 2025-12-01 18:08:02 +00:00
1b7719ac3d wait for mtu to be agreed 2025-12-01 18:07:50 +00:00
ebcfb38e41 (1.0.26) bump 2025-12-01 17:49:29 +00:00
ad7402f04b without responses again 2025-12-01 17:49:19 +00:00
e8e9547a20 (1.0.25) bump 2025-12-01 17:27:08 +00:00
852fcf67f4 going back to writing with response due to transmission issues 2025-12-01 17:26:43 +00:00
e798f997d3 (1.0.24) bump 2025-11-30 21:58:24 +00:00
d2f9809f52 (1.0.23) bump 2025-11-30 21:47:57 +00:00
3e7c26e3ba file progress in more places 2025-11-30 21:47:47 +00:00
e5912cd94e (1.0.22) bump 2025-11-30 21:43:00 +00:00
20c203ffa4 fix packet size issue 2025-11-30 21:42:47 +00:00
ad464e1c0d (1.0.21) bump 2025-11-30 21:20:50 +00:00
5009b0c8d1 Reducing number of awaits for speed 2025-11-30 21:20:33 +00:00
b13787b704 (1.0.20) bump 2025-11-30 21:11:31 +00:00
b155baed03 do file progress counter preemtively 2025-11-30 21:11:05 +00:00
41a2e30aca (1.0.19) bump 2025-11-30 17:42:03 +00:00
266044215d dbg 2025-11-30 17:41:52 +00:00
418df318ee (1.0.18) bump 2025-11-30 16:51:58 +00:00
896cccd7ff More debug 2025-11-30 16:51:45 +00:00
66cbb31dde (1.0.17) bump 2025-11-30 12:02:38 +00:00
90b8e08946 actually count up file progress 2025-11-30 12:02:21 +00:00
4900cf6acd (1.0.16) dbg 2025-11-30 11:47:25 +00:00
3e07911cac Some debug messages 2025-11-30 11:46:58 +00:00
8c3dd4c2e3 (1.0.15) bump 2025-11-29 23:15:37 +00:00
3bae392285 communicate error 2025-11-29 23:15:17 +00:00
4 changed files with 127 additions and 68 deletions

64
dist/index.cjs.js vendored
View File

@@ -175,10 +175,13 @@ class Updater {
}
async sendNextPacket() {
let packet = this.file.slice(this._fileProgress, this._fileProgress + this._packetSize);
// this._fileProgress += this._packetSize;
return new Promise((resolve, reject) => {
this.bleObject.write(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer, () => {
this.bleObject.writeWithoutResponse(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer, () => {
console.log(`Sent: ${packet}, progress: ${this._fileProgress}`);
resolve(true);
}, (error) => {
this._fileProgress -= this._packetSize;
reject(error);
});
});
@@ -198,23 +201,24 @@ 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);
// set mtu
this._packetSize = await this.bleObject.withPromises.requestMtu(this.bleDeviceId, this._packetSize);
// start notify
this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, async (rawData) => {
let dataView = new Int8Array(rawData);
if (dataView[0] == 1) {
this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, (rawData) => {
let dataView = new Uint8Array(rawData);
console.log(dataView);
if (dataView[0] == 1 && dataView.length == 1) {
// send file
await this.sendNextPacket();
progressCallback(`Sending (${Math.floor((this._fileProgress * 100) / this._fileSize)})`);
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
if (this._fileProgress >= this._fileSize) {
console.log(`progress >= filesize: ${this._fileProgress} vs ${this._fileSize}`);
if (this._fileProgress >= (this._fileSize - this._packetSize)) {
console.log("true");
// send agree
await this.sendEndCmd(true);
this.sendEndCmd(true);
progressCallback(`Complete!`);
this.bleObject.stopNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, () => {
// success
@@ -224,23 +228,39 @@ class Updater {
});
}
else {
console.log("False");
// send disagree
await this.sendEndCmd(false);
progressCallback(`Error, starting over`);
this.sendEndCmd(false);
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`);
progressCallback(`Error on remote: ${this._fileProgress} / ${this._fileSize}`);
reject("Error on remote");
}
else {
// no command
progressCallback(`Error on remote`);
reject("Error: command does not exist");
else if (dataView[0] == 0 && dataView.length == 1) {
// ignore no command
progressCallback(`Board is on`);
}
}, () => { reject("Error: Failed to start notify"); });
else {
// should be the file progress
let fileProgressView = new Uint32Array(rawData);
this._fileProgress = (dataView[3] << 24) |
(dataView[2] << 16) |
(dataView[1] << 8) | dataView[0];
this.sendNextPacket();
progressCallback(`Recieved progress ${fileProgressView[0]}; Sending (${Math.floor((this._fileProgress * 100) / this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`);
}
}, (error) => {
reject("Error: Failed to start notify");
console.error(error);
});
const buffer = new ArrayBuffer(4);
let view = new Int32Array(buffer);
view[0] = this._fileSize;
this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer);
});
}
}

64
dist/index.es.js vendored
View File

@@ -173,10 +173,13 @@ class Updater {
}
async sendNextPacket() {
let packet = this.file.slice(this._fileProgress, this._fileProgress + this._packetSize);
// this._fileProgress += this._packetSize;
return new Promise((resolve, reject) => {
this.bleObject.write(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer, () => {
this.bleObject.writeWithoutResponse(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer, () => {
console.log(`Sent: ${packet}, progress: ${this._fileProgress}`);
resolve(true);
}, (error) => {
this._fileProgress -= this._packetSize;
reject(error);
});
});
@@ -196,23 +199,24 @@ 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);
// set mtu
this._packetSize = await this.bleObject.withPromises.requestMtu(this.bleDeviceId, this._packetSize);
// start notify
this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, async (rawData) => {
let dataView = new Int8Array(rawData);
if (dataView[0] == 1) {
this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, (rawData) => {
let dataView = new Uint8Array(rawData);
console.log(dataView);
if (dataView[0] == 1 && dataView.length == 1) {
// send file
await this.sendNextPacket();
progressCallback(`Sending (${Math.floor((this._fileProgress * 100) / this._fileSize)})`);
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
if (this._fileProgress >= this._fileSize) {
console.log(`progress >= filesize: ${this._fileProgress} vs ${this._fileSize}`);
if (this._fileProgress >= (this._fileSize - this._packetSize)) {
console.log("true");
// send agree
await this.sendEndCmd(true);
this.sendEndCmd(true);
progressCallback(`Complete!`);
this.bleObject.stopNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, () => {
// success
@@ -222,23 +226,39 @@ class Updater {
});
}
else {
console.log("False");
// send disagree
await this.sendEndCmd(false);
progressCallback(`Error, starting over`);
this.sendEndCmd(false);
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`);
progressCallback(`Error on remote: ${this._fileProgress} / ${this._fileSize}`);
reject("Error on remote");
}
else {
// no command
progressCallback(`Error on remote`);
reject("Error: command does not exist");
else if (dataView[0] == 0 && dataView.length == 1) {
// ignore no command
progressCallback(`Board is on`);
}
}, () => { reject("Error: Failed to start notify"); });
else {
// should be the file progress
let fileProgressView = new Uint32Array(rawData);
this._fileProgress = (dataView[3] << 24) |
(dataView[2] << 16) |
(dataView[1] << 8) | dataView[0];
this.sendNextPacket();
progressCallback(`Recieved progress ${fileProgressView[0]}; Sending (${Math.floor((this._fileProgress * 100) / this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`);
}
}, (error) => {
reject("Error: Failed to start notify");
console.error(error);
});
const buffer = new ArrayBuffer(4);
let view = new Int32Array(buffer);
view[0] = this._fileSize;
this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer);
});
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "updaterweblibrary",
"version": "1.0.14",
"version": "1.0.37",
"description": "OTA Updater App frontend library",
"repository": {
"type": "git",

View File

@@ -209,12 +209,15 @@ export default class Updater {
private async sendNextPacket(): Promise<boolean> {
let packet = this.file.slice(this._fileProgress, this._fileProgress+this._packetSize);
// this._fileProgress += this._packetSize;
return new Promise((resolve, reject) => {
this.bleObject.write(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer,
this.bleObject.writeWithoutResponse(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer,
() => {
console.log(`Sent: ${packet}, progress: ${this._fileProgress}`);
resolve(true);
},
(error) => {
this._fileProgress -= this._packetSize;
reject(error);
}
)
@@ -238,24 +241,24 @@ export default class Updater {
// 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);
// set mtu
this._packetSize = await this.bleObject.withPromises.requestMtu(this.bleDeviceId, this._packetSize);
// start notify
this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID,
async (rawData: ArrayBuffer): Promise<void> => {
let dataView = new Int8Array(rawData);
if (dataView[0] == 1) {
(rawData: ArrayBuffer): void => {
let dataView = new Uint8Array(rawData);
console.log(dataView);
if (dataView[0] == 1 && dataView.length == 1) {
// send file
await this.sendNextPacket();
progressCallback(`Sending (${Math.floor((this._fileProgress *100)/this._fileSize)})`);
} else if (dataView[0] == 2) {
this.sendNextPacket();
progressCallback(`MTU: ${this._packetSize}; Sending (${Math.floor((this._fileProgress *100)/this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`);
} else if (dataView[0] == 2 && dataView.length == 1) {
// done logic
if (this._fileProgress >= this._fileSize) {
console.log(`progress >= filesize: ${this._fileProgress} vs ${this._fileSize}`);
if (this._fileProgress >= (this._fileSize - this._packetSize)) {
console.log("true");
// send agree
await this.sendEndCmd(true);
this.sendEndCmd(true);
progressCallback(`Complete!`);
this.bleObject.stopNotification(this.bleDeviceId,
this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID,
@@ -268,21 +271,37 @@ export default class Updater {
}
);
} else {
console.log("False");
// send disagree
await this.sendEndCmd(false);
progressCallback(`Error, starting over`);
this.sendEndCmd(false);
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`);
progressCallback(`Error on remote: ${this._fileProgress} / ${this._fileSize}`);
reject("Error on remote");
} else {
// no command
progressCallback(`Error on remote`);
reject("Error: command does not exist");
} else if (dataView[0] == 0 && dataView.length == 1) {
// ignore no command
progressCallback(`Board is on`);
}
else {
// should be the file progress
let fileProgressView = new Uint32Array(rawData);
this._fileProgress = (dataView[3] << 24) |
(dataView[2] << 16) |
(dataView[1] << 8) | dataView[0];
this.sendNextPacket();
progressCallback(`Recieved progress ${fileProgressView[0]}; Sending (${Math.floor((this._fileProgress *100)/this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`);
}
}, () => { reject("Error: Failed to start notify"); });
}, (error) => { reject("Error: Failed to start notify");
console.error(error);
}
);
const buffer = new ArrayBuffer(4)
let view = new Int32Array(buffer);
view[0] = this._fileSize;
this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer);
});
}
}