mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-16 22:18:13 +08:00
Updated hex2bin to accept loggers
This commit is contained in:
21
dist/hex2bin.js
vendored
21
dist/hex2bin.js
vendored
@@ -48,7 +48,19 @@
|
|||||||
EXTENDED_LINEAR_ADDRESS : '04',
|
EXTENDED_LINEAR_ADDRESS : '04',
|
||||||
START_LINEAR_ADDRESS: '05'
|
START_LINEAR_ADDRESS: '05'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var loggers = [];
|
||||||
|
function addLogger(loggerFn) {
|
||||||
|
if (typeof loggerFn === "function") {
|
||||||
|
loggers.push(loggerFn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function log(message) {
|
||||||
|
loggers.forEach(function(logger) {
|
||||||
|
logger(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The first record of type extended linear address in the provided hex file will store the start base address of the binary.
|
* The first record of type extended linear address in the provided hex file will store the start base address of the binary.
|
||||||
* Then the first data record's address offset will complete our start address.
|
* Then the first data record's address offset will complete our start address.
|
||||||
@@ -110,7 +122,7 @@
|
|||||||
* This is because we are not to send the Master Boot Record (under minAddress) when updating the SoftDevice.
|
* This is because we are not to send the Master Boot Record (under minAddress) when updating the SoftDevice.
|
||||||
* And we are not to send UICR data (above maxAddress) when updating the bootloader or application.
|
* And we are not to send UICR data (above maxAddress) when updating the bootloader or application.
|
||||||
*/
|
*/
|
||||||
return function(hex, minAddress, maxAddress) {
|
function convert(hex, minAddress, maxAddress) {
|
||||||
maxAddress = maxAddress || 0x80000; // This will always cut off the UICR and the user will not have to every specify this parameter.
|
maxAddress = maxAddress || 0x80000; // This will always cut off the UICR and the user will not have to every specify this parameter.
|
||||||
minAddress = minAddress || 0x0;
|
minAddress = minAddress || 0x0;
|
||||||
|
|
||||||
@@ -170,5 +182,10 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
return buffer;
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
addLogger: addLogger,
|
||||||
|
convert: convert
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ var fs = require('fs');
|
|||||||
|
|
||||||
var log = console.log;
|
var log = console.log;
|
||||||
dfu.addLogger(log);
|
dfu.addLogger(log);
|
||||||
|
hex2bin.addLogger(log);
|
||||||
|
|
||||||
var fileMask = "";
|
var fileMask = "";
|
||||||
var fileName = null;
|
var fileName = null;
|
||||||
@@ -38,7 +39,7 @@ dfu.findDevice({ services: [0x180D] })
|
|||||||
.then(device => {
|
.then(device => {
|
||||||
var file = fs.readFileSync(fileName);
|
var file = fs.readFileSync(fileName);
|
||||||
var hex = file.toString();
|
var hex = file.toString();
|
||||||
var buffer = hex2bin(hex);
|
var buffer = hex2bin.convert(hex);
|
||||||
log("file length: " + buffer.byteLength);
|
log("file length: " + buffer.byteLength);
|
||||||
|
|
||||||
return dfu.provision(device, buffer);
|
return dfu.provision(device, buffer);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
resultsEl.innerText += message + "\n";
|
resultsEl.innerText += message + "\n";
|
||||||
}
|
}
|
||||||
dfu.addLogger(log);
|
dfu.addLogger(log);
|
||||||
|
hex2bin.addLogger(log);
|
||||||
|
|
||||||
function download(url) {
|
function download(url) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
@@ -67,7 +68,7 @@
|
|||||||
|
|
||||||
download(url)
|
download(url)
|
||||||
.then(hex => {
|
.then(hex => {
|
||||||
var buffer = hex2bin(hex);
|
var buffer = hex2bin.convert(hex);
|
||||||
log("downloaded length: " + buffer.byteLength);
|
log("downloaded length: " + buffer.byteLength);
|
||||||
|
|
||||||
// dfu.ImageType.Application is the default value for the third parameter
|
// dfu.ImageType.Application is the default value for the third parameter
|
||||||
|
|||||||
Reference in New Issue
Block a user