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.RunProductDiscovery;
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.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>Ask the Bridge to detect (new) products/actuators</B>
28 * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
31 * As 3rd level class it defines informations how to send query and 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 * There are no methods in addition to the mentioned interface.
38 * @see SlipBridgeCommunicationProtocol
40 * @author Guenther Schreiner - Initial contribution.
43 class SCrunProductDiscovery extends RunProductDiscovery implements SlipBridgeCommunicationProtocol {
44 private final Logger logger = LoggerFactory.getLogger(SCrunProductDiscovery.class);
46 private static final String DESCRIPTION = "Detect Products/Actuators";
47 private static final Command COMMAND = Command.GW_CS_DISCOVER_NODES_REQ;
50 * ===========================================================
51 * Message Content Parameters
54 private int reqNodeType = 0; // NO_TYPE (All nodes except controller)
57 * ===========================================================
61 private byte[] requestData = new byte[0];
64 * ===========================================================
68 private boolean success = false;
69 private boolean finished = false;
72 * ===========================================================
73 * Methods required for interface {@link BridgeCommunicationProtocol}.
77 public String name() {
82 public CommandNumber getRequestCommand() {
85 logger.debug("getRequestCommand() returns {} ({}).", COMMAND.name(), COMMAND.getCommand());
86 return COMMAND.getCommand();
90 public byte[] getRequestDataAsArrayOfBytes() {
91 logger.trace("getRequestDataAsArrayOfBytes() returns data for detection with type {}.", reqNodeType);
92 Packet request = new Packet(new byte[1]);
93 request.setOneByteValue(0, reqNodeType);
94 requestData = request.toByteArray();
99 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
100 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
103 Packet responseData = new Packet(thisResponseData);
104 switch (Command.get(responseCommand)) {
105 case GW_CS_DISCOVER_NODES_CFM:
106 logger.trace("setResponse(): received confirmation for discovery mode.");
109 case GW_CS_DISCOVER_NODES_NTF:
111 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 131)) {
114 int ntfDiscoverStatus = responseData.getOneByteValue(130);
115 switch (ntfDiscoverStatus) {
117 logger.trace("setResponse(): returned status: OK. Discovered nodes. See bit array.");
121 logger.warn("setResponse(): returned status: ERROR - Failed. CS not ready.");
125 "setResponse(): returned status: OK. But some nodes were not added to system table (e.g. System table has reached its limit).");
128 logger.warn("setResponse(): returned status: ERROR - CS busy with another task.");
131 logger.warn("setResponse({}): returned status={} (Reserved/unknown).",
132 Command.get(responseCommand).toString(), ntfDiscoverStatus);
138 KLF200Response.errorLogging(logger, responseCommand);
141 KLF200Response.outroLogging(logger, success, finished);
145 public boolean isCommunicationFinished() {
150 public boolean isCommunicationSuccessful() {