mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-12 12:08:13 +08:00
Working for both mbed and current revisions of DFU OTA...
Minor problems like writeMode bug in mbed and CRC code is just 0x0 for now so will fail for init packet check.
This commit is contained in:
19
dist/dfu.js
vendored
19
dist/dfu.js
vendored
@@ -121,24 +121,21 @@
|
||||
log("DFU Target issued GAP Disconnect and reset into Bootloader/DFU mode.");
|
||||
resolve(device);
|
||||
});
|
||||
|
||||
*/
|
||||
connect(device)
|
||||
.then(chars => {
|
||||
log("enabling notifications");
|
||||
controlChar = chars.controlChar;
|
||||
return controlChar.startNotifications()
|
||||
.then(() => {
|
||||
controlChar.addEventListener('characteristicvaluechanged', handleNotifications);
|
||||
});
|
||||
return controlChar.startNotifications();
|
||||
})
|
||||
.then(() => {
|
||||
log("writing modeData");
|
||||
return controlChar.writeValue(new Uint8Array([1, 4]))
|
||||
controlChar.addEventListener('characteristicvaluechanged', handleNotifications);
|
||||
return controlChar.writeValue(new Uint8Array([1, 4]));
|
||||
})
|
||||
.then(() => {
|
||||
log("modeData written");
|
||||
resolve(device); // TODO: once disconnect event is implemented we should resolve in its callback...
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
error = "writeMode error: " + error;
|
||||
@@ -241,9 +238,9 @@
|
||||
log("found packet characteristic");
|
||||
packetChar = characteristic;
|
||||
service.getCharacteristic(versionUUID)
|
||||
.then(characteristic => { // Older DFU implementations (from older Nordic SDKs) have no DFU Version characteristic. So this may fail.
|
||||
.then(char => { // Older DFU implementations (from older Nordic SDKs) have no DFU Version characteristic. So this may fail.
|
||||
log("found version characteristic");
|
||||
versionChar = characteristic;
|
||||
versionChar = char;
|
||||
complete();
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -318,7 +315,7 @@
|
||||
var req_opcode = view.getUint8(1);
|
||||
var resp_code = view.getUint8(2);
|
||||
|
||||
if (opCode === 16) { // Response Code.
|
||||
if (opCode === OPCODE.RESPONSE_CODE) {
|
||||
if (resp_code !== 1) {
|
||||
var error = "error from control: " + resp_code;
|
||||
log(error);
|
||||
@@ -406,7 +403,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
} else if (opCode === OPCODE.PACKET_RECEIPT_NOTIFICATION) { // Packet Receipt Notification.
|
||||
} else if (opCode === OPCODE.PACKET_RECEIPT_NOTIFICATION) {
|
||||
var bytes = view.getUint32(1, LITTLE_ENDIAN);
|
||||
log('transferred: ' + bytes);
|
||||
writePacket(packetChar, arrayBuffer, 0);
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
|
||||
function transfer(device) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var url = urlMask.replace("{0}", device.name === "Hi_Rob" ? "Bye" : "Hi");
|
||||
//var url = urlMask52; // nRF52832 application (example BLE heart rate from Nordic SDK) for DFU OTA update.
|
||||
//var url = urlMask.replace("{0}", device.name === "Hi_Rob" ? "Bye" : "Hi");
|
||||
var url = urlMask52; // nRF52832 application (example BLE heart rate from Nordic SDK) for DFU OTA update.
|
||||
|
||||
download(url)
|
||||
.then(hex => {
|
||||
|
||||
Reference in New Issue
Block a user