Skip to content

Commit

Permalink
Merge pull request #89 from particle-iot/feature/dfu-impl
Browse files Browse the repository at this point in the history
Feature/dfu impl
  • Loading branch information
keeramis committed Aug 14, 2023
2 parents d770e99 + 63fa17b commit cbdc8dc
Show file tree
Hide file tree
Showing 11 changed files with 1,003 additions and 72 deletions.
5 changes: 4 additions & 1 deletion src/device-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ class DeviceBase extends EventEmitter {
}).then(() => {
this._log.trace('Device is open');
this._maxActiveReqs = options.concurrentRequests;
this._resetAllReqs = true; // Reset all requests remaining from a previous session
if (!this._dfu) {
this._resetAllReqs = true; // Reset all requests remaining from a previous session
}
this._state = DeviceState.OPEN;
this.emit('open');
this._process();
Expand Down Expand Up @@ -636,6 +638,7 @@ class DeviceBase extends EventEmitter {
this._state = DeviceState.CLOSED;
this._wantClose = false;
this._maxActiveReqs = null;
this._dfu = null;
this._fwVer = null;
this._id = null;
if (emitEvent) {
Expand Down
19 changes: 19 additions & 0 deletions src/dfu-device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const DfuDevice = (base) => class extends base {
/**
* Flashes the firmware over DFU interface.
*
* @param {Number} altSetting The interface alternate setting.
* @param {Buffer} buffer The binary firmware data to be flashed.
* @param {Number} addr The starting address where the firmware will be written.
* @param {Object} options Optional options for the flashing process.
* @returns {Promise<void>} A Promise that resolves when the firmware is successfully flashed.
*/
async writeOverDfu(altSetting, buffer, addr, options) {
await this._dfu.setAltSetting(altSetting);
await this._dfu.doDownload(addr, buffer, options);
}
};

module.exports = {
DfuDevice
};
Loading

0 comments on commit cbdc8dc

Please sign in to comment.