2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.paradoxalarm.internal;
15 import java.util.Arrays;
16 import java.util.concurrent.Executors;
17 import java.util.concurrent.ScheduledExecutorService;
18 import java.util.concurrent.TimeUnit;
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;
29 * The {@link Main} - used for testing purposes of low-level stuff.
31 * @author Konstantin Polihronov - Initial contribution
35 private static Logger logger = LoggerFactory.getLogger(Main.class);
37 private static String ipAddress;
38 private static int port;
40 // PASSWORD is your IP150 password
41 private static String ip150Password;
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;
46 private static ScheduledExecutorService scheduler;
48 private static IParadoxCommunicator communicator;
49 private static ParadoxPanel panel;
51 public static void main(String[] args) {
55 scheduler = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
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();
63 panel = new ParadoxPanel();
64 panel.setCommunicator(communicator);
65 communicator.setListeners(Arrays.asList(panel));
67 communicator.startLoginSequence();
69 scheduler.scheduleWithFixedDelay(() -> {
70 refreshMemoryMap(panel, false);
71 }, 7, 5, TimeUnit.SECONDS);
72 } catch (Exception e) {
73 logger.error("Exception: ", e);
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());
88 private static void readArguments(String[] args) {
89 MainMethodArgParser parser = new MainMethodArgParser(args);
90 logger.info("Arguments retrieved successfully from CLI.");
92 ip150Password = parser.getPassword();
93 logger.info("IP150 Password: {}", ip150Password);
95 pcPassword = parser.getPcPassword();
96 logger.info("PC Password: {}", pcPassword);
98 ipAddress = parser.getIpAddress();
99 logger.info("IP150 IP Address: {}", ipAddress);
101 port = Integer.parseInt(parser.getPort());
102 logger.info("IP150 port: {}", port);