diff --git a/src/adapter/ember/ezsp/ezsp.ts b/src/adapter/ember/ezsp/ezsp.ts index 939d091eba..640c0ae527 100644 --- a/src/adapter/ember/ezsp/ezsp.ts +++ b/src/adapter/ember/ezsp/ezsp.ts @@ -367,9 +367,6 @@ export class Ezsp extends EventEmitter { * Triggered by @see 'FRAME' */ private onAshFrame(): void { - // trigger housekeeping in ASH layer - this.ash.sendExec(); - const buffer = this.ash.rxQueue.getPrecedingEntry(); if (buffer == null) { diff --git a/src/adapter/ember/uart/ash.ts b/src/adapter/ember/uart/ash.ts index 48ff8d5122..c18cb32587 100644 --- a/src/adapter/ember/uart/ash.ts +++ b/src/adapter/ember/uart/ash.ts @@ -591,7 +591,7 @@ export class UartAsh extends EventEmitter { const status = this.receiveFrame(buffer); - setImmediate(this.sendExec.bind(this)); // always trigger to cover all cases (also triggered in Ezsp layer when a DATA frame is emitted) + this.sendExec(); // always trigger to cover all cases if (status !== EzspStatus.SUCCESS && status !== EzspStatus.ASH_IN_PROGRESS && status !== EzspStatus.NO_RX_DATA) { logger.error(`Error while parsing received frame, status=${EzspStatus[status]}.`, NS); diff --git a/test/adapter/ember/ezsp.test.ts b/test/adapter/ember/ezsp.test.ts index 3213253fb2..af4b40373f 100644 --- a/test/adapter/ember/ezsp.test.ts +++ b/test/adapter/ember/ezsp.test.ts @@ -284,6 +284,7 @@ describe('Ember Ezsp Layer', () => { describe('When connected', () => { let callbackDispatchSpy: jest.SpyInstance; let mockResponseWaiterResolve = jest.fn(); + let ashSendExecSpy: jest.SpyInstance; beforeEach(async () => { const startResult = ezsp.start(); @@ -294,8 +295,8 @@ describe('Ember Ezsp Layer', () => { expect(ezsp.checkConnection()).toBeTruthy(); callbackDispatchSpy = jest.spyOn(ezsp, 'callbackDispatch').mockImplementation(jest.fn()); + ashSendExecSpy = jest.spyOn(ezsp.ash, 'sendExec'); - callbackDispatchSpy.mockClear(); mockResponseWaiterResolve.mockClear(); }); @@ -310,6 +311,7 @@ describe('Ember Ezsp Layer', () => { expect(mockResponseWaiterResolve).toHaveBeenCalledTimes(1); expect(mockResponseWaiterResolve).toHaveBeenCalledWith(EzspStatus.SUCCESS); expect(ezsp.frameToString).toStrictEqual(`[FRAME: ID=52:"SEND_UNICAST" Seq=39 Len=10]`); + expect(ashSendExecSpy).toHaveBeenCalledTimes(1); await emitFromSerial(ezsp, Buffer.from(MESSAGE_SENT_HANDLER_FN1_ASH_RAW, 'hex')); await jest.advanceTimersByTimeAsync(1000); @@ -318,6 +320,7 @@ describe('Ember Ezsp Layer', () => { expect(mockResponseWaiterResolve).toHaveBeenCalledTimes(1); expect(ezsp.callbackFrameToString).toStrictEqual(`[CBFRAME: ID=63:"MESSAGE_SENT_HANDLER" Seq=39 Len=26]`); expect(ezsp.frameToString).toStrictEqual(`[FRAME: ID=52:"SEND_UNICAST" Seq=39 Len=10]`); + expect(ashSendExecSpy).toHaveBeenCalledTimes(2); await emitFromSerial(ezsp, Buffer.from(INCOMING_MESSAGE_HANDLER_FN2_ASH_RAW, 'hex')); await jest.advanceTimersByTimeAsync(1000); @@ -326,6 +329,7 @@ describe('Ember Ezsp Layer', () => { expect(mockResponseWaiterResolve).toHaveBeenCalledTimes(1); expect(ezsp.callbackFrameToString).toStrictEqual(`[CBFRAME: ID=69:"INCOMING_MESSAGE_HANDLER" Seq=39 Len=42]`); expect(ezsp.frameToString).toStrictEqual(`[FRAME: ID=52:"SEND_UNICAST" Seq=39 Len=10]`); + expect(ashSendExecSpy).toHaveBeenCalledTimes(3); }); it('Parses valid incoming callback frame while waiting for response frame', async () => { @@ -339,6 +343,7 @@ describe('Ember Ezsp Layer', () => { expect(mockResponseWaiterResolve).toHaveBeenCalledTimes(0); expect(ezsp.callbackFrameToString).toStrictEqual(`[CBFRAME: ID=63:"MESSAGE_SENT_HANDLER" Seq=39 Len=26]`); expect(ezsp.frameToString).toStrictEqual(`[FRAME: ID=0:"VERSION" Seq=0 Len=0]`); + expect(ashSendExecSpy).toHaveBeenCalledTimes(1); await emitFromSerial(ezsp, Buffer.from(SET_POLICY_REPLY_FN1_ASH_RAW, 'hex')); await jest.advanceTimersByTimeAsync(1000); @@ -348,6 +353,7 @@ describe('Ember Ezsp Layer', () => { expect(mockResponseWaiterResolve).toHaveBeenCalledWith(EzspStatus.SUCCESS); expect(ezsp.frameToString).toStrictEqual(`[FRAME: ID=85:"SET_POLICY" Seq=79 Len=9]`); expect(ezsp.callbackFrameToString).toStrictEqual(`[CBFRAME: ID=63:"MESSAGE_SENT_HANDLER" Seq=39 Len=26]`); + expect(ashSendExecSpy).toHaveBeenCalledTimes(2); }); it('Parses invalid incoming frame', async () => { @@ -363,6 +369,7 @@ describe('Ember Ezsp Layer', () => { expect(mockResponseWaiterResolve).toHaveBeenCalledTimes(1); expect(mockResponseWaiterResolve).toHaveBeenCalledWith(EzspStatus.ERROR_WRONG_DIRECTION); expect(ezsp.frameToString).toStrictEqual(`[FRAME: ID=52:"SEND_UNICAST" Seq=39 Len=10]`); + expect(ashSendExecSpy).toHaveBeenCalledTimes(1); }); it('Parses invalid incoming callback frame', async () => { @@ -375,6 +382,7 @@ describe('Ember Ezsp Layer', () => { expect(mockResponseWaiterResolve).toHaveBeenCalledTimes(0); expect(ezsp.callbackFrameToString).toStrictEqual(`[CBFRAME: ID=63:"MESSAGE_SENT_HANDLER" Seq=39 Len=26]`); expect(ezsp.frameToString).toStrictEqual(`[FRAME: ID=0:"VERSION" Seq=0 Len=0]`); + expect(ashSendExecSpy).toHaveBeenCalledTimes(1); }); }); });