mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-13 04:28:13 +08:00
Add default crc if not specified
This commit is contained in:
2
dist/crc16.js
vendored
2
dist/crc16.js
vendored
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
// https://github.com/umdjs/umd
|
// https://github.com/umdjs/umd
|
||||||
(function(global, factory) {
|
(function(global, factory) {
|
||||||
|
|
||||||
if (typeof exports === 'object') {
|
if (typeof exports === 'object') {
|
||||||
// CommonJS (Node)
|
// CommonJS (Node)
|
||||||
module.exports = factory();
|
module.exports = factory();
|
||||||
@@ -38,7 +37,6 @@
|
|||||||
// Browser global (with support for web workers)
|
// Browser global (with support for web workers)
|
||||||
global.crc16 = factory();
|
global.crc16 = factory();
|
||||||
}
|
}
|
||||||
|
|
||||||
}(this, function() {
|
}(this, function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|||||||
17
dist/dfu.js
vendored
17
dist/dfu.js
vendored
@@ -33,15 +33,15 @@
|
|||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
// AMD. Register as an anonymous module.
|
// AMD. Register as an anonymous module.
|
||||||
define(['es6-promise', 'bleat'], factory);
|
define(['es6-promise', 'bleat', 'crc16'], factory);
|
||||||
} else if (typeof exports === 'object') {
|
} else if (typeof exports === 'object') {
|
||||||
// Node. Does not work with strict CommonJS
|
// Node. Does not work with strict CommonJS
|
||||||
module.exports = factory(Promise, require('bleat').webbluetooth);
|
module.exports = factory(Promise, require('bleat').webbluetooth, require('./crc16'));
|
||||||
} else {
|
} else {
|
||||||
// Browser globals with support for web workers (root is window)
|
// Browser globals with support for web workers (root is window)
|
||||||
root.dfu = factory(Promise, root.navigator.bluetooth);
|
root.dfu = factory(Promise, root.navigator.bluetooth, root.crc16);
|
||||||
}
|
}
|
||||||
}(this, function(Promise, bluetooth) {
|
}(this, function(Promise, bluetooth, crc16) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var LITTLE_ENDIAN = true;
|
var LITTLE_ENDIAN = true;
|
||||||
@@ -162,16 +162,17 @@
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
function provision(device, arrayBuffer, crc, imageType) {
|
function provision(device, arrayBuffer, imageType, crc) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var versionChar = null;
|
|
||||||
initPacket.crc = crc || 0xFFFF; // Not used in mbed/ older bootloader revisions.
|
|
||||||
imageType = imageType || ImageType.Application;
|
imageType = imageType || ImageType.Application;
|
||||||
|
initPacket.crc = crc || crc16(arrayBuffer);
|
||||||
|
var versionChar = null;
|
||||||
|
|
||||||
connect(device)
|
connect(device)
|
||||||
.then(function(chars) {
|
.then(function(chars) {
|
||||||
versionChar = chars.versionChar;
|
versionChar = chars.versionChar;
|
||||||
if (versionChar) { // Older DFU implementations (from older Nordic SDKs < 7.0) have no DFU Version characteristic.
|
// Older DFU implementations (from older Nordic SDKs < 7.0) have no DFU Version characteristic.
|
||||||
|
if (versionChar) {
|
||||||
return versionChar.readValue()
|
return versionChar.readValue()
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
console.log('read versionChar');
|
console.log('read versionChar');
|
||||||
|
|||||||
2
dist/hex2bin.js
vendored
2
dist/hex2bin.js
vendored
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
// https://github.com/umdjs/umd
|
// https://github.com/umdjs/umd
|
||||||
(function(global, factory) {
|
(function(global, factory) {
|
||||||
|
|
||||||
if (typeof exports === 'object') {
|
if (typeof exports === 'object') {
|
||||||
// CommonJS (Node)
|
// CommonJS (Node)
|
||||||
module.exports = factory();
|
module.exports = factory();
|
||||||
@@ -38,7 +37,6 @@
|
|||||||
// Browser global (with support for web workers)
|
// Browser global (with support for web workers)
|
||||||
global.hex2bin = factory();
|
global.hex2bin = factory();
|
||||||
}
|
}
|
||||||
|
|
||||||
}(this, function() {
|
}(this, function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
var dfu = require('./index').dfu;
|
var dfu = require('./index').dfu;
|
||||||
var hex2bin = require('./index').hex2bin;
|
var hex2bin = require('./index').hex2bin;
|
||||||
var crc16 = require('./index').crc16;
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var log = console.log;
|
var log = console.log;
|
||||||
@@ -41,9 +40,8 @@ dfu.findDevice({ services: [0x180D] })
|
|||||||
var hex = file.toString();
|
var hex = file.toString();
|
||||||
var buffer = hex2bin(hex);
|
var buffer = hex2bin(hex);
|
||||||
log("file length: " + buffer.byteLength);
|
log("file length: " + buffer.byteLength);
|
||||||
var crc = crc16(buffer);
|
|
||||||
|
|
||||||
return dfu.provision(device, buffer, crc);
|
return dfu.provision(device, buffer);
|
||||||
})
|
})
|
||||||
.then(() => process.exit())
|
.then(() => process.exit())
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
<script src="dist/dfu.js"></script>
|
<script src="dist/dfu.js"></script>
|
||||||
<script src="dist/hex2bin.js"></script>
|
<script src="dist/hex2bin.js"></script>
|
||||||
<script src="dist/crc16.js"></script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var resultsEl = document.getElementById("results");
|
var resultsEl = document.getElementById("results");
|
||||||
@@ -69,9 +68,10 @@
|
|||||||
.then(hex => {
|
.then(hex => {
|
||||||
var buffer = hex2bin(hex);
|
var buffer = hex2bin(hex);
|
||||||
log("downloaded length: " + buffer.byteLength);
|
log("downloaded length: " + buffer.byteLength);
|
||||||
var crc = crc16(buffer);
|
|
||||||
|
|
||||||
return dfu.provision(device, buffer, crc); // dfu.ImageType.Application is the default value for the fourth parameter. Specify this if you want to upload a softdevice/bootloader.
|
// dfu.ImageType.Application is the default value for the third parameter
|
||||||
|
// Specify this if you want to upload a softdevice/bootloader
|
||||||
|
return dfu.provision(device, buffer);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log('dfu complete');
|
log('dfu complete');
|
||||||
|
|||||||
Reference in New Issue
Block a user