@@ -70,6 +70,22 @@ export class ZoHAdapter extends Adapter {
7070
7171 const channel = networkOptions . channelList [ 0 ] ;
7272 this . driver = new OTRCPDriver (
73+ {
74+ /* v8 ignore start */
75+ onFatalError : ( message ) => {
76+ logger . error ( message , NS ) ;
77+ } ,
78+ onMACFrame : ( ) => undefined , // unused
79+ /* v8 ignore stop */
80+
81+ onFrame : this . onFrame . bind ( this ) ,
82+ onGPFrame : this . onGPFrame . bind ( this ) ,
83+
84+ onDeviceJoined : this . onDeviceJoined . bind ( this ) ,
85+ onDeviceRejoined : this . onDeviceRejoined . bind ( this ) ,
86+ onDeviceLeft : this . onDeviceLeft . bind ( this ) ,
87+ onDeviceAuthorized : this . onDeviceAuthorized . bind ( this ) ,
88+ } ,
7389 {
7490 txChannel : channel ,
7591 ccaBackoffAttempts : 1 ,
@@ -88,7 +104,7 @@ export class ZoHAdapter extends Adapter {
88104 eui64 : Buffer . from ( [ 0x5a , 0x6f , 0x48 , 0x6f , 0x6e , 0x5a , 0x32 , 0x4d ] ) . readBigUInt64LE ( 0 ) ,
89105 panId : this . networkOptions . panID ,
90106 // biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
91- extendedPANId : Buffer . from ( this . networkOptions . extendedPanID ! ) . readBigUInt64LE ( 0 ) ,
107+ extendedPanId : Buffer . from ( this . networkOptions . extendedPanID ! ) . readBigUInt64LE ( 0 ) ,
92108 channel,
93109 nwkUpdateId : 0 ,
94110 txPower : this . adapterOptions . transmitPower ?? /* v8 ignore next */ 5 ,
@@ -261,15 +277,15 @@ export class ZoHAdapter extends Adapter {
261277 await this . initPort ( ) ;
262278
263279 let result : TsType . StartResult = "resumed" ;
264- const currentNetParams = await this . driver . readNetworkState ( ) ;
280+ const currentNetParams = await this . driver . context . readNetworkState ( ) ;
265281
266282 if ( currentNetParams ) {
267283 // Note: channel change is handled by Controller
268284 if (
269285 // TODO: add eui64 whenever added as configurable
270286 this . networkOptions . panID !== currentNetParams . panId ||
271287 // biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
272- Buffer . from ( this . networkOptions . extendedPanID ! ) . readBigUInt64LE ( 0 ) !== currentNetParams . extendedPANId ||
288+ Buffer . from ( this . networkOptions . extendedPanID ! ) . readBigUInt64LE ( 0 ) !== currentNetParams . extendedPanId ||
273289 // biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
274290 ! Buffer . from ( this . networkOptions . networkKey ! ) . equals ( currentNetParams . networkKey )
275291 ) {
@@ -285,28 +301,20 @@ export class ZoHAdapter extends Adapter {
285301 await this . driver . start ( ) ;
286302 await this . driver . formNetwork ( ) ;
287303
288- this . driver . on ( "frame" , this . onFrame . bind ( this ) ) ;
289- this . driver . on ( "gpFrame" , this . onGPFrame . bind ( this ) ) ;
290- this . driver . on ( "deviceJoined" , this . onDeviceJoined . bind ( this ) ) ;
291- this . driver . on ( "deviceRejoined" , this . onDeviceRejoined . bind ( this ) ) ;
292- this . driver . on ( "deviceLeft" , this . onDeviceLeft . bind ( this ) ) ;
293- this . driver . on ( "deviceAuthorized" , this . onDeviceAuthorized . bind ( this ) ) ;
294-
295304 return result ;
296305 }
297306
298307 public async stop ( ) : Promise < void > {
299308 this . closing = true ;
300309
301- this . driver . removeAllListeners ( ) ;
302310 this . queue . clear ( ) ;
303311 this . zclWaitress . clear ( ) ;
304312 this . zdoWaitress . clear ( ) ;
305313 await this . driver . stop ( ) ;
306314 }
307315
308316 public async getCoordinatorIEEE ( ) : Promise < string > {
309- return await Promise . resolve ( `0x${ bigUInt64ToHexBE ( this . driver . netParams . eui64 ) } ` ) ;
317+ return await Promise . resolve ( `0x${ bigUInt64ToHexBE ( this . driver . context . netParams . eui64 ) } ` ) ;
310318 }
311319
312320 public async getCoordinatorVersion ( ) : Promise < TsType . CoordinatorVersion > {
@@ -342,18 +350,18 @@ export class ZoHAdapter extends Adapter {
342350
343351 public async getNetworkParameters ( ) : Promise < TsType . NetworkParameters > {
344352 return await Promise . resolve ( {
345- panID : this . driver . netParams . panId ,
346- extendedPanID : `0x${ bigUInt64ToHexBE ( this . driver . netParams . extendedPANId ) } ` ,
347- channel : this . driver . netParams . channel ,
348- nwkUpdateID : this . driver . netParams . nwkUpdateId ,
353+ panID : this . driver . context . netParams . panId ,
354+ extendedPanID : `0x${ bigUInt64ToHexBE ( this . driver . context . netParams . extendedPanId ) } ` ,
355+ channel : this . driver . context . netParams . channel ,
356+ nwkUpdateID : this . driver . context . netParams . nwkUpdateId ,
349357 } ) ;
350358 }
351359
352- /* v8 ignore start */
353- public async addInstallCode ( ieeeAddress : string , key : Buffer ) : Promise < void > {
354- await Promise . reject ( new Error ( `not supported ${ ieeeAddress } , ${ key . toString ( "hex" ) } ` ) ) ;
360+ public async addInstallCode ( ieeeAddress : string , key : Buffer , hashed : boolean ) : Promise < void > {
361+ this . driver . context . addInstallCode ( BigInt ( ieeeAddress ) , key , hashed ) ;
362+
363+ return await Promise . resolve ( ) ;
355364 }
356- /* v8 ignore stop */
357365
358366 /* v8 ignore start */
359367 public waitFor (
@@ -408,7 +416,7 @@ export class ZoHAdapter extends Adapter {
408416 if ( networkAddress === ZSpec . COORDINATOR_ADDRESS ) {
409417 // mock ZDO response using driver layer data for coordinator
410418 // seqNum doesn't matter since waitress bypassed, so don't bother doing any logic for it
411- const response = this . driver . getCoordinatorZDOResponse ( clusterId , payload ) ;
419+ const response = this . driver . apsHandler . getCoordinatorZDOResponse ( clusterId , payload ) ;
412420
413421 if ( ! response ) {
414422 throw new Error ( `Coordinator does not support ZDO cluster ${ clusterId } ` ) ;
@@ -458,20 +466,20 @@ export class ZoHAdapter extends Adapter {
458466 public async permitJoin ( seconds : number , networkAddress ?: number ) : Promise < void > {
459467 if ( networkAddress === undefined ) {
460468 // send ZDO BCAST
461- this . driver . allowJoins ( seconds , true ) ;
462- this . driver . gpEnterCommissioningMode ( seconds ) ;
469+ this . driver . context . allowJoins ( seconds , true ) ;
470+ this . driver . nwkGPHandler . enterCommissioningMode ( seconds ) ;
463471
464472 const clusterId = Zdo . ClusterId . PERMIT_JOINING_REQUEST ;
465473 // `authentication`: TC significance always 1 (zb specs)
466474 const zdoPayload = Zdo . Buffalo . buildRequest ( this . hasZdoMessageOverhead , clusterId , seconds , 1 , [ ] ) ;
467475
468476 await this . sendZdo ( ZSpec . BLANK_EUI64 , ZSpec . BroadcastAddress . DEFAULT , clusterId , zdoPayload , true ) ;
469477 } else if ( networkAddress === ZSpec . COORDINATOR_ADDRESS ) {
470- this . driver . allowJoins ( seconds , true ) ;
471- this . driver . gpEnterCommissioningMode ( seconds ) ;
478+ this . driver . context . allowJoins ( seconds , true ) ;
479+ this . driver . nwkGPHandler . enterCommissioningMode ( seconds ) ;
472480 } else {
473481 // send ZDO to networkAddress
474- this . driver . allowJoins ( seconds , false ) ;
482+ this . driver . context . allowJoins ( seconds , false ) ;
475483
476484 const clusterId = Zdo . ClusterId . PERMIT_JOINING_REQUEST ;
477485 // `authentication`: TC significance always 1 (zb specs)
@@ -654,7 +662,7 @@ export class ZoHAdapter extends Adapter {
654662 * @param apsHeader
655663 * @param apsPayload
656664 */
657- private onFrame (
665+ onFrame (
658666 sender16 : number | undefined ,
659667 sender64 : bigint | undefined ,
660668 apsHeader : ZigbeeAPSHeader ,
@@ -715,7 +723,7 @@ export class ZoHAdapter extends Adapter {
715723 }
716724 }
717725
718- private onGPFrame ( cmdId : number , payload : Buffer , macHeader : MACHeader , nwkHeader : ZigbeeNWKGPHeader , rssi : number ) : void {
726+ onGPFrame ( cmdId : number , payload : Buffer , macHeader : MACHeader , nwkHeader : ZigbeeNWKGPHeader , rssi : number ) : void {
719727 // transform into a ZCL frame
720728 const data = Buffer . alloc ( ( nwkHeader . frameControlExt ?. appId === 0x02 /* ZGP */ ? /* v8 ignore next */ 20 : 15 ) + payload . byteLength ) ;
721729 let offset = 0 ;
@@ -794,7 +802,7 @@ export class ZoHAdapter extends Adapter {
794802 this . emit ( "zclPayload" , zclPayload ) ;
795803 }
796804
797- private onDeviceJoined ( source16 : number , source64 : bigint , capabilities : MACCapabilities ) : void {
805+ onDeviceJoined ( source16 : number , source64 : bigint , capabilities : MACCapabilities ) : void {
798806 // XXX: don't delay if no cap? (joined through router)
799807 if ( capabilities ?. rxOnWhenIdle ) {
800808 this . emit ( "deviceJoined" , { networkAddress : source16 , ieeeAddr : `0x${ bigUInt64ToHexBE ( source64 ) } ` } ) ;
@@ -805,16 +813,17 @@ export class ZoHAdapter extends Adapter {
805813 } , 5000 ) ;
806814 }
807815 }
808- private onDeviceRejoined ( source16 : number , source64 : bigint , _capabilities : MACCapabilities ) : void {
816+
817+ onDeviceRejoined ( source16 : number , source64 : bigint , _capabilities : MACCapabilities ) : void {
809818 this . emit ( "deviceJoined" , { networkAddress : source16 , ieeeAddr : `0x${ bigUInt64ToHexBE ( source64 ) } ` } ) ;
810819 }
811820
812- private onDeviceLeft ( source16 : number , source64 : bigint ) : void {
821+ onDeviceLeft ( source16 : number , source64 : bigint ) : void {
813822 this . emit ( "deviceLeave" , { networkAddress : source16 , ieeeAddr : `0x${ bigUInt64ToHexBE ( source64 ) } ` } ) ;
814823 }
815824
816825 /* v8 ignore start */
817- private onDeviceAuthorized ( _source16 : number , _source64 : bigint ) : void { }
826+ onDeviceAuthorized ( _source16 : number , _source64 : bigint ) : void { }
818827 /* v8 ignore stop */
819828
820829 private waitressTimeoutFormatter ( matcher : WaitressMatcher , timeout : number ) : string {
0 commit comments