]> git.basschouten.com Git - openhab-addons.git/blob
59bd9a9d2d5260b5fb9007a211e4eb1f188aa5ed
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.powermax.internal.message;
14
15 import org.openhab.binding.powermax.internal.state.PowermaxState;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * A class for POWERLINK message handling
21  *
22  * @author Laurent Garnier - Initial contribution
23  */
24 public class PowermaxPowerlinkMessage extends PowermaxBaseMessage {
25
26     private final Logger logger = LoggerFactory.getLogger(PowermaxPowerlinkMessage.class);
27
28     /**
29      * Constructor
30      *
31      * @param message
32      *            the received message as a buffer of bytes
33      */
34     public PowermaxPowerlinkMessage(byte[] message) {
35         super(message);
36     }
37
38     @Override
39     protected PowermaxState handleMessageInternal(PowermaxCommManager commManager) {
40         if (commManager == null) {
41             return null;
42         }
43
44         PowermaxState updatedState = null;
45
46         byte[] message = getRawData();
47         byte subType = message[2];
48
49         if (subType == 0x03) {
50             // keep alive message
51
52             debug("Subtype", subType, "Keep Alive");
53
54             commManager.sendAck(this, (byte) 0x02);
55             updatedState = commManager.createNewState();
56             updatedState.setLastKeepAlive(System.currentTimeMillis());
57         } else if (subType == 0x0A) {
58             byte enroll = message[4];
59
60             debug("Subtype", subType, "Enroll");
61             debug("Enroll", enroll);
62
63             if (enroll == 0x01) {
64                 logger.debug("Powermax alarm binding: Enrolling Powerlink");
65                 commManager.enrollPowerlink();
66                 updatedState = commManager.createNewState();
67                 updatedState.setDownloadSetupRequired(true);
68             } else {
69                 commManager.sendAck(this, (byte) 0x02);
70             }
71         } else {
72             debug("Subtype", subType, "UNKNOWN");
73             commManager.sendAck(this, (byte) 0x02);
74         }
75
76         return updatedState;
77     }
78 }