From 1fb43f83dfdc13a7022fc51071cd5843b649e17e Mon Sep 17 00:00:00 2001 From: Pierpaolo Follia Date: Mon, 30 Jan 2023 15:18:12 +0100 Subject: [PATCH] Create a different flow for actuators (#41) * Create a different flow for actuators * v2.5.1-beta.1 * fix the version number --- package.json | 2 +- src/bin/icona-cli.ts | 6 ++++- src/icona-bridge-client.ts | 45 ++++++++++++++++++++++++++++++++++++++ src/icona/types.ts | 13 +++++------ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 4ed1ddc..73a5274 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "comelit-client", - "version": "2.5.0", + "version": "2.5.1", "author": "Pierpaolo Follia", "repository": { "type": "git", diff --git a/src/bin/icona-cli.ts b/src/bin/icona-cli.ts index ce1ce75..96bd038 100644 --- a/src/bin/icona-cli.ts +++ b/src/bin/icona-cli.ts @@ -211,7 +211,11 @@ async function openDoor() { if (item) { logger.info(`Opening door ${item.name} at address ${item["apt-address"]} and index ${item["output-index"]}`); logger.info(serialize(await client.getServerInfo(), options.output)); - await client.openDoor(addressBookAll.vip, item); + if (type === 'actuator') { + await client.openActuator(addressBookAll.vip, item); + } else { + await client.openDoor(addressBookAll.vip, item); + } } else { logger.error(`No door with name ${options.door} found in config. Available door names are: ${addressBookAll.vip["user-parameters"]["opendoor-address-book"].map(d => d.name).join(', ')}`); } diff --git a/src/icona-bridge-client.ts b/src/icona-bridge-client.ts index 2fe17da..35057de 100644 --- a/src/icona-bridge-client.ts +++ b/src/icona-bridge-client.ts @@ -14,6 +14,7 @@ import { readJSON } from "./icona/packet"; import { + ActuatorDoorItem, AddressbooksConfigMessage, AuthMessage, BaseMessage, @@ -126,6 +127,33 @@ function getInitOpenDoorMessage(requestId: number, vip: VIPConfig, doorItem: Doo return PacketMessage.createBinaryPacketFromBuffers(requestId, ...buffers); } +function getInitOpenActuatorMessage(requestId: number, vip: VIPConfig, actuatorDoorItem: ActuatorDoorItem) { + const buffers: Buffer[] = [ + Buffer.from([0xc0, 0x18, 0x45, 0xbe]), // ?? + Buffer.from([0x8f, 0x5c, 0x00, 0x4]), // ?? + Buffer.from([0x00, 0x20, 0xff, 0x1]), // ?? + Buffer.from([0xff, 0xff, 0xff, 0xff]), // -1 + stringToBuffer(`${vip["apt-address"]}${vip["apt-subaddress"]}`, true), + stringToBuffer(`${actuatorDoorItem["apt-address"]}`, true), + NULL + ]; + + return PacketMessage.createBinaryPacketFromBuffers(requestId, ...buffers); +} + +function getOpenActuatorMessage(requestId: number, vip: VIPConfig, actuatorDoorItem: ActuatorDoorItem, confirm = false) { + const buffers: Buffer[] = [ + Buffer.from([confirm ? 0x20 : 0x0, 0x18, 0x45, 0xbe]), // ?? + Buffer.from([0x8f, 0x5c, 0x00, 0x4]), // ?? + Buffer.from([0xff, 0xff, 0xff, 0xff]), // -1 + stringToBuffer(`${vip["apt-address"]}${vip["apt-subaddress"]}`, true), + stringToBuffer(`${actuatorDoorItem["apt-address"]}`, true), + NULL + ]; + + return PacketMessage.createBinaryPacketFromBuffers(requestId, ...buffers); +} + export class IconaBridgeClient { private readonly host: string; private readonly port: number; @@ -352,4 +380,21 @@ export class IconaBridgeClient { const confirmMessage1 = getOpenDoorMessage(channelCTPPData.id, vip, doorItem, true); await this.writeBytePacket(confirmMessage1); } + + async openActuator(vip: VIPConfig, actuatorDoorItem: ActuatorDoorItem) { + if(!this.openChannels.has(Channel.CTPP)) { + await this.openDoorInit(vip); + } + const channelCTPPData = this.openChannels.get(Channel.CTPP); + const message1 = getInitOpenActuatorMessage(channelCTPPData.id, vip, actuatorDoorItem); + await this.writeBytePacket(message1); + const resp = await this.readResponse(); + this.logger.debug(`${JSON.stringify(resp)}`); + const resp2 = await this.readResponse(); + this.logger.debug(`${JSON.stringify(resp2)}`); + const packetMessage1 = getOpenActuatorMessage(channelCTPPData.id, vip, actuatorDoorItem, false); + await this.writeBytePacket(packetMessage1); + const confirmMessage1 = getOpenActuatorMessage(channelCTPPData.id, vip, actuatorDoorItem, true); + await this.writeBytePacket(confirmMessage1); + } } diff --git a/src/icona/types.ts b/src/icona/types.ts index 083e300..b148793 100644 --- a/src/icona/types.ts +++ b/src/icona/types.ts @@ -133,21 +133,18 @@ export interface EntranceDoorItem { "apt-address": string } -export interface ActuatorDoorItem { - id: number, - name: string, - "apt-address": string, - "module-index": number, - "output-index": number -} - export interface DoorItem { + id: number, name: string; "apt-address": string; "output-index": number; "secure-mode": boolean; } +export interface ActuatorDoorItem extends DoorItem { + "module-index": number, +} + export interface OpenDoorAction { action: string; "apt-address": string;