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

fix: Use BuffaloZdo in ZStackAdapter #1133

Merged
merged 26 commits into from
Sep 14, 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
16 changes: 2 additions & 14 deletions src/adapter/ember/adapter/emberAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,6 @@ export type LinkKeyBackupData = {
incomingFrameCounter: number;
};

/** Enum to pass strings from numbers up to Z2M. */
enum RoutingTableStatus {
ACTIVE = 0x0,
DISCOVERY_UNDERWAY = 0x1,
DISCOVERY_FAILED = 0x2,
INACTIVE = 0x3,
VALIDATION_UNDERWAY = 0x4,
RESERVED1 = 0x5,
RESERVED2 = 0x6,
RESERVED3 = 0x7,
}

enum NetworkInitAction {
/** Ain't that nice! */
DONE,
Expand Down Expand Up @@ -536,7 +524,7 @@ export class EmberAdapter extends Adapter {
*/
private async onZDOResponse(apsFrame: EmberApsFrame, sender: NodeId, messageContents: Buffer): Promise<void> {
try {
const payload = BuffaloZdo.readResponse(apsFrame.clusterId, messageContents);
const payload = BuffaloZdo.readResponse(apsFrame.clusterId, messageContents, true);

logger.debug(() => `<~~~ [ZDO ${Zdo.ClusterId[apsFrame.clusterId]} from=${sender} ${payload ? JSON.stringify(payload) : 'OK'}]`, NS);
this.oneWaitress.resolveZDO(sender, apsFrame, payload);
Expand Down Expand Up @@ -2168,7 +2156,7 @@ export class EmberAdapter extends Adapter {
for (const entry of result.entryList) {
table.push({
destinationAddress: entry.destinationAddress,
status: RoutingTableStatus[entry.status], // get str value from enum to satisfy upstream's needs
status: TsType.RoutingTableStatus[entry.status], // get str value from enum to satisfy upstream's needs
nextHop: entry.nextHopAddress,
});
}
Expand Down
12 changes: 12 additions & 0 deletions src/adapter/tstype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ interface LQI {
neighbors: LQINeighbor[];
}

enum RoutingTableStatus {
ACTIVE = 0x0,
DISCOVERY_UNDERWAY = 0x1,
DISCOVERY_FAILED = 0x2,
INACTIVE = 0x3,
VALIDATION_UNDERWAY = 0x4,
RESERVED1 = 0x5,
RESERVED2 = 0x6,
RESERVED3 = 0x7,
}

interface RoutingTableEntry {
destinationAddress: number;
status: string;
Expand Down Expand Up @@ -113,4 +124,5 @@ export {
StartResult,
RoutingTableEntry,
AdapterOptions,
RoutingTableStatus,
};
13 changes: 6 additions & 7 deletions src/adapter/z-stack/adapter/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {AdapterBackup} from './adapter-backup';
import {AdapterNvMemory} from './adapter-nv-memory';
import {Endpoints} from './endpoints';
import {ZnpVersion} from './tstype';
import ZStackAdapter from './zStackAdapter';

const NS = 'zh:adapter:zstack:manager';

Expand All @@ -33,12 +34,14 @@ export class ZnpAdapterManager {
public backup: AdapterBackup;

private znp: Znp;
private adapter: ZStackAdapter;
private options: ZStackModels.StartupOptions;
// @ts-expect-error initialized in `start()`
private nwkOptions: Models.NetworkOptions;

public constructor(znp: Znp, options: ZStackModels.StartupOptions) {
public constructor(adapter: ZStackAdapter, znp: Znp, options: ZStackModels.StartupOptions) {
this.znp = znp;
this.adapter = adapter;
this.options = options;
this.nv = new AdapterNvMemory(this.znp);
this.backup = new AdapterBackup(this.znp, this.nv, this.options.backupPath);
Expand Down Expand Up @@ -449,13 +452,9 @@ export class ZnpAdapterManager {
* Registers endpoints before beginning normal operation.
*/
private async registerEndpoints(): Promise<void> {
const activeEpResponse = this.znp.waitFor(UnpiConstants.Type.AREQ, Subsystem.ZDO, 'activeEpRsp');
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.znp.request(Subsystem.ZDO, 'activeEpReq', {dstaddr: 0, nwkaddrofinterest: 0});
const activeEp = await activeEpResponse.start().promise;

const activeEp = await this.adapter.activeEndpoints(0);
for (const endpoint of Endpoints) {
if (activeEp.payload.activeeplist.includes(endpoint.endpoint)) {
if (activeEp.endpoints.includes(endpoint.endpoint)) {
logger.debug(`endpoint '${endpoint.endpoint}' already registered`, NS);
} else {
logger.debug(`registering endpoint '${endpoint.endpoint}'`, NS);
Expand Down
Loading