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

ZBOSS: group and broadcast requests #1200

Merged
merged 6 commits into from
Sep 23, 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
19 changes: 15 additions & 4 deletions src/adapter/zboss/adapter/zbossAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,13 @@ export class ZBOSSAdapter extends Adapter {
}

public async sendZclFrameToGroup(groupID: number, zclFrame: Zcl.Frame, sourceEndpoint?: number): Promise<void> {
logger.error(() => `NOT SUPPORTED: sendZclFrameToGroup(${groupID},${JSON.stringify(zclFrame)},${sourceEndpoint})`, NS);
return;
await this.driver.grequest(
groupID,
sourceEndpoint === ZSpec.GP_ENDPOINT ? ZSpec.GP_PROFILE_ID : ZSpec.HA_PROFILE_ID,
zclFrame.cluster.ID,
sourceEndpoint || 0x01,
zclFrame.toBuffer(),
);
}

public async sendZclFrameToAll(
Expand All @@ -436,8 +441,14 @@ export class ZBOSSAdapter extends Adapter {
sourceEndpoint: number,
destination: ZSpec.BroadcastAddress,
): Promise<void> {
logger.error(() => `NOT SUPPORTED: sendZclFrameToAll(${endpoint},${JSON.stringify(zclFrame)},${sourceEndpoint},${destination})`, NS);
return;
await this.driver.brequest(
destination,
sourceEndpoint === ZSpec.GP_ENDPOINT && endpoint === ZSpec.GP_ENDPOINT ? ZSpec.GP_PROFILE_ID : ZSpec.HA_PROFILE_ID,
zclFrame.cluster.ID,
endpoint,
sourceEndpoint || 0x01,
zclFrame.toBuffer(),
);
}

public async setChannelInterPAN(channel: number): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions src/adapter/zboss/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,11 @@ export const FRAMES: {[key in CommandId]?: ZBOSSFrameDesc} = {
request: [
{name: 'paramLength', type: DataType.UINT8},
{name: 'dataLength', type: DataType.UINT16},
{name: 'ieee', type: DataType.IEEE_ADDR},
{name: 'addr', type: DataType.IEEE_ADDR},
{name: 'profileID', type: DataType.UINT16},
{name: 'clusterID', type: DataType.UINT16},
//{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => ![2,3].includes(payload.dstAddrMode)},
{name: 'dstEndpoint', type: DataType.UINT8},
{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => [2, 3].includes(payload.dstAddrMode)},
//{name: 'dstEndpoint', type: DataType.UINT8},
{name: 'srcEndpoint', type: DataType.UINT8},
{name: 'radius', type: DataType.UINT8},
{name: 'dstAddrMode', type: DataType.UINT8},
Expand All @@ -707,7 +707,7 @@ export const FRAMES: {[key in CommandId]?: ZBOSSFrameDesc} = {
response: [
...commonResponse,
{name: 'ieee', type: DataType.IEEE_ADDR},
{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => ![2, 3].includes(payload.dstAddrMode)},
{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => [2, 3].includes(payload.dstAddrMode)},
{name: 'srcEndpoint', type: DataType.UINT8},
{name: 'txTime', type: DataType.UINT32},
{name: 'dstAddrMode', type: DataType.UINT8},
Expand Down
49 changes: 48 additions & 1 deletion src/adapter/zboss/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {TsType} from '..';
import {KeyValue} from '../../controller/tstype';
import {Queue, Waitress} from '../../utils';
import {logger} from '../../utils/logger';
import * as ZSpec from '../../zspec';
import * as Zdo from '../../zspec/zdo';
import {ZDO_REQ_CLUSTER_ID_TO_ZBOSS_COMMAND_ID} from './commands';
import {CommandId, DeviceType, PolicyType, ResetOptions, StatusCodeGeneric} from './enums';
Expand Down Expand Up @@ -305,7 +306,7 @@ export class ZBOSSDriver extends EventEmitter {
const payload = {
paramLength: 21,
dataLength: data.length,
ieee: ieee,
addr: ieee,
profileID: profileID,
clusterID: clusterID,
dstEndpoint: dstEp,
Expand All @@ -321,6 +322,52 @@ export class ZBOSSDriver extends EventEmitter {
return await this.execCommand(CommandId.APSDE_DATA_REQ, payload);
}

public async brequest(
addr: ZSpec.BroadcastAddress,
profileID: number,
clusterID: number,
dstEp: number,
srcEp: number,
data: Buffer,
): Promise<ZBOSSFrame> {
const payload = {
paramLength: 21,
dataLength: data.length,
addr: `0x${addr.toString(16).padStart(16, '0')}`,
profileID: profileID,
clusterID: clusterID,
dstEndpoint: dstEp,
srcEndpoint: srcEp,
radius: 3,
dstAddrMode: 2, // ADDRESS MODE broadcast
txOptions: 2, // ROUTE DISCOVERY
useAlias: 0,
aliasAddr: 0,
aliasSequence: 0,
data: data,
};
return await this.execCommand(CommandId.APSDE_DATA_REQ, payload);
}

public async grequest(group: number, profileID: number, clusterID: number, srcEp: number, data: Buffer): Promise<ZBOSSFrame> {
const payload = {
paramLength: 20,
dataLength: data.length,
addr: `0x${group.toString(16).padStart(16, '0')}`,
profileID: profileID,
clusterID: clusterID,
srcEndpoint: srcEp,
radius: 3,
dstAddrMode: 1, // ADDRESS MODE group
txOptions: 2, // ROUTE DISCOVERY
useAlias: 0,
aliasAddr: 0,
aliasSequence: 0,
data: data,
};
return await this.execCommand(CommandId.APSDE_DATA_REQ, payload);
}

public async requestZdo(clusterId: Zdo.ClusterId, payload: Buffer, disableResponse: boolean): Promise<ZBOSSFrame | void> {
if (!this.port.portOpen) {
throw new Error('Connection not initialized');
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/zboss/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export function makeFrame(type: FrameType, commandId: CommandId, params: KeyValu
for (const parameter of frameDesc) {
// const options: BuffaloZclOptions = {payload};

if (parameter.condition && !parameter.condition(payload, undefined)) {
if (parameter.condition && !parameter.condition(params, undefined)) {
continue;
}

Expand Down