Skip to content

Commit

Permalink
feat: expose firmware ID for OTA update to applications (#7599)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Feb 6, 2025
1 parent f857f30 commit 3d06a1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion docs/api/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,16 @@ Performs an OTA firmware update process for this node, applying the provided fir
This method an array of firmware updates, each of which contains the following properties:

- `data` - A buffer containing the firmware image in a format supported by the device
- `target` - _(optional)_ The firmware target (i.e. chip) to upgrade. `0` updates the Z-Wave chip, `>=1` updates others if they exist
- `firmwareTarget` - _(optional)_ The firmware target (i.e. chip) to upgrade. `0` updates the Z-Wave chip, `>=1` updates others if they exist
- `firmwareId` - _(optional)_ The ID of the new firmware that will be uploaded. This is only necessary if the device checks the firmware ID before starting the update. If not given, the current firmware ID will be reused.

<!-- #import Firmware from "zwave-js" -->

```ts
interface Firmware {
data: Uint8Array;
firmwareTarget?: number;
firmwareId?: number;
}
```

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/util/_Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type FirmwareFileFormat =
export interface Firmware {
data: Uint8Array;
firmwareTarget?: number;
firmwareId?: number;
}
26 changes: 17 additions & 9 deletions packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,16 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
let sentBytesOfPreviousFiles = 0;

for (let i = 0; i < updatesWithChecksum.length; i++) {
const { firmwareTarget: target = 0, data, checksum } =
updatesWithChecksum[i];
const {
// If the firmware target is not given, update the Z-Wave chip
firmwareTarget: target = 0,
// If the firmware ID is not given, use the current one for the given chip
firmwareId = target === 0
? meta.firmwareId
: meta.additionalFirmwareIDs[target - 1],
data,
checksum,
} = updatesWithChecksum[i];

if (i < skipFinishedFiles) {
// If we are resuming, skip this file since it was already done before
Expand Down Expand Up @@ -351,8 +359,9 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
const { resume, nonSecureTransfer } = yield* self
.beginFirmwareUpdateInternal(
data,
meta.manufacturerId,
target,
meta,
firmwareId,
fragmentSize,
checksum,
hardwareVersion,
Expand Down Expand Up @@ -645,8 +654,9 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin
/** Kicks off a firmware update of a single target. Returns whether the node accepted resuming and non-secure transfer */
private async *beginFirmwareUpdateInternal(
data: Uint8Array,
manufacturerId: number,
target: number,
meta: FirmwareUpdateMetaData,
firmwareId: number,
fragmentSize: number,
checksum: number,
hardwareVersion?: number,
Expand All @@ -665,11 +675,9 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin

// Request the node to start the upgrade
await api.requestUpdate({
// TODO: Should manufacturer id and firmware id be provided externally?
manufacturerId: meta.manufacturerId,
firmwareId: target == 0
? meta.firmwareId
: meta.additionalFirmwareIDs[target - 1],
// TODO: Should manufacturer id be provided externally?
manufacturerId,
firmwareId,
firmwareTarget: target,
fragmentSize,
checksum,
Expand Down

0 comments on commit 3d06a1b

Please sign in to comment.