]> git.basschouten.com Git - openhab-addons.git/blob
0d044fae92020c5dd5532c4d01881cb64c535951
[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.fineoffsetweatherstation.internal.domain;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.fineoffsetweatherstation.internal.Utils;
17
18 /**
19  * The Commands supported by the gateway.
20  *
21  * @author Andreas Berger - Initial contribution
22  */
23 @NonNullByDefault
24 public enum Command {
25
26     /**
27      * read current data,reply data size is 2bytes.
28      */
29     CMD_WS980_LIVEDATA((byte) 0x0b, 2),
30
31     /**
32      * send SSID and Password to WIFI module
33      */
34     CMD_WRITE_SSID((byte) 0x11, 1),
35
36     /**
37      * UDP cast for device echo,answer back data size is 2 Bytes
38      */
39     CMD_BROADCAST((byte) 0x12, 2),
40
41     /**
42      * read aw.net setting
43      */
44     CMD_READ_ECOWITT((byte) 0x1E, 1),
45
46     /**
47      * write back awt.net setting
48      */
49     CMD_WRITE_ECOWITT((byte) 0x1F, 1),
50
51     /**
52      * read Wunderground setting
53      */
54     CMD_READ_WUNDERGROUND((byte) 0x20, 1),
55
56     /**
57      * write back Wunderground setting
58      */
59     CMD_WRITE_WUNDERGROUND((byte) 0x21, 1),
60
61     /**
62      * read WeatherObservationsWebsite setting
63      */
64     CMD_READ_WOW((byte) 0x22, 1),
65
66     /**
67      * write back WeatherObservationsWebsite setting
68      */
69     CMD_WRITE_WOW((byte) 0x23, 1),
70
71     /**
72      * read Weathercloud setting
73      */
74     CMD_READ_WEATHERCLOUD((byte) 0x24, 1),
75
76     /**
77      * write back Weathercloud setting
78      */
79     CMD_WRITE_WEATHERCLOUD((byte) 0x25, 1),
80
81     /**
82      * read MAC address
83      */
84     CMD_READ_SATION_MAC((byte) 0x26, 1),
85
86     /**
87      * read Customized sever setting
88      */
89     CMD_READ_CUSTOMIZED((byte) 0x2A, 1),
90
91     /**
92      * write back Customized sever setting
93      */
94     CMD_WRITE_CUSTOMIZED((byte) 0x2B, 1),
95
96     /**
97      * firmware upgrade
98      */
99     CMD_WRITE_UPDATE((byte) 0x43, 1),
100
101     /**
102      * read current firmware version number
103      */
104     CMD_READ_FIRMWARE_VERSION((byte) 0x50, 1),
105
106     CMD_READ_USR_PATH((byte) 0x51, 1),
107
108     CMD_WRITE_USR_PATH((byte) 0x52, 1),
109
110     // the following command is only valid for GW1000, WH2650 and wn1900
111
112     /**
113      * read current data,reply data size is 2bytes.
114      */
115     CMD_GW1000_LIVEDATA((byte) 0x27, 2),
116
117     /**
118      * read Soilmoisture Sensor calibration parameters
119      */
120     CMD_GET_SOILHUMIAD((byte) 0x28, 1),
121
122     /**
123      * write back Soilmoisture Sensor calibration parameters
124      */
125     CMD_SET_SOILHUMIAD((byte) 0x29, 1),
126
127     /**
128      * read multi channel sensor offset value
129      */
130     CMD_GET_MulCH_OFFSET((byte) 0x2C, 1),
131
132     /**
133      * write back multi channel sensor OFFSET value
134      */
135     CMD_SET_MulCH_OFFSET((byte) 0x2D, 1),
136
137     /**
138      * read PM2.5OFFSET calibration data
139      */
140     CMD_GET_PM25_OFFSET((byte) 0x2E, 1),
141
142     /**
143      * writeback PM2.5OFFSET calibration data
144      */
145     CMD_SET_PM25_OFFSET((byte) 0x2F, 1),
146
147     /**
148      * read system info
149      */
150     CMD_READ_SSSS((byte) 0x30, 1),
151
152     /**
153      * write back system info
154      */
155     CMD_WRITE_SSSS((byte) 0x31, 1),
156
157     /**
158      * read rain data
159      */
160     CMD_READ_RAINDATA((byte) 0x34, 1),
161
162     /**
163      * write back rain data
164      */
165     CMD_WRITE_RAINDATA((byte) 0x35, 1),
166
167     /**
168      * read rain gain
169      */
170     CMD_READ_GAIN((byte) 0x36, 1),
171
172     /**
173      * write back rain gain
174      */
175     CMD_WRITE_GAIN((byte) 0x37, 1),
176
177     /**
178      * read sensor set offset calibration value
179      */
180     CMD_READ_CALIBRATION((byte) 0x38, 1),
181
182     /**
183      * write back sensor set offset value
184      */
185     CMD_WRITE_CALIBRATION((byte) 0x39, 1),
186
187     /**
188      * read Sensors ID
189      */
190     CMD_READ_SENSOR_ID((byte) 0x3A, 1),
191
192     /**
193      * write back Sensors ID
194      */
195     CMD_WRITE_SENSOR_ID((byte) 0x3B, 1),
196
197     /**
198      * this is reserved for newly added sensors
199      */
200     CMD_READ_SENSOR_ID_NEW((byte) 0x3C, 2),
201
202     /**
203      * system restart
204      */
205     CMD_WRITE_REBOOT((byte) 0x40, 1),
206
207     /**
208      * reset to default
209      */
210     CMD_WRITE_RESET((byte) 0x41, 1),
211
212     CMD_READ_CUSTOMIZED_PATH((byte) 0x51, 1),
213
214     CMD_WRITE_CUSTOMIZED_PATH((byte) 0x52, 1),
215
216     /**
217      * CO2 OFFSET
218      */
219     CMD_GET_CO2_OFFSET((byte) 0x53, 1),
220
221     /**
222      * CO2 OFFSET
223      */
224     CMD_SET_CO2_OFFSET((byte) 0x54, 1),
225
226     /**
227      * read rain reset time
228      */
229     CMD_READ_RSTRAIN_TIME((byte) 0x55, 1),
230
231     /**
232      * write back rain reset time
233      */
234     CMD_WRITE_RSTRAIN_TIME((byte) 0x56, 1);
235
236     private final byte code;
237     private final int sizeBytes;
238
239     Command(byte code, int sizeBytes) {
240         this.code = code;
241         this.sizeBytes = sizeBytes;
242     }
243
244     public byte[] getPayload() {
245         byte size = 3; // + rest of payload / not yet implemented
246         return new byte[] { (byte) 0xff, (byte) 0xff, code, size, (byte) (code + size) };
247     }
248
249     public byte[] getPayloadAlternative() {
250         if (sizeBytes == 2) {
251             return new byte[] { (byte) 0xff, (byte) 0xff, code, 0, (byte) (sizeBytes + 2),
252                     (byte) ((code + sizeBytes + 2) % 0xff) };
253         }
254         byte size = 3;
255         return new byte[] { (byte) 0xff, (byte) 0xff, code, size, (byte) ((code + size) % 0xff) };
256     }
257
258     public boolean isHeaderValid(byte[] data) {
259         if (data.length < 4 + sizeBytes) {
260             return false;
261         }
262         return data[0] == (byte) 0xff && data[1] == (byte) 0xff && data[2] == code;
263     }
264
265     public boolean isResponseValid(byte[] data) {
266         return isHeaderValid(data) && Utils.validateChecksum(data, sizeBytes);
267     }
268 }