]> git.basschouten.com Git - openhab-addons.git/blob
891c9fcf2cda55791c4dc357082d33c5c8a9f48e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.openhab.binding.velux.internal.bridge.common.RunReboot;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
18 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
19 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Protocol specific bridge communication supported by the Velux bridge:
25  * <B>Reboot Bridge</B>
26  * <P>
27  * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
28  * itself.
29  * <P>
30  * As 3rd level class it defines informations how to send query and receive answer through the
31  * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
32  * as described by the {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
33  * SlipBridgeCommunicationProtocol}.
34  * <P>
35  * Methods in addition to the mentioned interface:
36  * <UL>
37  * <LI>{@link #runReboot} for rebooting the Velux hub.</LI>
38  * </UL>
39  *
40  * @see RunReboot
41  * @see SlipBridgeCommunicationProtocol
42  *
43  * @author Andrew Fiddian-Green - Initial contribution.
44  */
45 @NonNullByDefault
46 class SCrunReboot extends RunReboot implements SlipBridgeCommunicationProtocol {
47     private final Logger logger = LoggerFactory.getLogger(SCrunReboot.class);
48
49     private static final String DESCRIPTION = "Issue the reboot command";
50     private static final Command COMMAND = Command.GW_REBOOT_REQ;
51
52     /*
53      * ===========================================================
54      * Message Objects
55      */
56
57     private byte[] requestData = new byte[0];
58
59     /*
60      * ===========================================================
61      * Result Objects
62      */
63
64     private boolean success = false;
65     private boolean finished = false;
66
67     /*
68      * ===========================================================
69      * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
70      */
71
72     @Override
73     public String name() {
74         return DESCRIPTION;
75     }
76
77     @Override
78     public CommandNumber getRequestCommand() {
79         success = false;
80         finished = false;
81         logger.debug("getRequestCommand() returns {} ({}).", COMMAND.name(), COMMAND.getCommand());
82         return COMMAND.getCommand();
83     }
84
85     @Override
86     public byte[] getRequestDataAsArrayOfBytes() {
87         return requestData;
88     }
89
90     @Override
91     public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
92         KLF200Response.introLogging(logger, responseCommand, thisResponseData);
93         success = false;
94         finished = false;
95         switch (Command.get(responseCommand)) {
96             case GW_REBOOT_CFM:
97                 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 0)) {
98                     finished = true;
99                     break;
100                 }
101                 success = true;
102                 finished = true;
103                 break;
104
105             default:
106                 KLF200Response.errorLogging(logger, responseCommand);
107                 finished = true;
108         }
109         KLF200Response.outroLogging(logger, success, finished);
110     }
111
112     @Override
113     public boolean isCommunicationFinished() {
114         return finished;
115     }
116
117     @Override
118     public boolean isCommunicationSuccessful() {
119         return success;
120     }
121 }