mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-13 04:28:13 +08:00
Switch to bootloader/DFU mode working for recent revisions of DFU OTA protocol.
This commit is contained in:
30
dist/dfu.js
vendored
30
dist/dfu.js
vendored
@@ -88,24 +88,36 @@
|
|||||||
/**
|
/**
|
||||||
* Switch to bootloader/DFU mode by writing to the control point of the DFU Service.
|
* Switch to bootloader/DFU mode by writing to the control point of the DFU Service.
|
||||||
* The DFU Controller is not responsible for disconnecting from the application (DFU Target) after the write.
|
* The DFU Controller is not responsible for disconnecting from the application (DFU Target) after the write.
|
||||||
* The application (DFU Target) will issue a GAP Disconnect and reset into Bootloader/DFU mode.
|
* The application (DFU Target) will issue a GAP Disconnect and reset into bootloader/DFU mode.
|
||||||
|
*
|
||||||
|
* https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/bledfu_appswitching.html?cp=4_0_0_4_1_3_2_2
|
||||||
*/
|
*/
|
||||||
function writeMode(device) {
|
function writeMode(device) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
var characteristics = null;
|
||||||
/*
|
/*
|
||||||
// Disconnect event currently not implemented...
|
// Disconnect event currently not implemented...
|
||||||
device.addEventListener("gattserverdisconnected", () => {
|
device.addEventListener("gattserverdisconnected", () => {
|
||||||
log("DFU Target issued GAP Disconnect and reset into Bootloader/DFU mode.");
|
log("DFU Target issued GAP Disconnect and reset into Bootloader/DFU mode.");
|
||||||
resolve(device);
|
resolve(device);
|
||||||
});
|
});
|
||||||
|
|
||||||
*/
|
*/
|
||||||
connect(device)
|
connect(device)
|
||||||
.then(chars => {
|
.then(chars => {
|
||||||
log("Writing modeData...");
|
log("enabling notifications");
|
||||||
return chars.controlChar.writeValue(new Uint8Array([1]))
|
characteristics = chars;
|
||||||
|
return characteristics.controlChar.startNotifications()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log("modeData Written.");
|
characteristics.controlChar.addEventListener('characteristicvaluechanged', handleNotifications);
|
||||||
resolve(device); // Once disconnect event is implemented we should resolve in its callback...
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
log("writing modeData");
|
||||||
|
return characteristics.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 => {
|
.catch(error => {
|
||||||
@@ -113,11 +125,17 @@
|
|||||||
log(error);
|
log(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function handleNotifications(event) {
|
||||||
|
log('received notification on control characteristic - ERROR this should not happen');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function provision(device, arrayBuffer, imageType) {
|
function provision(device, arrayBuffer, imageType) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
log('function provision(device, arrayBuffer, imageType)');
|
||||||
|
|
||||||
imageType = imageType || ImageType.Application;
|
imageType = imageType || ImageType.Application;
|
||||||
|
|
||||||
connect(device)
|
connect(device)
|
||||||
@@ -149,6 +167,8 @@
|
|||||||
|
|
||||||
function connect(device) {
|
function connect(device) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
log('function connect(device)');
|
||||||
|
|
||||||
var server = null;
|
var server = null;
|
||||||
var service = null;
|
var service = null;
|
||||||
var controlChar = null;
|
var controlChar = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user