]> git.basschouten.com Git - openhab-addons.git/blob
d496cc12f902376a4f89ee07b1b9e592e641cc72
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.velux.internal.bridge.slip;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.velux.internal.bridge.common.GetWLANConfig;
18 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
19 import org.openhab.binding.velux.internal.things.VeluxGwWLAN;
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;
24
25 /**
26  * Protocol specific bridge communication supported by the Velux bridge:
27  * <B>Retrieve WLAN configuration</B>
28  * <P>
29  * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
30  * itself.
31  * <P>
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 SlipBridgeCommunicationProtocol}.
35  * <P>
36  * Methods in addition to the mentioned interface:
37  * <UL>
38  * <LI>{@link #getWLANConfig} to retrieve the current WLAN configuration.</LI>
39  * </UL>
40  *
41  * @see GetWLANConfig
42  * @see SlipBridgeCommunicationProtocol
43  *
44  *
45  * @author Guenther Schreiner - Initial contribution.
46  */
47 @NonNullByDefault
48 class SCgetWLANConfig extends GetWLANConfig implements SlipBridgeCommunicationProtocol {
49     private final Logger logger = LoggerFactory.getLogger(SCgetWLANConfig.class);
50
51     private static final String DESCRIPTION = "Retrieve WLAN configuration";
52     private static final Command COMMAND = Command.GW_GET_NETWORK_SETUP_REQ;
53
54     private static final String UNSUPPORTED = "*** unsupported-by-current-gateway-firmware ***";
55
56     /*
57      * Message Objects
58      */
59
60     private byte[] requestData = new byte[0];
61     private short responseCommand;
62     @SuppressWarnings("unused")
63     private byte @Nullable [] responseData;
64
65     /*
66      * ===========================================================
67      * Constructor Method
68      */
69
70     public SCgetWLANConfig() {
71         logger.trace("SCgetWLANConfig(constructor) called.");
72         requestData = new byte[1];
73     }
74
75     /*
76      * ===========================================================
77      * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
78      */
79
80     @Override
81     public String name() {
82         return DESCRIPTION;
83     }
84
85     @Override
86     public CommandNumber getRequestCommand() {
87         return COMMAND.getCommand();
88     }
89
90     @Override
91     public byte[] getRequestDataAsArrayOfBytes() {
92         return requestData;
93     }
94
95     @Override
96     public void setResponse(short thisResponseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
97         logger.trace("setResponseCommand({}, {}) called.", thisResponseCommand, new Packet(thisResponseData));
98         responseCommand = thisResponseCommand;
99         responseData = thisResponseData;
100     }
101
102     @Override
103     public boolean isCommunicationFinished() {
104         return true;
105     }
106
107     @Override
108     public boolean isCommunicationSuccessful() {
109         return (responseCommand == Command.GW_GET_NETWORK_SETUP_CFM.getShort());
110     }
111
112     /*
113      * ===========================================================
114      * Methods in addition to interface {@link BridgeCommunicationProtocol}.
115      */
116
117     @Override
118     public VeluxGwWLAN getWLANConfig() {
119         logger.trace("getWLANConfig() called.");
120         // Enhancement idea: Velux should provide an enhanced API.
121         return new VeluxGwWLAN(UNSUPPORTED, UNSUPPORTED);
122     }
123 }