Skip to content

Commit

Permalink
fix: Ember: minor cleanup (#1223)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored Oct 25, 2024
1 parent 85b6e5c commit bf8b468
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/adapter/ember/ezsp/ezsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,6 @@ export class Ezsp extends EventEmitter<EmberEzspEventMap> {
* Triggered by @see 'FRAME'
*/
private onAshFrame(): void {
// trigger housekeeping in ASH layer
this.ash.sendExec();

const buffer = this.ash.rxQueue.getPrecedingEntry();

if (buffer == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/ember/uart/ash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ export class UartAsh extends EventEmitter<UartAshEventMap> {

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);
Expand Down
10 changes: 9 additions & 1 deletion test/adapter/ember/ezsp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
});

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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 () => {
Expand All @@ -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);
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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);
});
});
});

0 comments on commit bf8b468

Please sign in to comment.