Skip to content

Commit 0317295

Browse files
authored
feat: ZBOSS: group and broadcast requests (#1200)
* sendZclFrameToAll broadcast request * sendZclFrameToGroup * lint * lint * lint
1 parent b007282 commit 0317295

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

src/adapter/zboss/adapter/zbossAdapter.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,13 @@ export class ZBOSSAdapter extends Adapter {
426426
}
427427

428428
public async sendZclFrameToGroup(groupID: number, zclFrame: Zcl.Frame, sourceEndpoint?: number): Promise<void> {
429-
logger.error(() => `NOT SUPPORTED: sendZclFrameToGroup(${groupID},${JSON.stringify(zclFrame)},${sourceEndpoint})`, NS);
430-
return;
429+
await this.driver.grequest(
430+
groupID,
431+
sourceEndpoint === ZSpec.GP_ENDPOINT ? ZSpec.GP_PROFILE_ID : ZSpec.HA_PROFILE_ID,
432+
zclFrame.cluster.ID,
433+
sourceEndpoint || 0x01,
434+
zclFrame.toBuffer(),
435+
);
431436
}
432437

433438
public async sendZclFrameToAll(
@@ -436,8 +441,14 @@ export class ZBOSSAdapter extends Adapter {
436441
sourceEndpoint: number,
437442
destination: ZSpec.BroadcastAddress,
438443
): Promise<void> {
439-
logger.error(() => `NOT SUPPORTED: sendZclFrameToAll(${endpoint},${JSON.stringify(zclFrame)},${sourceEndpoint},${destination})`, NS);
440-
return;
444+
await this.driver.brequest(
445+
destination,
446+
sourceEndpoint === ZSpec.GP_ENDPOINT && endpoint === ZSpec.GP_ENDPOINT ? ZSpec.GP_PROFILE_ID : ZSpec.HA_PROFILE_ID,
447+
zclFrame.cluster.ID,
448+
endpoint,
449+
sourceEndpoint || 0x01,
450+
zclFrame.toBuffer(),
451+
);
441452
}
442453

443454
public async setChannelInterPAN(channel: number): Promise<void> {

src/adapter/zboss/commands.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,11 @@ export const FRAMES: {[key in CommandId]?: ZBOSSFrameDesc} = {
689689
request: [
690690
{name: 'paramLength', type: DataType.UINT8},
691691
{name: 'dataLength', type: DataType.UINT16},
692-
{name: 'ieee', type: DataType.IEEE_ADDR},
692+
{name: 'addr', type: DataType.IEEE_ADDR},
693693
{name: 'profileID', type: DataType.UINT16},
694694
{name: 'clusterID', type: DataType.UINT16},
695-
//{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => ![2,3].includes(payload.dstAddrMode)},
696-
{name: 'dstEndpoint', type: DataType.UINT8},
695+
{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => [2, 3].includes(payload.dstAddrMode)},
696+
//{name: 'dstEndpoint', type: DataType.UINT8},
697697
{name: 'srcEndpoint', type: DataType.UINT8},
698698
{name: 'radius', type: DataType.UINT8},
699699
{name: 'dstAddrMode', type: DataType.UINT8},
@@ -707,7 +707,7 @@ export const FRAMES: {[key in CommandId]?: ZBOSSFrameDesc} = {
707707
response: [
708708
...commonResponse,
709709
{name: 'ieee', type: DataType.IEEE_ADDR},
710-
{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => ![2, 3].includes(payload.dstAddrMode)},
710+
{name: 'dstEndpoint', type: DataType.UINT8, condition: (payload) => [2, 3].includes(payload.dstAddrMode)},
711711
{name: 'srcEndpoint', type: DataType.UINT8},
712712
{name: 'txTime', type: DataType.UINT32},
713713
{name: 'dstAddrMode', type: DataType.UINT8},

src/adapter/zboss/driver.ts

+48-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {TsType} from '..';
99
import {KeyValue} from '../../controller/tstype';
1010
import {Queue, Waitress} from '../../utils';
1111
import {logger} from '../../utils/logger';
12+
import * as ZSpec from '../../zspec';
1213
import * as Zdo from '../../zspec/zdo';
1314
import {ZDO_REQ_CLUSTER_ID_TO_ZBOSS_COMMAND_ID} from './commands';
1415
import {CommandId, DeviceType, PolicyType, ResetOptions, StatusCodeGeneric} from './enums';
@@ -305,7 +306,7 @@ export class ZBOSSDriver extends EventEmitter {
305306
const payload = {
306307
paramLength: 21,
307308
dataLength: data.length,
308-
ieee: ieee,
309+
addr: ieee,
309310
profileID: profileID,
310311
clusterID: clusterID,
311312
dstEndpoint: dstEp,
@@ -321,6 +322,52 @@ export class ZBOSSDriver extends EventEmitter {
321322
return await this.execCommand(CommandId.APSDE_DATA_REQ, payload);
322323
}
323324

325+
public async brequest(
326+
addr: ZSpec.BroadcastAddress,
327+
profileID: number,
328+
clusterID: number,
329+
dstEp: number,
330+
srcEp: number,
331+
data: Buffer,
332+
): Promise<ZBOSSFrame> {
333+
const payload = {
334+
paramLength: 21,
335+
dataLength: data.length,
336+
addr: `0x${addr.toString(16).padStart(16, '0')}`,
337+
profileID: profileID,
338+
clusterID: clusterID,
339+
dstEndpoint: dstEp,
340+
srcEndpoint: srcEp,
341+
radius: 3,
342+
dstAddrMode: 2, // ADDRESS MODE broadcast
343+
txOptions: 2, // ROUTE DISCOVERY
344+
useAlias: 0,
345+
aliasAddr: 0,
346+
aliasSequence: 0,
347+
data: data,
348+
};
349+
return await this.execCommand(CommandId.APSDE_DATA_REQ, payload);
350+
}
351+
352+
public async grequest(group: number, profileID: number, clusterID: number, srcEp: number, data: Buffer): Promise<ZBOSSFrame> {
353+
const payload = {
354+
paramLength: 20,
355+
dataLength: data.length,
356+
addr: `0x${group.toString(16).padStart(16, '0')}`,
357+
profileID: profileID,
358+
clusterID: clusterID,
359+
srcEndpoint: srcEp,
360+
radius: 3,
361+
dstAddrMode: 1, // ADDRESS MODE group
362+
txOptions: 2, // ROUTE DISCOVERY
363+
useAlias: 0,
364+
aliasAddr: 0,
365+
aliasSequence: 0,
366+
data: data,
367+
};
368+
return await this.execCommand(CommandId.APSDE_DATA_REQ, payload);
369+
}
370+
324371
public async requestZdo(clusterId: Zdo.ClusterId, payload: Buffer, disableResponse: boolean): Promise<ZBOSSFrame | void> {
325372
if (!this.port.portOpen) {
326373
throw new Error('Connection not initialized');

src/adapter/zboss/frame.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export function makeFrame(type: FrameType, commandId: CommandId, params: KeyValu
200200
for (const parameter of frameDesc) {
201201
// const options: BuffaloZclOptions = {payload};
202202

203-
if (parameter.condition && !parameter.condition(payload, undefined)) {
203+
if (parameter.condition && !parameter.condition(params, undefined)) {
204204
continue;
205205
}
206206

0 commit comments

Comments
 (0)