Skip to content

Commit

Permalink
fix: EZSP: Added base for incomingNetworkStatusHandler (Koenkk#883)
Browse files Browse the repository at this point in the history
* Added base for `incomingNetworkStatusHandler`

* Fix lint
  • Loading branch information
Nerivec authored Jan 22, 2024
1 parent 8059d39 commit 0b16f1b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/adapter/ezsp/driver/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {/* Basic Types */
EzspMfgTokenId,
EzspStatus,
EmberStatus,
EmberStackError,
EmberEventUnits,
EmberNodeType,
EmberNetworkStatus,
Expand Down Expand Up @@ -2261,7 +2262,7 @@ export const FRAMES: {[key: string]: EZSPFrameDesc} = {
ID: 0x00C4,
request: null,
response: {
errorCode: uint8_t,
errorCode: EmberStackError,
target: EmberNodeId
},
minV: 9
Expand Down
23 changes: 22 additions & 1 deletion src/adapter/ezsp/driver/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EmberNetworkStatus,
EmberKeyType,
EmberDerivedKeyType,
EmberStackError,
} from './types/named';
import {Multicast} from './multicast';
import {Waitress, Wait} from '../../../utils';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -422,6 +429,20 @@ export class Driver extends EventEmitter {
// this.eui64ToRelays.set(ieee.toString(), null);
}

private async handleNetworkStatus(errorCode: EmberStackError, nwk: number): Promise<void> {
// 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);
Expand Down
2 changes: 2 additions & 0 deletions src/adapter/ezsp/driver/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
EzspMfgTokenId,
EzspStatus,
EmberStatus,
EmberStackError,
EmberEventUnits,
EmberNodeType,
EmberNetworkStatus,
Expand Down Expand Up @@ -177,6 +178,7 @@ export {
EzspMfgTokenId,
EzspStatus,
EmberStatus,
EmberStackError,
EmberEventUnits,
EmberNodeType,
EmberNetworkStatus,
Expand Down
24 changes: 24 additions & 0 deletions src/adapter/ezsp/driver/types/named.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b16f1b

Please sign in to comment.