mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-10 19:08:12 +08:00
Use the CRC we generate for the image in the init packet.
This commit is contained in:
3
dist/dfu.js
vendored
3
dist/dfu.js
vendored
@@ -162,10 +162,11 @@
|
||||
return view;
|
||||
}
|
||||
|
||||
function provision(device, arrayBuffer, imageType) {
|
||||
function provision(device, arrayBuffer, imageType, crc) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var versionChar = null;
|
||||
imageType = imageType || ImageType.Application;
|
||||
initPacket.crc = crc;
|
||||
|
||||
connect(device)
|
||||
.then(function(chars) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var dfu = require('./index').dfu;
|
||||
var hex2bin = require('./index').hex2bin;
|
||||
var crc16 = require('./index').crc16;
|
||||
var fs = require('fs');
|
||||
|
||||
var log = console.log;
|
||||
@@ -40,8 +41,9 @@ 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);
|
||||
return dfu.provision(device, buffer, 4, crc);
|
||||
})
|
||||
.then(() => process.exit())
|
||||
.catch(error => {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
<script src="dist/dfu.js"></script>
|
||||
<script src="dist/hex2bin.js"></script>
|
||||
<script src="dist/crc16.js"></script>
|
||||
|
||||
<script>
|
||||
var resultsEl = document.getElementById("results");
|
||||
@@ -68,8 +69,9 @@
|
||||
.then(hex => {
|
||||
var buffer = hex2bin(hex);
|
||||
log("downloaded length: " + buffer.byteLength);
|
||||
var crc = crc16(buffer);
|
||||
|
||||
return dfu.provision(device, buffer);
|
||||
return dfu.provision(device, buffer, 4, crc);
|
||||
})
|
||||
.then(() => {
|
||||
log('dfu complete');
|
||||
|
||||
Reference in New Issue
Block a user