Skip to content

EZSP: fixed losting children, fixed reconnect and optional retry #661

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

Merged
merged 4 commits into from
Feb 10, 2023
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
9 changes: 3 additions & 6 deletions src/adapter/ezsp/adapter/ezspAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,11 @@ class EZSPAdapter extends Adapter {
);
}

const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID);
const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, disableResponse || zclFrame.Header.frameControl.disableDefaultResponse);
frame.profileId = 0x0104;
frame.sourceEndpoint = sourceEndpoint || 0x01;
frame.destinationEndpoint = endpoint;
frame.groupId = 0;
frame.options = EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY | EmberApsOption.APS_OPTION_RETRY;

this.driver.setNode(networkAddress, new EmberEUI64(ieeeAddr));
const dataConfirmResult = await this.driver.request(networkAddress, frame, zclFrame.toBuffer());
Expand Down Expand Up @@ -488,12 +487,11 @@ class EZSPAdapter extends Adapter {
public async sendZclFrameToGroup(groupID: number, zclFrame: ZclFrame): Promise<void> {
return this.driver.queue.execute<void>(async () => {
this.checkInterpanLock();
const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID);
const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, false);
frame.profileId = 0x0104;
frame.sourceEndpoint = 0x01;
frame.destinationEndpoint = 0x01;
frame.groupId = groupID;
frame.options = EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY | EmberApsOption.APS_OPTION_RETRY;
const dataConfirmResult = await this.driver.mrequest(frame, zclFrame.toBuffer());
/**
* As a group command is not confirmed and thus immidiately returns
Expand All @@ -507,12 +505,11 @@ class EZSPAdapter extends Adapter {
public async sendZclFrameToAll(endpoint: number, zclFrame: ZclFrame, sourceEndpoint: number): Promise<void> {
return this.driver.queue.execute<void>(async () => {
this.checkInterpanLock();
const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID);
const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, false);
frame.profileId = sourceEndpoint === 242 && endpoint === 242 ? 0xA1E0 : 0x0104;
frame.sourceEndpoint = sourceEndpoint;
frame.destinationEndpoint = endpoint;
frame.groupId = 0xFFFD;
frame.options = EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY | EmberApsOption.APS_OPTION_RETRY;
const dataConfirmResult = await this.driver.mrequest(frame, zclFrame.toBuffer());

/**
Expand Down
29 changes: 15 additions & 14 deletions src/adapter/ezsp/driver/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export class Driver extends EventEmitter {
debug.log(`Reset connection. Try ${attempts}`);
try {
await this.stop();
this.ezsp = undefined;
await Wait(1000);
await this.startup(this.port, this.serialOpt, this.nwkOpt, this.greenPowerGroup);
break;
Expand All @@ -133,6 +132,7 @@ export class Driver extends EventEmitter {
this.serialOpt = serialOpt;
this.greenPowerGroup = greenPowerGroup;
this.transactionID = 1;
this.ezsp = undefined;
this.ezsp = new Ezsp();
this.ezsp.on('reset', this.onReset.bind(this));
this.ezsp.on('close', this.onClose.bind(this));
Expand Down Expand Up @@ -350,14 +350,14 @@ export class Driver extends EventEmitter {
debug.log(`stackStatusHandler: ${EmberStatus.valueToName(EmberStatus, frame.status)}`);
break;
}
case (frameName === 'childJoinHandler'): {
if (!frame.joining) {
this.handleNodeLeft(frame.childId, frame.childEui64);
} else {
this.handleNodeJoined(frame.childId, frame.childEui64);
}
break;
}
// case (frameName === 'childJoinHandler'): {
// if (!frame.joining) {
// this.handleNodeLeft(frame.childId, frame.childEui64);
// } else {
// this.handleNodeJoined(frame.childId, frame.childEui64);
// }
// break;
// }
case (frameName == 'gpepIncomingMessageHandler'): {
this.handleGPMessage(frame);
break;
Expand Down Expand Up @@ -530,17 +530,18 @@ export class Driver extends EventEmitter {
return this.transactionID;
}

public makeApsFrame(clusterId: number): EmberApsFrame {
public makeApsFrame(clusterId: number, disableResponse: boolean): EmberApsFrame {
const frame = new EmberApsFrame();
frame.clusterId = clusterId;
frame.profileId = 0;
frame.sequence = this.nextTransactionID();
frame.sourceEndpoint = 0;
frame.destinationEndpoint = 0;
frame.groupId = 0;
//frame.options = EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY;
frame.options = EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY | EmberApsOption.APS_OPTION_RETRY;
//frame.options = EmberApsOption.APS_OPTION_NONE;
frame.options = EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY;
if (!disableResponse) {
frame.options ||= EmberApsOption.APS_OPTION_RETRY;
}
return frame;
}

Expand All @@ -561,7 +562,7 @@ export class Driver extends EventEmitter {
const requestName = EmberZDOCmd.valueName(EmberZDOCmd, requestCmd);
const responseName = EmberZDOCmd.valueName(EmberZDOCmd, responseCmd);
debug.log(`ZDO ${requestName} params: ${JSON.stringify(params)}`);
const frame = this.makeApsFrame(requestCmd as number);
const frame = this.makeApsFrame(requestCmd as number, false);
const payload = this.makeZDOframe(requestCmd as number, {transId: frame.sequence, ...params});
const waiter = this.waitFor(networkAddress, responseCmd as number, frame.sequence).start();
const res = await this.request(networkAddress, frame, payload);
Expand Down