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.PowermaxState;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * A class for POWERLINK message handling
22 * @author Laurent Garnier - Initial contribution
24 public class PowermaxPowerlinkMessage extends PowermaxBaseMessage {
26 private final Logger logger = LoggerFactory.getLogger(PowermaxPowerlinkMessage.class);
32 * the received message as a buffer of bytes
34 public PowermaxPowerlinkMessage(byte[] message) {
39 public PowermaxState handleMessage(PowermaxCommManager commManager) {
40 super.handleMessage(commManager);
42 if (commManager == null) {
46 PowermaxState updatedState = null;
48 byte[] message = getRawData();
49 byte subType = message[2];
51 if (subType == 0x03) {
53 commManager.sendAck(this, (byte) 0x02);
54 updatedState = commManager.createNewState();
55 updatedState.setLastKeepAlive(System.currentTimeMillis());
56 } else if (subType == 0x0A && message[4] == 0x01) {
57 logger.debug("Powermax alarm binding: Enrolling Powerlink");
58 commManager.enrollPowerlink();
59 updatedState = commManager.createNewState();
60 updatedState.setDownloadSetupRequired(true);
62 commManager.sendAck(this, (byte) 0x02);
69 public String toString() {
70 String str = super.toString();
72 byte[] message = getRawData();
73 byte subType = message[2];
75 if (subType == 0x03) {
76 str += "\n - sub type = keep alive";
77 } else if (subType == 0x0A) {
78 str += "\n - sub type = enroll";
79 str += "\n - enroll = " + String.format("%02X", message[4]);
81 str += "\n - sub type = " + String.format("%02X", subType);