Skip to content

Commit

Permalink
fix: Ember: bugfixes (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored Mar 29, 2024
1 parent 976c212 commit ca5fa57
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
12 changes: 4 additions & 8 deletions src/adapter/ember/adapter/emberAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,11 @@ export class EmberAdapter extends Adapter {

await this.onNCPPreReset();

try {
// NOTE: something deep in this call can throw too
const result = (await this.ezsp.start());
// NOTE: something deep in this call can throw too
const startResult = (await this.ezsp.start());

if (result !== EzspStatus.SUCCESS) {
throw new Error(`Failed to start EZSP layer with status=${EzspStatus[result]}.`);
}
} catch (err) {
throw err;
if (startResult !== EzspStatus.SUCCESS) {
throw new Error(`Failed to start EZSP layer with status=${EzspStatus[startResult]}.`);
}

// call before any other command, else fails
Expand Down
6 changes: 3 additions & 3 deletions src/adapter/ember/ezsp/ezsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class Ezsp extends EventEmitter {
this.buffalo = new EzspBuffalo(this.frameContents);

this.ash = new UartAsh(options);
this.ash.on(AshEvents.rxError, this.onAshRxError.bind(this));
this.ash.on(AshEvents.fatalError, this.onAshFatalError.bind(this));
this.ash.on(AshEvents.frame, this.onAshFrame.bind(this));
}

Expand Down Expand Up @@ -389,8 +389,8 @@ export class Ezsp extends EventEmitter {
return this.ash.connected;
}

private onAshRxError(status: EzspStatus): void {
this.ezspErrorHandler(status);
private onAshFatalError(status: EzspStatus): void {
this.emit(EzspEvents.ncpNeedsResetAndInit, status);
}

private onAshFrame(): void {
Expand Down
15 changes: 9 additions & 6 deletions src/adapter/ember/uart/ash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const ashGetACKNum = (ctrl: number): number => ((ctrl & ASH_ACKNUM_MASK) >> ASH_


export enum AshEvents {
/** When the ASH protocol detects an error while receiving a frame. NOTE: TX errors are handled by the EZSP layer. */
rxError = 'rxError',
/** When the ASH protocol detects a fatal error (bubbles up to restart adapter). */
fatalError = 'fatalError',
/** When a frame has been parsed and queued in the rxQueue. */
frame = 'frame',
}
Expand Down Expand Up @@ -318,7 +318,11 @@ export class UartAsh extends EventEmitter {
return false;
}

return SocketPortUtils.isTcpPath(this.portOptions.path) ? !this.socketPort?.closed : !!this.serialPort?.isOpen;
if (SocketPortUtils.isTcpPath(this.portOptions.path)) {
return this.socketPort && !this.socketPort.closed;
} else {
return this.serialPort && this.serialPort.isOpen;
}
}

/**
Expand Down Expand Up @@ -572,8 +576,7 @@ export class UartAsh extends EventEmitter {
*/
private async onPortError(error: Error): Promise<void> {
console.log(`Port error: ${error}`);
this.hostDisconnect(EzspStatus.ERROR_SERIAL_INIT);
await this.stop();
this.emit(AshEvents.fatalError, EzspStatus.ERROR_SERIAL_INIT);
}

/**
Expand Down Expand Up @@ -608,7 +611,7 @@ export class UartAsh extends EventEmitter {
if (this.flags & Flag.CONNECTED) {
console.error(`Error while parsing received frame, status=${EzspStatus[status]}.`);
// if we're connected (not in reset) and get here, we need to reset
this.emit(AshEvents.rxError, EzspStatus.HOST_FATAL_ERROR);
this.emit(AshEvents.fatalError, EzspStatus.HOST_FATAL_ERROR);
return;
} else {
debug(`Error while parsing received frame in NOT_CONNECTED state (flags=${this.flags}), status=${EzspStatus[status]}.`);
Expand Down

0 comments on commit ca5fa57

Please sign in to comment.