Skip to content

Commit

Permalink
feat: ZCL types revamp (#1033)
Browse files Browse the repository at this point in the history
* ZCL types revamp

* Added missing foundation commands with tests.

* Added Foundation-related typing.

* Cleanup

* Fix.

* Fix zigate issues. Tag codepaths likely still broken.

* Fix.

* Cleanup.

* Fix for zigate.
  • Loading branch information
Nerivec committed May 1, 2024
1 parent 859215e commit f88b4d6
Show file tree
Hide file tree
Showing 25 changed files with 5,373 additions and 3,659 deletions.
8 changes: 4 additions & 4 deletions src/adapter/ember/ezsp/buffalo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class EzspBuffalo extends Buffalo {
}

public readEmberNetworkParameters(): EmberNetworkParameters {
const extendedPanId = this.readListUInt8({length: EXTENDED_PAN_ID_SIZE});
const extendedPanId = this.readListUInt8(EXTENDED_PAN_ID_SIZE);
const panId = this.readUInt16();
const radioTxPower = this.readUInt8();
const radioChannel = this.readUInt8();
Expand Down Expand Up @@ -586,7 +586,7 @@ export class EzspBuffalo extends Buffalo {
public readEmberZigbeeNetwork(): EmberZigbeeNetwork {
const channel = this.readUInt8();
const panId = this.readUInt16();
const extendedPanId = this.readListUInt8({length: EXTENDED_PAN_ID_SIZE});
const extendedPanId = this.readListUInt8(EXTENDED_PAN_ID_SIZE);
const allowingJoin = this.readUInt8();
const stackProfile = this.readUInt8();
const nwkUpdateId = this.readUInt8();
Expand Down Expand Up @@ -1146,7 +1146,7 @@ export class EzspBuffalo extends Buffalo {
const hasCapacity = this.readUInt8() === 1 ? true : false;
const panId = this.readUInt16();
const sender = this.readUInt16();
const extendedPanId = this.readListUInt8({length: EXTENDED_PAN_ID_SIZE});
const extendedPanId = this.readListUInt8(EXTENDED_PAN_ID_SIZE);
const index = this.readUInt8();

return {
Expand Down Expand Up @@ -1205,7 +1205,7 @@ export class EzspBuffalo extends Buffalo {
const hasCapacity = this.readUInt8() === 1 ? true : false;
const panId = this.readUInt16();
const sender = this.readUInt16();
const extendedPanId = this.readListUInt8({length: EXTENDED_PAN_ID_SIZE});
const extendedPanId = this.readListUInt8(EXTENDED_PAN_ID_SIZE);

return {
channel,
Expand Down
39 changes: 20 additions & 19 deletions src/adapter/ember/ezsp/ezsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ import {
EZSP_FRAME_CONTROL_PENDING_CB_MASK,
EZSP_FRAME_CONTROL_PENDING_CB,
EXTENDED_PAN_ID_SIZE,
EMBER_ENCRYPTION_KEY_SIZE,
} from "./consts";
import {
EmberLeaveReason,
Expand Down Expand Up @@ -719,7 +720,7 @@ export class Ezsp extends EventEmitter {
}
case EzspFrameID.CUSTOM_FRAME_HANDLER: {
const payloadLength = this.buffalo.readUInt8();
const payload = this.buffalo.readListUInt8({length: payloadLength});
const payload = this.buffalo.readListUInt8(payloadLength);
this.ezspCustomFrameHandler(payloadLength, payload);
break;
}
Expand Down Expand Up @@ -856,7 +857,7 @@ export class Ezsp extends EventEmitter {
const lastHopLqi = this.buffalo.readUInt8();
const lastHopRssi = this.buffalo.readUInt8();
const relayCount = this.buffalo.readUInt8();
const relayList = this.buffalo.readListUInt16({length: relayCount});//this.buffalo.readListUInt8({length: (relayCount * 2)});
const relayList = this.buffalo.readListUInt16(relayCount);//this.buffalo.readListUInt8(relayCount * 2);
this.ezspIncomingRouteRecordHandler(source, sourceEui, lastHopLqi, lastHopRssi, relayCount, relayList);
break;
}
Expand Down Expand Up @@ -948,7 +949,7 @@ export class Ezsp extends EventEmitter {
const linkQuality = this.buffalo.readUInt8();
const rssi = this.buffalo.readUInt8();
const packetLength = this.buffalo.readUInt8();
const packetContents = this.buffalo.readListUInt8({length: packetLength});
const packetContents = this.buffalo.readListUInt8(packetLength);
this.ezspMfglibRxHandler(linkQuality, rssi, packetLength, packetContents);
break;
}
Expand Down Expand Up @@ -1401,7 +1402,7 @@ export class Ezsp extends EventEmitter {
throw EzspStatus.ERROR_INVALID_VALUE;
}

const data = this.buffalo.readListUInt8({length: readLength});
const data = this.buffalo.readListUInt8(readLength);

return [status, dataType, readLength, data];
}
Expand Down Expand Up @@ -1585,7 +1586,7 @@ export class Ezsp extends EventEmitter {
throw EzspStatus.ERROR_INVALID_VALUE;
}

const value = this.buffalo.readListUInt8({length: valueLength});
const value = this.buffalo.readListUInt8(valueLength);

return [status, valueLength, value];
}
Expand Down Expand Up @@ -1626,7 +1627,7 @@ export class Ezsp extends EventEmitter {
throw EzspStatus.ERROR_INVALID_VALUE;
}

const value = this.buffalo.readListUInt8({length: valueLength});
const value = this.buffalo.readListUInt8(valueLength);

return [status, valueLength, value];
}
Expand Down Expand Up @@ -1789,7 +1790,7 @@ export class Ezsp extends EventEmitter {
}

const status: EmberStatus = this.buffalo.readUInt8();
const tokenData = this.buffalo.readListUInt8({length: 8});
const tokenData = this.buffalo.readListUInt8(8);

return [status, tokenData];
}
Expand Down Expand Up @@ -1855,7 +1856,7 @@ export class Ezsp extends EventEmitter {
throw EzspStatus.ERROR_INVALID_VALUE;
}

const tokenData = this.buffalo.readListUInt8({length: tokenDataLength});
const tokenData = this.buffalo.readListUInt8(tokenDataLength);

return [tokenDataLength, tokenData];
}
Expand Down Expand Up @@ -2014,7 +2015,7 @@ export class Ezsp extends EventEmitter {
throw new Error(EzspStatus[sendStatus]);
}

const values = this.buffalo.readListUInt16({length: EmberCounterType.COUNT});
const values = this.buffalo.readListUInt16(EmberCounterType.COUNT);

return values;
}
Expand All @@ -2032,7 +2033,7 @@ export class Ezsp extends EventEmitter {
throw new Error(EzspStatus[sendStatus]);
}

const values = this.buffalo.readListUInt16({length: EmberCounterType.COUNT});
const values = this.buffalo.readListUInt16(EmberCounterType.COUNT);

return values;
}
Expand Down Expand Up @@ -3366,7 +3367,7 @@ export class Ezsp extends EventEmitter {
}

const status: EmberStatus = this.buffalo.readUInt8();
const arrayOfDeviceDutyCycles = this.buffalo.readListUInt8({length: 134});
const arrayOfDeviceDutyCycles = this.buffalo.readListUInt8(134);

return [status, arrayOfDeviceDutyCycles];
}
Expand Down Expand Up @@ -4128,7 +4129,7 @@ export class Ezsp extends EventEmitter {
assocDevCount = zdoBuffalo.readUInt8();
startIndex = zdoBuffalo.readUInt8();

assocDevList = zdoBuffalo.readListUInt16({length: assocDevCount});
assocDevList = zdoBuffalo.readListUInt16(assocDevCount);
}

logger.debug(`<=== [ZDO IEEE_ADDRESS_RESPONSE status=${EmberZdoStatus[status]} eui64=${eui64} nodeId=${nodeId} `
Expand Down Expand Up @@ -4170,7 +4171,7 @@ export class Ezsp extends EventEmitter {
assocDevCount = zdoBuffalo.readUInt8();
startIndex = zdoBuffalo.readUInt8();

assocDevList = zdoBuffalo.readListUInt16({length: assocDevCount});
assocDevList = zdoBuffalo.readListUInt16(assocDevCount);
}

logger.debug(`<=== [ZDO NETWORK_ADDRESS_RESPONSE status=${EmberZdoStatus[status]} eui64=${eui64} nodeId=${nodeId} `
Expand All @@ -4191,7 +4192,7 @@ export class Ezsp extends EventEmitter {
} else {
const nodeId = zdoBuffalo.readUInt16();
const endpointCount = zdoBuffalo.readUInt8();
const endpointList = zdoBuffalo.readListUInt8({length: endpointCount});
const endpointList = zdoBuffalo.readListUInt8(endpointCount);

logger.debug(
`<=== [ZDO MATCH_DESCRIPTORS_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} endpointList=${endpointList}]`,
Expand Down Expand Up @@ -4221,9 +4222,9 @@ export class Ezsp extends EventEmitter {
// values 0000-1111, others reserved
const deviceVersion = zdoBuffalo.readUInt8();
const inClusterCount = zdoBuffalo.readUInt8();
const inClusterList = zdoBuffalo.readListUInt16({length: inClusterCount});
const inClusterList = zdoBuffalo.readListUInt16(inClusterCount);
const outClusterCount = zdoBuffalo.readUInt8();
const outClusterList = zdoBuffalo.readListUInt16({length: outClusterCount});
const outClusterList = zdoBuffalo.readListUInt16(outClusterCount);

logger.debug(`<=== [ZDO SIMPLE_DESCRIPTOR_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} endpoint=${endpoint} `
+ `profileId=${profileId} deviceId=${deviceId} deviceVersion=${deviceVersion} inClusterList=${inClusterList} `
Expand Down Expand Up @@ -4371,7 +4372,7 @@ export class Ezsp extends EventEmitter {
} else {
const nodeId = zdoBuffalo.readUInt16();
const endpointCount = zdoBuffalo.readUInt8();
const endpointList = zdoBuffalo.readListUInt8({length: endpointCount});
const endpointList = zdoBuffalo.readListUInt8(endpointCount);

logger.debug(
`<=== [ZDO ACTIVE_ENDPOINTS_RESPONSE status=${EmberZdoStatus[status]} nodeId=${nodeId} endpointList=${endpointList}]`,
Expand Down Expand Up @@ -4402,7 +4403,7 @@ export class Ezsp extends EventEmitter {
const entryList: ZDOLQITableEntry[] = [];

for (let i = 0; i < entryCount; i++) {
const extendedPanId = zdoBuffalo.readListUInt8({length: EXTENDED_PAN_ID_SIZE});
const extendedPanId = zdoBuffalo.readListUInt8(EXTENDED_PAN_ID_SIZE);
const eui64 = zdoBuffalo.readIeeeAddr();
const nodeId = zdoBuffalo.readUInt16();
const deviceTypeByte = zdoBuffalo.readUInt8();
Expand Down Expand Up @@ -6937,7 +6938,7 @@ export class Ezsp extends EventEmitter {
throw new Error(EzspStatus[sendStatus]);
}

const ciphertext = this.buffalo.readListUInt8({length: 16});
const ciphertext = this.buffalo.readListUInt8(EMBER_ENCRYPTION_KEY_SIZE);

return ciphertext;
}
Expand Down

0 comments on commit f88b4d6

Please sign in to comment.