From e2a427d0946c9231a12fa911980f69d3ae6ee291 Mon Sep 17 00:00:00 2001 From: Rob Moran Date: Sat, 27 Feb 2016 14:07:34 +0000 Subject: [PATCH] Add default crc if not specified --- dist/crc16.js | 2 -- dist/dfu.js | 17 +++++++++-------- dist/hex2bin.js | 2 -- example_node.js | 4 +--- example_web.html | 6 +++--- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/dist/crc16.js b/dist/crc16.js index 017627d..7be2075 100644 --- a/dist/crc16.js +++ b/dist/crc16.js @@ -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'; diff --git a/dist/dfu.js b/dist/dfu.js index fd554b9..de90066 100644 --- a/dist/dfu.js +++ b/dist/dfu.js @@ -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'); diff --git a/dist/hex2bin.js b/dist/hex2bin.js index d17728b..9065db8 100644 --- a/dist/hex2bin.js +++ b/dist/hex2bin.js @@ -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'; diff --git a/example_node.js b/example_node.js index 8568252..7bc7f72 100644 --- a/example_node.js +++ b/example_node.js @@ -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 => { diff --git a/example_web.html b/example_web.html index d5a82fd..8299a17 100644 --- a/example_web.html +++ b/example_web.html @@ -27,7 +27,6 @@ -