Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember: Handle port close event triggered with error but without port error event. #1080

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/adapter/ember/adapter/emberAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ export class EmberAdapter extends Adapter {
}

private initVariables(): void {
this.ezsp.removeAllListeners(EzspEvents.ncpNeedsResetAndInit);
this.ezsp.removeAllListeners(EzspEvents.NCP_NEEDS_RESET_AND_INIT);

clearInterval(this.watchdogCountersHandle);

Expand All @@ -833,7 +833,7 @@ export class EmberAdapter extends Adapter {
this.networkCache = initNetworkCache();
this.manufacturerCode = DEFAULT_MANUFACTURER_CODE;// will be set in NCP in initEzsp

this.ezsp.once(EzspEvents.ncpNeedsResetAndInit, this.onNcpNeedsResetAndInit.bind(this));
this.ezsp.once(EzspEvents.NCP_NEEDS_RESET_AND_INIT, this.onNcpNeedsResetAndInit.bind(this));
}

/**
Expand Down Expand Up @@ -2679,7 +2679,6 @@ export class EmberAdapter extends Adapter {
logger.info(`======== Ember Adapter Starting ========`, NS);
this.initVariables();

logger.debug(`Starting EZSP with stack configuration: "${this.stackConfig}".`, NS);
const result = await this.initEzsp();

return result;
Expand Down
8 changes: 4 additions & 4 deletions src/adapter/ember/ezsp/ezsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const MESSAGE_TAG_MASK = 0x7F;
/* eslint-disable max-len */
export enum EzspEvents {
//-- App logic
ncpNeedsResetAndInit = 'ncpNeedsResetAndInit',
NCP_NEEDS_RESET_AND_INIT = 'NCP_NEEDS_RESET_AND_INIT',

//-- ezspIncomingMessageHandler
/** params => status: EmberZdoStatus, sender: EmberNodeId, apsFrame: EmberApsFrame, payload: { cluster-dependent @see zdo.ts } */
Expand Down Expand Up @@ -261,7 +261,7 @@ export enum EzspEvents {
* - They will throw `EzspStatus` if `sendCommand` fails or the returned value(s) by NCP are invalid (wrong length, etc).
* - Most will return `EmberStatus` given by NCP (some `EzspStatus`, some `SLStatus`...).
*
* @event 'ncpNeedsResetAndInit(EzspStatus)' An error was detected that requires resetting the NCP.
* @event 'NCP_NEEDS_RESET_AND_INIT(EzspStatus)' An error was detected that requires resetting the NCP.
*/
export class Ezsp extends EventEmitter {
private readonly tickInterval: number;
Expand Down Expand Up @@ -390,7 +390,7 @@ export class Ezsp extends EventEmitter {
}

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

private onAshFrame(): void {
Expand Down Expand Up @@ -436,7 +436,7 @@ export class Ezsp extends EventEmitter {
// For all other errors, we reset the NCP
if ((status !== EzspStatus.ERROR_SECURITY_PARAMETERS_INVALID) && (status !== EzspStatus.ERROR_OVERFLOW)
&& (status !== EzspStatus.ERROR_QUEUE_FULL)) {
this.emit(EzspEvents.ncpNeedsResetAndInit, status);
this.emit(EzspEvents.NCP_NEEDS_RESET_AND_INIT, status);
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/adapter/ember/uart/ash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,23 @@ export class UartAsh extends EventEmitter {
* Handle port closing
* @param err A boolean for Socket, an Error for serialport
*/
private async onPortClose(err: boolean | Error): Promise<void> {
logger.info(`Port closed. Error? ${err ?? 'no'}`, NS);
private async onPortClose(error: boolean | Error): Promise<void> {
logger.info(`Port closed.`, NS);

if (error && this.flags !== 0) {
logger.info(`Port close ${error}`, NS);
this.flags = 0;
this.emit(AshEvents.FATAL_ERROR, EzspStatus.ERROR_SERIAL_INIT);
}
}

/**
* Handle port error
* @param error
*/
private async onPortError(error: Error): Promise<void> {
logger.info(`Port error: ${error}`, NS);
logger.info(`Port ${error}`, NS);
this.flags = 0;
this.emit(AshEvents.FATAL_ERROR, EzspStatus.ERROR_SERIAL_INIT);
}

Expand Down