2 * Copyright (c) 2010-2022 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.velux.internal.bridge.slip;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.bridge.common.BridgeCommunicationProtocol;
17 import org.openhab.binding.velux.internal.bridge.common.GetHouseStatus;
18 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
19 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
20 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
21 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Protocol specific bridge communication supported by the Velux bridge:
27 * <B>Retrieve House Status</B>
29 * Common Message semantic: Communication from the bridge and storing returned information within the class itself.
31 * As 3rd level class it defines informations how to receive answer through the
32 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
33 * as described by the interface {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
34 * SlipBridgeCommunicationProtocol}.
36 * Methods in addition to the mentioned interface:
38 * <LI>{@link #getNtfNodeID} to retrieve the node identifier which has been changed.</LI>
39 * <LI>{@link #getNtfState} to retrieve the state of the node which has been changed.</LI>
40 * <LI>{@link #getNtfCurrentPosition} to retrieve the actual position of this node.</LI>
41 * <LI>{@link #getNtfTarget} to retrieve the target position of this node.</LI>
44 * NOTE: the class does NOT define a request as it only works as receiver.
46 * @see BridgeCommunicationProtocol
47 * @see SlipBridgeCommunicationProtocol
49 * @author Guenther Schreiner - Initial contribution.
52 class SCgetHouseStatus extends GetHouseStatus implements BridgeCommunicationProtocol, SlipBridgeCommunicationProtocol {
53 private final Logger logger = LoggerFactory.getLogger(SCgetHouseStatus.class);
55 private static final String DESCRIPTION = "Retrieve House Status";
56 private static final Command COMMAND = Command.GW_OPENHAB_RECEIVEONLY;
59 * ===========================================================
63 @SuppressWarnings("unused")
64 private byte[] requestData = new byte[0];
67 * ===========================================================
71 private boolean success = false;
72 private boolean finished = false;
74 private int ntfNodeID;
76 private int ntfCurrentPosition;
77 private int ntfTarget;
80 * ===========================================================
81 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
85 public String name() {
90 public CommandNumber getRequestCommand() {
91 logger.debug("getRequestCommand() returns {} ({}).", COMMAND.name(), COMMAND.getCommand());
92 return COMMAND.getCommand();
96 public byte[] getRequestDataAsArrayOfBytes() {
101 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
102 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
105 Packet responseData = new Packet(thisResponseData);
106 switch (Command.get(responseCommand)) {
107 case GW_NODE_STATE_POSITION_CHANGED_NTF:
108 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 20)) {
111 ntfNodeID = responseData.getOneByteValue(0);
112 ntfState = responseData.getOneByteValue(1);
113 ntfCurrentPosition = responseData.getTwoByteValue(2);
114 ntfTarget = responseData.getTwoByteValue(4);
115 @SuppressWarnings("unused")
116 int ntfFP1CurrentPosition = responseData.getTwoByteValue(6);
117 @SuppressWarnings("unused")
118 int ntfFP2CurrentPosition = responseData.getTwoByteValue(8);
119 @SuppressWarnings("unused")
120 int ntfFP3CurrentPosition = responseData.getTwoByteValue(10);
121 @SuppressWarnings("unused")
122 int ntfFP4CurrentPosition = responseData.getTwoByteValue(12);
123 int ntfRemainingTime = responseData.getTwoByteValue(14);
124 int ntfTimeStamp = responseData.getFourByteValue(16);
125 // Extracting information items
126 logger.trace("setResponse(): ntfNodeID={}.", ntfNodeID);
127 logger.trace("setResponse(): ntfState={}.", ntfState);
128 logger.trace("setResponse(): ntfCurrentPosition={}.", ntfCurrentPosition);
129 logger.trace("setResponse(): ntfTarget={}.", ntfTarget);
130 logger.trace("setResponse(): ntfRemainingTime={}.", ntfRemainingTime);
131 logger.trace("setResponse(): ntfTimeStamp={}.", ntfTimeStamp);
136 KLF200Response.errorLogging(logger, responseCommand);
138 KLF200Response.outroLogging(logger, success, finished);
142 public boolean isCommunicationFinished() {
147 public boolean isCommunicationSuccessful() {
152 * ===========================================================
153 * Methods in addition to the interface {@link BridgeCommunicationProtocol}
157 * @return <b>ntfNodeID</b> returns the Actuator Id as int.
159 public int getNtfNodeID() {
164 * @return <b>ntfState</b> returns the state of the Actuator as int.
166 public int getNtfState() {
171 * @return <b>ntfCurrentPosition</b> returns the current position of the Actuator as int.
173 public int getNtfCurrentPosition() {
174 return ntfCurrentPosition;
178 * @return <b>ntfTarget</b> returns the target position of the Actuator as int.
180 public int getNtfTarget() {