From 0b16f1ba1ed441c65c65ec6165158de054107ffc Mon Sep 17 00:00:00 2001 From: Nerivec <62446222+Nerivec@users.noreply.github.com> Date: Mon, 22 Jan 2024 20:21:36 +0100 Subject: [PATCH] fix: EZSP: Added base for `incomingNetworkStatusHandler` (#883) * Added base for `incomingNetworkStatusHandler` * Fix lint --- src/adapter/ezsp/driver/commands.ts | 3 ++- src/adapter/ezsp/driver/driver.ts | 23 ++++++++++++++++++++++- src/adapter/ezsp/driver/types/index.ts | 2 ++ src/adapter/ezsp/driver/types/named.ts | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/adapter/ezsp/driver/commands.ts b/src/adapter/ezsp/driver/commands.ts index ea639a38cf..5801d839a2 100644 --- a/src/adapter/ezsp/driver/commands.ts +++ b/src/adapter/ezsp/driver/commands.ts @@ -28,6 +28,7 @@ import {/* Basic Types */ EzspMfgTokenId, EzspStatus, EmberStatus, + EmberStackError, EmberEventUnits, EmberNodeType, EmberNetworkStatus, @@ -2261,7 +2262,7 @@ export const FRAMES: {[key: string]: EZSPFrameDesc} = { ID: 0x00C4, request: null, response: { - errorCode: uint8_t, + errorCode: EmberStackError, target: EmberNodeId }, minV: 9 diff --git a/src/adapter/ezsp/driver/driver.ts b/src/adapter/ezsp/driver/driver.ts index 5dbffb0b5e..8d0666e6dc 100644 --- a/src/adapter/ezsp/driver/driver.ts +++ b/src/adapter/ezsp/driver/driver.ts @@ -18,6 +18,7 @@ import { EmberNetworkStatus, EmberKeyType, EmberDerivedKeyType, + EmberStackError, } from './types/named'; import {Multicast} from './multicast'; import {Waitress, Wait} from '../../../utils'; @@ -327,6 +328,10 @@ export class Driver extends EventEmitter { this.handleRouteError(frame.status, frame.target); break; } + case (frameName === 'incomingNetworkStatusHandler'): { + this.handleNetworkStatus(frame.errorCode, frame.target); + break; + } case (frameName === 'messageSentHandler'): { // todo const status = frame.status; @@ -405,7 +410,9 @@ export class Driver extends EventEmitter { private handleRouteRecord(nwk: number, ieee: EmberEUI64 | number[], lqi: number, rssi: number, relays: number): void { // todo - debug.log(`handleRouteRecord: nwk=${nwk}, ieee=${ieee}, lqi=${lqi}, rssi=${rssi}, relays=${relays}`); + debug.log( + `handleRouteRecord: nwk=${nwk}, ieee=${ieee.toString()}, lqi=${lqi}, rssi=${rssi}, relays=${relays}` + ); this.setNode(nwk, ieee); // if (ieee && !(ieee instanceof EmberEUI64)) { @@ -422,6 +429,20 @@ export class Driver extends EventEmitter { // this.eui64ToRelays.set(ieee.toString(), null); } + private async handleNetworkStatus(errorCode: EmberStackError, nwk: number): Promise { + // todo + // <== Frame: e19401c4000684c5 + // <== 0xc4: { + // "_cls_":"incomingNetworkStatusHandler", + // "_id_":196, + // "_isRequest_":false, + // "errorCode":6, + // "target":50564 + // } + // https://docs.silabs.com/d/zigbee-stack-api/7.4.0/message#ember-incoming-network-status-handler + debug.log(`handleNetworkStatus: nwk=${nwk}, errorCode=${errorCode}`); + } + private handleNodeLeft(nwk: number, ieee: EmberEUI64 | number[]): void { if (ieee && !(ieee instanceof EmberEUI64)) { ieee = new EmberEUI64(ieee); diff --git a/src/adapter/ezsp/driver/types/index.ts b/src/adapter/ezsp/driver/types/index.ts index bfaff82748..ff45ef77cd 100644 --- a/src/adapter/ezsp/driver/types/index.ts +++ b/src/adapter/ezsp/driver/types/index.ts @@ -43,6 +43,7 @@ import { EzspMfgTokenId, EzspStatus, EmberStatus, + EmberStackError, EmberEventUnits, EmberNodeType, EmberNetworkStatus, @@ -177,6 +178,7 @@ export { EzspMfgTokenId, EzspStatus, EmberStatus, + EmberStackError, EmberEventUnits, EmberNodeType, EmberNetworkStatus, diff --git a/src/adapter/ezsp/driver/types/named.ts b/src/adapter/ezsp/driver/types/named.ts index 9d6f8ec768..39cb0343e7 100644 --- a/src/adapter/ezsp/driver/types/named.ts +++ b/src/adapter/ezsp/driver/types/named.ts @@ -1086,6 +1086,30 @@ export class EmberStatus extends basic.uint8_t { static APPLICATION_ERROR_15 = 0xFF; } +export class EmberStackError extends basic.uint8_t { + // Error codes that a router uses to notify the message initiator about a broken route. + static EMBER_ROUTE_ERROR_NO_ROUTE_AVAILABLE = 0x00; + static EMBER_ROUTE_ERROR_TREE_LINK_FAILURE = 0x01; + static EMBER_ROUTE_ERROR_NON_TREE_LINK_FAILURE = 0x02; + static EMBER_ROUTE_ERROR_LOW_BATTERY_LEVEL = 0x03; + static EMBER_ROUTE_ERROR_NO_ROUTING_CAPACITY = 0x04; + static EMBER_ROUTE_ERROR_NO_INDIRECT_CAPACITY = 0x05; + static EMBER_ROUTE_ERROR_INDIRECT_TRANSACTION_EXPIRY = 0x06; + static EMBER_ROUTE_ERROR_TARGET_DEVICE_UNAVAILABLE = 0x07; + static EMBER_ROUTE_ERROR_TARGET_ADDRESS_UNALLOCATED = 0x08; + static EMBER_ROUTE_ERROR_PARENT_LINK_FAILURE = 0x09; + static EMBER_ROUTE_ERROR_VALIDATE_ROUTE = 0x0A; + static EMBER_ROUTE_ERROR_SOURCE_ROUTE_FAILURE = 0x0B; + static EMBER_ROUTE_ERROR_MANY_TO_ONE_ROUTE_FAILURE = 0x0C; + static EMBER_ROUTE_ERROR_ADDRESS_CONFLICT = 0x0D; + static EMBER_ROUTE_ERROR_VERIFY_ADDRESSES = 0x0E; + static EMBER_ROUTE_ERROR_PAN_IDENTIFIER_UPDATE = 0x0F; + + static ZIGBEE_NETWORK_STATUS_NETWORK_ADDRESS_UPDATE = 0x10; + static ZIGBEE_NETWORK_STATUS_BAD_FRAME_COUNTER = 0x11; + static ZIGBEE_NETWORK_STATUS_BAD_KEY_SEQUENCE_NUMBER = 0x12; + static ZIGBEE_NETWORK_STATUS_UNKNOWN_COMMAND = 0x13; +} export class EmberEventUnits extends basic.uint8_t { // Either marks an event as inactive or specifies the units for the event