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.velux.internal.bridge.slip;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.bridge.common.GetDeviceStatus;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
18 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
19 import org.openhab.binding.velux.internal.things.VeluxGwState;
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>Get Bridge Device Status</B>
29 * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
32 * As 3rd level class it defines informations how to send query and receive answer through the
33 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
34 * as described by the interface {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
35 * SlipBridgeCommunicationProtocol}.
37 * Methods in addition to the mentioned interface:
39 * <LI>{@link #getState} to retrieve the Velux gateway status.</LI>
42 * @see GetDeviceStatus
43 * @see SlipBridgeCommunicationProtocol
45 * @author Guenther Schreiner - Initial contribution.
48 class SCgetDeviceStatus extends GetDeviceStatus implements SlipBridgeCommunicationProtocol {
49 private final Logger logger = LoggerFactory.getLogger(SCgetDeviceStatus.class);
51 private static final String DESCRIPTION = "Get Bridge Device Status";
52 private static final Command COMMAND = Command.GW_GET_STATE_REQ;
55 * ===========================================================
56 * Message Content Parameters
59 private int cfmGatewayState;
60 private int cfmSubState;
61 @SuppressWarnings("unused")
62 private int cfmStateData;
65 * ===========================================================
69 private byte[] requestData = new byte[0];
72 * ===========================================================
76 private boolean success = false;
77 private boolean finished = false;
80 * ===========================================================
81 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
85 public String name() {
90 public CommandNumber getRequestCommand() {
93 logger.debug("getRequestCommand() returns {} ({}).", COMMAND.name(), COMMAND.getCommand());
94 return COMMAND.getCommand();
98 public byte[] getRequestDataAsArrayOfBytes() {
99 logger.trace("getRequestDataAsArrayOfBytes() returns data.");
100 requestData = new byte[0];
105 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
106 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
109 Packet responseData = new Packet(thisResponseData);
110 switch (Command.get(responseCommand)) {
111 case GW_GET_STATE_CFM:
112 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 6)) {
116 cfmGatewayState = responseData.getOneByteValue(0);
117 cfmSubState = responseData.getOneByteValue(1);
118 cfmStateData = responseData.getFourByteValue(2);
124 KLF200Response.errorLogging(logger, responseCommand);
127 KLF200Response.outroLogging(logger, success, finished);
131 public boolean isCommunicationFinished() {
136 public boolean isCommunicationSuccessful() {
141 * ===========================================================
142 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
146 public VeluxGwState getState() {
147 VeluxGwState thisGwState = new VeluxGwState((byte) cfmGatewayState, (byte) cfmSubState);
148 logger.trace("getState() returns {} ({}).", thisGwState, thisGwState.toDescription());