Skip to content

Commit

Permalink
fix: handle more cases of unexpected Serial API restart (#6551)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Dec 9, 2023
1 parent c3f1e1a commit d045267
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
37 changes: 23 additions & 14 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3867,23 +3867,32 @@ supported CCs: ${
private async handleSerialAPIStartedUnexpectedly(
msg: SerialAPIStartedRequest,
): Promise<boolean> {
// Normally, the soft reset command includes waiting for this message. If we end up here, it is unexpected.
// Normally, the soft reset command includes waiting for this message.
// If we end up here, it is unexpected.

switch (msg.wakeUpReason) {
// All wakeup reasons that indicate a reset of the Serial API
// need to be handled here, so we interpret node IDs correctly.
case SerialAPIWakeUpReason.Reset:
case SerialAPIWakeUpReason.WatchdogReset:
case SerialAPIWakeUpReason.SoftwareReset:
case SerialAPIWakeUpReason.EmergencyWatchdogReset:
case SerialAPIWakeUpReason.BrownoutCircuit: {
// The Serial API restarted unexpectedly
if (this._nodeIdType === NodeIDType.Long) {
this.driver.controllerLog.print(
`Serial API restarted unexpectedly.`,
"warn",
);

if (msg.wakeUpReason === SerialAPIWakeUpReason.SoftwareReset) {
// The Serial API restarted
if (this._nodeIdType === NodeIDType.Long) {
this.driver.controllerLog.print(
`Serial API restarted unexpectedly.`,
"warn",
);
// We previously used 16 bit node IDs, but the controller was reset.
// Remember this and try to go back to 16 bit.
this._nodeIdType = NodeIDType.Short;
await this.trySetNodeIDType(NodeIDType.Long);
}

// We previously used 16 bit node IDs, but the controller was reset.
// Remember this and try to go back to 16 bit.
this._nodeIdType = NodeIDType.Short;
await this.trySetNodeIDType(NodeIDType.Long);
return true; // Don't invoke any more handlers
}

return true; // Don't invoke any more handlers
}

return false; // Not handled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export enum SerialAPIWakeUpReason {
WatchdogReset = 0x03,
/** The Z-Wave API Module has been woken up by an external interrupt. */
ExternalInterrupt = 0x04,
/** The Z-Wave API Module has been woken up by a powering up. */
/** The Z-Wave API Module has been woken up by powering up. */
PowerUp = 0x05,
/** The Z-Wave API Module has been woken up by USB Suspend. */
USBSuspend = 0x06,
Expand Down

0 comments on commit d045267

Please sign in to comment.