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.GetFirmware;
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.VeluxGwFirmware;
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 Firmware Version</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 #getFirmware} to retrieve the Velux firmware version.</LI>
43 * @see SlipBridgeCommunicationProtocol
45 * @author Guenther Schreiner - Initial contribution.
48 class SCgetFirmware extends GetFirmware implements SlipBridgeCommunicationProtocol {
49 private final Logger logger = LoggerFactory.getLogger(SCgetFirmware.class);
51 private static final String DESCRIPTION = "Retrieve firmware version";
52 private static final Command COMMAND = Command.GW_GET_VERSION_REQ;
55 * ===========================================================
56 * Message Content Parameters
59 private int cfmSoftwareVersionCommand = 0;
60 private int cfmSoftwareVersionWhole = 0;
61 private int cfmSoftwareVersionSub = 0;
62 private int cfmSoftwareVersionBranch = 0;
63 private int cfmSoftwareVersionBuild = 0;
64 private int cfmSoftwareVersionMicroBuild = 0;
65 private int cfmHardwareVersion = 0;
66 private int cfmProductGroup = 0;
67 private int cfmProductType = 0;
70 * ===========================================================
74 private byte[] requestData = new byte[0];
77 * ===========================================================
81 private boolean success = false;
82 private boolean finished = false;
85 * ===========================================================
86 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
90 public String name() {
95 public CommandNumber getRequestCommand() {
98 logger.debug("getRequestCommand() returns {} ({}).", COMMAND.name(), COMMAND.getCommand());
99 return COMMAND.getCommand();
103 public byte[] getRequestDataAsArrayOfBytes() {
104 requestData = new byte[1];
109 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
110 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
113 Packet responseData = new Packet(thisResponseData);
114 switch (Command.get(responseCommand)) {
115 case GW_GET_VERSION_CFM:
116 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 9)) {
120 cfmSoftwareVersionCommand = responseData.getOneByteValue(0);
121 cfmSoftwareVersionWhole = responseData.getOneByteValue(1);
122 cfmSoftwareVersionSub = responseData.getOneByteValue(2);
123 cfmSoftwareVersionBranch = responseData.getOneByteValue(3);
124 cfmSoftwareVersionBuild = responseData.getOneByteValue(4);
125 cfmSoftwareVersionMicroBuild = responseData.getOneByteValue(5);
126 cfmHardwareVersion = responseData.getOneByteValue(6);
127 cfmProductGroup = responseData.getOneByteValue(7);
128 cfmProductType = responseData.getOneByteValue(8);
134 KLF200Response.errorLogging(logger, responseCommand);
137 KLF200Response.outroLogging(logger, success, finished);
141 public boolean isCommunicationFinished() {
146 public boolean isCommunicationSuccessful() {
151 * ===========================================================
152 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
156 public VeluxGwFirmware getFirmware() {
157 String result = String.format("Software version %d.%d.%d.%d.%d.%d, Hardware version %d.%d.%d",
158 cfmSoftwareVersionCommand, cfmSoftwareVersionWhole, cfmSoftwareVersionSub, cfmSoftwareVersionBranch,
159 cfmSoftwareVersionBuild, cfmSoftwareVersionMicroBuild, cfmHardwareVersion, cfmProductGroup,
161 logger.trace("getFirmware() returns {}.", result);
162 return new VeluxGwFirmware(result);