Skip to content

Commit

Permalink
feat: allow resuming OTA updates and non-secure transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Aug 15, 2024
1 parent d857d56 commit 4eaf324
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 41 deletions.
1 change: 1 addition & 0 deletions .vscode/extensions/zwave-js-config-editor
Submodule zwave-js-config-editor added at fe2c78
26 changes: 16 additions & 10 deletions packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { V } from "../lib/Values";
import {
FirmwareDownloadStatus,
FirmwareUpdateActivationStatus,
type FirmwareUpdateInitResult,
type FirmwareUpdateMetaData,
FirmwareUpdateMetaDataCommand,
FirmwareUpdateRequestStatus,
Expand Down Expand Up @@ -163,7 +164,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI {
@validateArgs()
public async requestUpdate(
options: FirmwareUpdateMetaDataCCRequestGetOptions,
): Promise<FirmwareUpdateRequestStatus> {
): Promise<FirmwareUpdateInitResult> {
this.assertSupportsCommand(
FirmwareUpdateMetaDataCommand,
FirmwareUpdateMetaDataCommand.RequestGet,
Expand All @@ -183,15 +184,20 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI {
// Do not wait for Nonce Reports
s2VerifyDelivery: false,
});
const { status } = await this.applHost.waitForCommand<
FirmwareUpdateMetaDataCCRequestReport
>(
(cc) =>
cc instanceof FirmwareUpdateMetaDataCCRequestReport
&& cc.nodeId === this.endpoint.nodeId,
60000,
);
return status;
const result = await this.applHost
.waitForCommand<
FirmwareUpdateMetaDataCCRequestReport
>(
(cc) =>
cc instanceof FirmwareUpdateMetaDataCCRequestReport
&& cc.nodeId === this.endpoint.nodeId,
60000,
);
return pick(result, [
"status",
"resume",
"nonSecureTransfer",
]);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions packages/cc/src/lib/_Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,14 @@ export enum FirmwareUpdateRequestStatus {
OK = 0xff,
}

export interface FirmwareUpdateInitResult {
status: FirmwareUpdateRequestStatus;
/** Whether the node will resume a previous transfer */
resume?: boolean;
/** Whether the node will accept non-secure firmware fragments */
nonSecureTransfer?: boolean;
}

export enum FirmwareUpdateStatus {
// Error_Timeout is not part of the Z-Wave standard, but we use it to report
// that no status report was received
Expand Down Expand Up @@ -822,6 +830,18 @@ export interface FirmwareUpdateResult {
reInterview: boolean;
}

export interface FirmwareUpdateOptions {
/**
* Whether a previous attempt to update this node's firmware should be resumed (if supported).
*/
resume?: boolean;
/**
* Whether the firmware data should be transferred without encryption (if supported).
* This can massively reduce the time needed.
*/
nonSecureTransfer?: boolean;
}

export enum HailCommand {
Hail = 0x01,
}
Expand Down
4 changes: 3 additions & 1 deletion packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type AssociationGroup,
ECDHProfiles,
FLiRS2WakeUpTime,
type FirmwareUpdateOptions,
type FirmwareUpdateResult,
InclusionControllerCCComplete,
InclusionControllerCCInitiate,
Expand Down Expand Up @@ -7629,6 +7630,7 @@ ${associatedNodes.join(", ")}`,
public async firmwareUpdateOTA(
nodeId: number,
updateInfo: FirmwareUpdateInfo,
options?: FirmwareUpdateOptions,
): Promise<FirmwareUpdateResult> {
// Don't let two firmware updates happen in parallel
if (this.isAnyOTAFirmwareUpdateInProgress()) {
Expand Down Expand Up @@ -7735,7 +7737,7 @@ ${associatedNodes.join(", ")}`,
);
}

return node.updateFirmware(firmwares);
return node.updateFirmware(firmwares, options);
}

private _firmwareUpdateInProgress: boolean = false;
Expand Down
Loading

0 comments on commit 4eaf324

Please sign in to comment.