2 * Copyright (c) 2010-2020 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.powermax.internal.message;
15 import org.openhab.binding.powermax.internal.state.PowermaxPanelSettings;
16 import org.openhab.binding.powermax.internal.state.PowermaxState;
19 * A class for EVENTLOG message handling
21 * @author Laurent Garnier - Initial contribution
23 public class PowermaxEventLogMessage extends PowermaxBaseMessage {
25 public static final String[] LOG_EVENT_TABLE = new String[] { "None", "Interior Alarm", "Perimeter Alarm",
26 "Delay Alarm", "24h Silent Alarm", "24h Audible Alarm", "Tamper", "Control Panel Tamper", "Tamper Alarm",
27 "Tamper Alarm", "Communication Loss", "Panic From Keyfob", "Panic From Control Panel", "Duress",
28 "Confirm Alarm", "General Trouble", "General Trouble Restore", "Interior Restore", "Perimeter Restore",
29 "Delay Restore", "24h Silent Restore", "24h Audible Restore", "Tamper Restore",
30 "Control Panel Tamper Restore", "Tamper Restore", "Tamper Restore", "Communication Restore", "Cancel Alarm",
31 "General Restore", "Trouble Restore", "Not used", "Recent Close", "Fire", "Fire Restore", "No Active",
32 "Emergency", "No used", "Disarm Latchkey", "Panic Restore", "Supervision (Inactive)",
33 "Supervision Restore (Active)", "Low Battery", "Low Battery Restore", "AC Fail", "AC Restore",
34 "Control Panel Low Battery", "Control Panel Low Battery Restore", "RF Jamming", "RF Jamming Restore",
35 "Communications Failure", "Communications Restore", "Telephone Line Failure", "Telephone Line Restore",
36 "Auto Test", "Fuse Failure", "Fuse Restore", "Keyfob Low Battery", "Keyfob Low Battery Restore",
37 "Engineer Reset", "Battery Disconnect", "1-Way Keypad Low Battery", "1-Way Keypad Low Battery Restore",
38 "1-Way Keypad Inactive", "1-Way Keypad Restore Active", "Low Battery", "Clean Me", "Fire Trouble",
39 "Low Battery", "Battery Restore", "AC Fail", "AC Restore", "Supervision (Inactive)",
40 "Supervision Restore (Active)", "Gas Alert", "Gas Alert Restore", "Gas Trouble", "Gas Trouble Restore",
41 "Flood Alert", "Flood Alert Restore", "X-10 Trouble", "X-10 Trouble Restore", "Arm Home", "Arm Away",
42 "Quick Arm Home", "Quick Arm Away", "Disarm", "Fail To Auto-Arm", "Enter To Test Mode",
43 "Exit From Test Mode", "Force Arm", "Auto Arm", "Instant Arm", "Bypass", "Fail To Arm", "Door Open",
44 "Communication Established By Control Panel", "System Reset", "Installer Programming", "Wrong Password",
45 "Not Sys Event", "Not Sys Event", "Extreme Hot Alert", "Extreme Hot Alert Restore", "Freeze Alert",
46 "Freeze Alert Restore", "Human Cold Alert", "Human Cold Alert Restore", "Human Hot Alert",
47 "Human Hot Alert Restore", "Temperature Sensor Trouble", "Temperature Sensor Trouble Restore",
48 // new values partition models
49 "PIR Mask", "PIR Mask Restore", "", "", "", "", "", "", "", "", "", "", "Alarmed", "Restore", "Alarmed",
50 "Restore", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Exit Installer", "Enter Installer",
53 public static final String[] LOG_USER_TABLE = new String[] { "System", "Zone 1", "Zone 2", "Zone 3", "Zone 4",
54 "Zone 5", "Zone 6", "Zone 7", "Zone 8", "Zone 9", "Zone 10", "Zone 11", "Zone 12", "Zone 13", "Zone 14",
55 "Zone 15", "Zone 16", "Zone 17", "Zone 18", "Zone 19", "Zone 20", "Zone 21", "Zone 22", "Zone 23",
56 "Zone 24", "Zone 25", "Zone 26", "Zone 27", "Zone 28", "Zone 29", "Zone 30", "Fob 1", "Fob 2", "Fob 3",
57 "Fob 4", "Fob 5", "Fob 6", "Fob 7", "Fob 8", "User 1", "User 2", "User 3", "User 4", "User 5", "User 6",
58 "User 7", "User 8", "Pad 1", "Pad 2", "Pad 3", "Pad 4", "Pad 5", "Pad 6", "Pad 7", "Pad 8", "Siren 1",
59 "Siren 2", "2Pad 1", "2Pad 2", "2Pad 3", "2Pad 4", "X10 1", "X10 2", "X10 3", "X10 4", "X10 5", "X10 6",
60 "X10 7", "X10 8", "X10 9", "X10 10", "X10 11", "X10 12", "X10 13", "X10 14", "X10 15", "PGM", "GSM",
61 "P-LINK", "PTag 1", "PTag 2", "PTag 3", "PTag 4", "PTag 5", "PTag 6", "PTag 7", "PTag 8" };
67 * the received message as a buffer of bytes
69 public PowermaxEventLogMessage(byte[] message) {
74 public PowermaxState handleMessage(PowermaxCommManager commManager) {
75 super.handleMessage(commManager);
77 if (commManager == null) {
81 PowermaxPanelSettings panelSettings = commManager.getPanelSettings();
82 PowermaxState updatedState = commManager.createNewState();
84 byte[] message = getRawData();
85 int eventNum = message[3] & 0x000000FF;
89 int eventCnt = message[2] & 0x000000FF;
90 updatedState.setEventLogSize(eventCnt - 1);
92 int second = message[4] & 0x000000FF;
93 int minute = message[5] & 0x000000FF;
94 int hour = message[6] & 0x000000FF;
95 int day = message[7] & 0x000000FF;
96 int month = message[8] & 0x000000FF;
97 int year = (message[9] & 0x000000FF) + 2000;
98 byte eventZone = message[10];
99 byte logEvent = message[11];
100 String logEventStr = ((logEvent & 0x000000FF) < LOG_EVENT_TABLE.length)
101 ? LOG_EVENT_TABLE[logEvent & 0x000000FF]
103 String logUserStr = ((eventZone & 0x000000FF) < LOG_USER_TABLE.length)
104 ? LOG_USER_TABLE[eventZone & 0x000000FF]
108 if (panelSettings.getPanelType().getPartitions() > 1) {
110 if ((second & 0x01) == 0x01) {
112 } else if ((second & 0x02) == 0x02) {
114 } else if ((second & 0x04) == 0x04) {
119 eventStr = String.format("%02d/%02d/%04d %02d:%02d / %s: %s (%s)", day, month, year, hour, minute, part,
120 logEventStr, logUserStr);
122 eventStr = String.format("%02d/%02d/%04d %02d:%02d:%02d: %s (%s)", day, month, year, hour, minute,
123 second, logEventStr, logUserStr);
125 updatedState.setEventLogSize(eventNum);
126 updatedState.setEventLog(eventNum, eventStr);
133 public String toString() {
134 String str = super.toString();
136 byte[] message = getRawData();
137 int eventNum = message[3] & 0x000000FF;
139 str += "\n - event number = " + eventNum;
142 int eventCnt = message[2] & 0x000000FF;
144 str += "\n - event count = " + eventCnt;
146 int second = message[4] & 0x000000FF;
147 int minute = message[5] & 0x000000FF;
148 int hour = message[6] & 0x000000FF;
149 int day = message[7] & 0x000000FF;
150 int month = message[8] & 0x000000FF;
151 int year = (message[9] & 0x000000FF) + 2000;
152 byte eventZone = message[10];
153 byte logEvent = message[11];
155 String logEventStr = ((logEvent & 0x000000FF) < LOG_EVENT_TABLE.length)
156 ? LOG_EVENT_TABLE[logEvent & 0x000000FF]
158 String logUserStr = ((eventZone & 0x000000FF) < LOG_USER_TABLE.length)
159 ? LOG_USER_TABLE[eventZone & 0x000000FF]
162 str += "\n - event " + eventNum + " date & time = "
163 + String.format("%02d/%02d/%04d %02d:%02d:%02d", day, month, year, hour, minute, second);
164 str += "\n - event " + eventNum + " zone code = " + String.format("%08X - %s", eventZone, logUserStr);
165 str += "\n - event " + eventNum + " event code = " + String.format("%08X - %s", logEvent, logEventStr);