trying a different way to confirm mtu size
This commit is contained in:
15
src/index.ts
15
src/index.ts
@@ -208,7 +208,7 @@ export default class Updater {
|
||||
}
|
||||
|
||||
private async sendNextPacket(): Promise<boolean> {
|
||||
let packet = this.file.slice(this._fileProgress, this._fileProgress+this._packetSize);
|
||||
let packet = this.file.slice(this._fileProgress, this._fileProgress + this._packetSize);
|
||||
this._fileProgress += this._packetSize;
|
||||
return new Promise((resolve, reject) => {
|
||||
this.bleObject.writeWithoutResponse(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer,
|
||||
@@ -241,8 +241,8 @@ export default class Updater {
|
||||
// write file length
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// set mtu
|
||||
this._packetSize = await this.bleObject.withPromises.requestMtu(this.bleDeviceId, this._packetSize);
|
||||
// start notify
|
||||
this.bleObject.requestMtu(this.bleDeviceId, this._packetSize, (mtu: number) => {
|
||||
this._packetSize = mtu;
|
||||
this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID,
|
||||
(rawData: ArrayBuffer): void => {
|
||||
let dataView = new Uint8Array(rawData);
|
||||
@@ -250,7 +250,7 @@ export default class Updater {
|
||||
if (dataView[0] == 1) {
|
||||
// send file
|
||||
this.sendNextPacket();
|
||||
progressCallback(`MTU: ${this._packetSize}; Sending (${Math.floor((this._fileProgress *100)/this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`);
|
||||
progressCallback(`MTU: ${this._packetSize}; Sending (${Math.floor((this._fileProgress * 100) / this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`);
|
||||
} else if (dataView[0] == 2) {
|
||||
// done logic
|
||||
console.log(`progress >= filesize: ${this._fileProgress} vs ${this._fileSize}`);
|
||||
@@ -289,7 +289,8 @@ export default class Updater {
|
||||
progressCallback(`Error on remote`);
|
||||
reject("Error: command does not exist");
|
||||
}
|
||||
}, (error) => { reject("Error: Failed to start notify");
|
||||
}, (error) => {
|
||||
reject("Error: Failed to start notify");
|
||||
console.error(error);
|
||||
}
|
||||
);
|
||||
@@ -298,6 +299,10 @@ export default class Updater {
|
||||
view[0] = this._fileSize;
|
||||
this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer);
|
||||
});
|
||||
|
||||
// start notify
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user