]> git.basschouten.com Git - openhab-addons.git/blob
25c46195895d0fc45e10f88ed1cc2ee996837d59
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.paradoxalarm.internal;
14
15 import java.util.Arrays;
16 import java.util.concurrent.Executors;
17 import java.util.concurrent.ScheduledExecutorService;
18 import java.util.concurrent.TimeUnit;
19
20 import org.openhab.binding.paradoxalarm.internal.communication.ICommunicatorBuilder;
21 import org.openhab.binding.paradoxalarm.internal.communication.IParadoxCommunicator;
22 import org.openhab.binding.paradoxalarm.internal.communication.ParadoxBuilderFactory;
23 import org.openhab.binding.paradoxalarm.internal.model.PanelType;
24 import org.openhab.binding.paradoxalarm.internal.model.ParadoxPanel;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * The {@link Main} - used for testing purposes of low-level stuff.
30  *
31  * @author Konstantin Polihronov - Initial contribution
32  */
33 public class Main {
34
35     private static Logger logger = LoggerFactory.getLogger(Main.class);
36
37     private static String ipAddress;
38     private static int port;
39
40     // PASSWORD is your IP150 password
41     private static String ip150Password;
42
43     // PC Password is the value of section 3012, i.e. if value is 0987, PC Password is two bytes 0x09, 0x87
44     private static String pcPassword;
45
46     private static ScheduledExecutorService scheduler;
47
48     private static IParadoxCommunicator communicator;
49     private static ParadoxPanel panel;
50
51     public static void main(String[] args) {
52         readArguments(args);
53
54         try {
55             scheduler = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
56
57             ParadoxBuilderFactory factory = new ParadoxBuilderFactory();
58             ICommunicatorBuilder builder = factory.createBuilder(PanelType.EVO192);
59             communicator = builder.withIp150Password(ip150Password).withPcPassword(pcPassword).withIpAddress(ipAddress)
60                     .withTcpPort(port).withMaxPartitions(4).withMaxZones(20).withScheduler(scheduler)
61                     .withEncryption(true).build();
62
63             panel = new ParadoxPanel();
64             panel.setCommunicator(communicator);
65             communicator.setListeners(Arrays.asList(panel));
66
67             communicator.startLoginSequence();
68
69             scheduler.scheduleWithFixedDelay(() -> {
70                 refreshMemoryMap(panel, false);
71             }, 7, 5, TimeUnit.SECONDS);
72         } catch (Exception e) {
73             logger.error("Exception: ", e);
74             System.exit(0);
75         }
76     }
77
78     private static void refreshMemoryMap(ParadoxPanel panel, boolean withEpromValues) {
79         logger.debug("Refreshing memory map");
80         IParadoxCommunicator communicator = panel.getCommunicator();
81         communicator.refreshMemoryMap();
82         panel.getPartitions().stream().forEach(partition -> logger.debug("Partition={}", partition));
83         panel.getZones().stream().filter(zone -> zone.getId() == 19).forEach(zone -> logger.debug("Zone={}", zone));
84         logger.debug("PanelTime={}, ACLevel={}, DCLevel={}, BatteryLevel={}", panel.getPanelTime(), panel.getVdcLevel(),
85                 panel.getDcLevel(), panel.getBatteryLevel());
86     }
87
88     private static void readArguments(String[] args) {
89         MainMethodArgParser parser = new MainMethodArgParser(args);
90         logger.info("Arguments retrieved successfully from CLI.");
91
92         ip150Password = parser.getPassword();
93         logger.info("IP150 Password: {}", ip150Password);
94
95         pcPassword = parser.getPcPassword();
96         logger.info("PC Password: {}", pcPassword);
97
98         ipAddress = parser.getIpAddress();
99         logger.info("IP150 IP Address: {}", ipAddress);
100
101         port = Integer.parseInt(parser.getPort());
102         logger.info("IP150 port: {}", port);
103     }
104 }