Added an init packet which (for recent DFU OTA protocols) must transferred before the firmware image.

This commit is contained in:
Michael Dietz
2016-02-17 13:08:26 +01:00
parent 160889f638
commit ccd602838c
2 changed files with 16 additions and 3 deletions

15
dist/dfu.js vendored
View File

@@ -132,6 +132,17 @@
});
}
/**
* Contains basic functionality for performing safety checks on software updates for nRF5 based devices.
* Init packet used for pre-checking to ensure the following image is compatible with the device.
* Contains information on device type, revision, and supported SoftDevices along with a CRC or hash of firmware image.
*
* Not used in mbed bootloader.
*/
function generateInitPacket() {
return new Uint8Array([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0xFE, 0xFF, 0x00, 0x00]); // Temporary init packet.
}
function provision(device, arrayBuffer, imageType) {
return new Promise(function(resolve, reject) {
log('function provision(device, arrayBuffer, imageType)');
@@ -289,11 +300,11 @@
var req_opcode = view.getUint8(1);
if (req_opcode === 1 && majorVersion > 6) {
log('write null init packet');
log('write init packet');
controlChar.writeValue(new Uint8Array([2,0]))
.then(() => {
return packetChar.writeValue(new Uint8Array([0]));
return packetChar.writeValue(generateInitPacket());
})
.then(() => {
return controlChar.writeValue(new Uint8Array([2,1]));

View File

@@ -14,6 +14,7 @@
<script>
var urlMask = "//thegecko.github.io/web-bluetooth-dfu/firmware/NRF51822_{0}_Rob_OTA.hex";
var urlMask52 = "https://raw.githubusercontent.com/mjdietzx/web-bluetooth-dfu/develop/firmware/ble_app_hrs_with_dfu_nrf52.hex";
var resultsEl = document.getElementById("results");
function log(message) {
@@ -35,7 +36,8 @@
function transfer(device) {
return new Promise(function(resolve, reject) {
var url = urlMask.replace("{0}", device.name === "Hi_Rob" ? "Bye" : "Hi");
//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 => {