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.GetLANConfig;
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.VeluxGwLAN;
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 LAN configuration</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 {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
35 * SlipBridgeCommunicationProtocol}.
37 * Methods in addition to the mentioned interface:
39 * <LI>{@link #getLANConfig} to retrieve the current LAN configuration.</LI>
43 * @see SlipBridgeCommunicationProtocol
45 * @author Guenther Schreiner - Initial contribution.
48 class SCgetLANConfig extends GetLANConfig implements SlipBridgeCommunicationProtocol {
49 private final Logger logger = LoggerFactory.getLogger(SCgetLANConfig.class);
51 private static final String DESCRIPTION = "Retrieve LAN configuration";
52 private static final Command COMMAND = Command.GW_GET_NETWORK_SETUP_REQ;
55 * ===========================================================
56 * Message Content Parameters
59 private int cfmIpAddress;
62 private boolean cfmDHCP;
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 requestData = new byte[1];
104 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
105 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
108 Packet responseData = new Packet(thisResponseData);
109 switch (Command.get(responseCommand)) {
110 case GW_GET_NETWORK_SETUP_CFM:
112 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 13)) {
115 cfmIpAddress = responseData.getFourByteValue(0);
116 cfmMask = responseData.getFourByteValue(4);
117 cfmDefGW = responseData.getFourByteValue(8);
118 cfmDHCP = responseData.getOneByteValue(12) == 0 ? false : true;
123 KLF200Response.errorLogging(logger, responseCommand);
126 KLF200Response.outroLogging(logger, success, finished);
130 public boolean isCommunicationFinished() {
135 public boolean isCommunicationSuccessful() {
140 * ===========================================================
141 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
145 public VeluxGwLAN getLANConfig() {
146 logger.trace("getLANConfig() called.");
147 VeluxGwLAN result = new VeluxGwLAN(Packet.intToIPAddressString(cfmIpAddress),
148 Packet.intToIPAddressString(cfmMask), Packet.intToIPAddressString(cfmDefGW), cfmDHCP);
149 logger.debug("getLANConfig() returns {}.", result);