Skip to content

Commit

Permalink
Create a different flow for actuators (#41)
Browse files Browse the repository at this point in the history
* Create a different flow for actuators

* v2.5.1-beta.1

* fix the version number
  • Loading branch information
madchicken authored Jan 30, 2023
1 parent e43ff7d commit 1fb43f8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "comelit-client",
"version": "2.5.0",
"version": "2.5.1",
"author": "Pierpaolo Follia",
"repository": {
"type": "git",
Expand Down
6 changes: 5 additions & 1 deletion src/bin/icona-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')}`);
}
Expand Down
45 changes: 45 additions & 0 deletions src/icona-bridge-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
readJSON
} from "./icona/packet";
import {
ActuatorDoorItem,
AddressbooksConfigMessage,
AuthMessage,
BaseMessage,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<ConfigurationResponse>();
this.logger.debug(`${JSON.stringify(resp)}`);
const resp2 = await this.readResponse<ConfigurationResponse>();
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);
}
}
13 changes: 5 additions & 8 deletions src/icona/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1fb43f8

Please sign in to comment.