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
|
||||
(function(global, factory) {
|
||||
|
||||
if (typeof exports === 'object') {
|
||||
// CommonJS (Node)
|
||||
module.exports = factory();
|
||||
@@ -38,7 +37,6 @@
|
||||
// Browser global (with support for web workers)
|
||||
global.crc16 = factory();
|
||||
}
|
||||
|
||||
}(this, function() {
|
||||
'use strict';
|
||||
|
||||
|
||||
17
dist/dfu.js
vendored
17
dist/dfu.js
vendored
@@ -33,15 +33,15 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['es6-promise', 'bleat'], factory);
|
||||
define(['es6-promise', 'bleat', 'crc16'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node. Does not work with strict CommonJS
|
||||
module.exports = factory(Promise, require('bleat').webbluetooth);
|
||||
module.exports = factory(Promise, require('bleat').webbluetooth, require('./crc16'));
|
||||
} else {
|
||||
// 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";
|
||||
|
||||
var LITTLE_ENDIAN = true;
|
||||
@@ -162,16 +162,17 @@
|
||||
return view;
|
||||
}
|
||||
|
||||
function provision(device, arrayBuffer, crc, imageType) {
|
||||
function provision(device, arrayBuffer, imageType, crc) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var versionChar = null;
|
||||
initPacket.crc = crc || 0xFFFF; // Not used in mbed/ older bootloader revisions.
|
||||
imageType = imageType || ImageType.Application;
|
||||
initPacket.crc = crc || crc16(arrayBuffer);
|
||||
var versionChar = null;
|
||||
|
||||
connect(device)
|
||||
.then(function(chars) {
|
||||
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()
|
||||
.then(function(data) {
|
||||
console.log('read versionChar');
|
||||
|
||||
2
dist/hex2bin.js
vendored
2
dist/hex2bin.js
vendored
@@ -27,7 +27,6 @@
|
||||
|
||||
// https://github.com/umdjs/umd
|
||||
(function(global, factory) {
|
||||
|
||||
if (typeof exports === 'object') {
|
||||
// CommonJS (Node)
|
||||
module.exports = factory();
|
||||
@@ -38,7 +37,6 @@
|
||||
// Browser global (with support for web workers)
|
||||
global.hex2bin = factory();
|
||||
}
|
||||
|
||||
}(this, function() {
|
||||
'use strict';
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
var dfu = require('./index').dfu;
|
||||
var hex2bin = require('./index').hex2bin;
|
||||
var crc16 = require('./index').crc16;
|
||||
var fs = require('fs');
|
||||
|
||||
var log = console.log;
|
||||
@@ -41,9 +40,8 @@ dfu.findDevice({ services: [0x180D] })
|
||||
var hex = file.toString();
|
||||
var buffer = hex2bin(hex);
|
||||
log("file length: " + buffer.byteLength);
|
||||
var crc = crc16(buffer);
|
||||
|
||||
return dfu.provision(device, buffer, crc);
|
||||
return dfu.provision(device, buffer);
|
||||
})
|
||||
.then(() => process.exit())
|
||||
.catch(error => {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
<script src="dist/dfu.js"></script>
|
||||
<script src="dist/hex2bin.js"></script>
|
||||
<script src="dist/crc16.js"></script>
|
||||
|
||||
<script>
|
||||
var resultsEl = document.getElementById("results");
|
||||
@@ -69,9 +68,10 @@
|
||||
.then(hex => {
|
||||
var buffer = hex2bin(hex);
|
||||
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(() => {
|
||||
log('dfu complete');
|
||||
|
||||
Reference in New Issue
Block a user