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.RunProductSearch;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
18 import org.openhab.binding.velux.internal.things.VeluxGwState;
19 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
20 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Protocol specific bridge communication supported by the Velux bridge:
26 * <B>Check for lost Nodes</B>
28 * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
31 * Implementing the protocol-independent class {@link RunProductSearch}.
33 * As 3rd level class it defines informations how to send query and receive answer through the
34 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
35 * as described by the interface {@link SlipBridgeCommunicationProtocol}.
37 * Methods in addition to the mentioned interface:
39 * <LI>{@link SCrunProductSearch#getState} to retrieve the Velux gateway status.</LI>
42 * @see RunProductSearch
43 * @see SlipBridgeCommunicationProtocol
45 * @author Guenther Schreiner - Initial contribution.
48 class SCrunProductSearch extends RunProductSearch implements SlipBridgeCommunicationProtocol {
49 private final Logger logger = LoggerFactory.getLogger(SCrunProductSearch.class);
51 private static final String DESCRIPTION = "Check for lost Nodes";
52 private static final Command COMMAND = Command.GW_GET_STATE_REQ;
58 private byte[] requestData = new byte[0];
59 private short responseCommand;
60 private byte[] responseData = new byte[0];
63 * ===========================================================
64 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
68 public String name() {
73 public CommandNumber getRequestCommand() {
74 return COMMAND.getCommand();
78 public byte[] getRequestDataAsArrayOfBytes() {
79 requestData = new byte[0];
84 public void setResponse(short thisResponseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
85 logger.trace("setResponseCommand({}, {}) called.", thisResponseCommand, new Packet(thisResponseData));
86 responseCommand = thisResponseCommand;
87 responseData = thisResponseData;
91 public boolean isCommunicationFinished() {
92 return (responseCommand == Command.GW_GET_STATE_CFM.getShort());
96 public boolean isCommunicationSuccessful() {
97 return (responseCommand == Command.GW_GET_STATE_CFM.getShort());
101 * ===========================================================
102 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
105 public VeluxGwState getState() {
106 byte stateValue = responseData[0];
107 byte subStateValue = responseData[1];
108 VeluxGwState thisGwState = new VeluxGwState(stateValue, subStateValue);
109 logger.trace("getState() returns {} ({}).", thisGwState, thisGwState.toDescription());