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.fineoffsetweatherstation.internal.domain;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.fineoffsetweatherstation.internal.Utils;
19 * The Commands supported by the gateway.
21 * @author Andreas Berger - Initial contribution
27 * read current data,reply data size is 2bytes.
29 CMD_WS980_LIVEDATA((byte) 0x0b, 2),
32 * send SSID and Password to WIFI module
34 CMD_WRITE_SSID((byte) 0x11, 1),
37 * UDP cast for device echo,answer back data size is 2 Bytes
39 CMD_BROADCAST((byte) 0x12, 2),
44 CMD_READ_ECOWITT((byte) 0x1E, 1),
47 * write back awt.net setting
49 CMD_WRITE_ECOWITT((byte) 0x1F, 1),
52 * read Wunderground setting
54 CMD_READ_WUNDERGROUND((byte) 0x20, 1),
57 * write back Wunderground setting
59 CMD_WRITE_WUNDERGROUND((byte) 0x21, 1),
62 * read WeatherObservationsWebsite setting
64 CMD_READ_WOW((byte) 0x22, 1),
67 * write back WeatherObservationsWebsite setting
69 CMD_WRITE_WOW((byte) 0x23, 1),
72 * read Weathercloud setting
74 CMD_READ_WEATHERCLOUD((byte) 0x24, 1),
77 * write back Weathercloud setting
79 CMD_WRITE_WEATHERCLOUD((byte) 0x25, 1),
84 CMD_READ_SATION_MAC((byte) 0x26, 1),
87 * read Customized sever setting
89 CMD_READ_CUSTOMIZED((byte) 0x2A, 1),
92 * write back Customized sever setting
94 CMD_WRITE_CUSTOMIZED((byte) 0x2B, 1),
99 CMD_WRITE_UPDATE((byte) 0x43, 1),
102 * read current firmware version number
104 CMD_READ_FIRMWARE_VERSION((byte) 0x50, 1),
106 CMD_READ_USR_PATH((byte) 0x51, 1),
108 CMD_WRITE_USR_PATH((byte) 0x52, 1),
110 // the following command is only valid for GW1000, WH2650 and wn1900
113 * read current data,reply data size is 2bytes.
115 CMD_GW1000_LIVEDATA((byte) 0x27, 2),
118 * read Soilmoisture Sensor calibration parameters
120 CMD_GET_SOILHUMIAD((byte) 0x28, 1),
123 * write back Soilmoisture Sensor calibration parameters
125 CMD_SET_SOILHUMIAD((byte) 0x29, 1),
128 * read multi channel sensor offset value
130 CMD_GET_MulCH_OFFSET((byte) 0x2C, 1),
133 * write back multi channel sensor OFFSET value
135 CMD_SET_MulCH_OFFSET((byte) 0x2D, 1),
138 * read PM2.5OFFSET calibration data
140 CMD_GET_PM25_OFFSET((byte) 0x2E, 1),
143 * writeback PM2.5OFFSET calibration data
145 CMD_SET_PM25_OFFSET((byte) 0x2F, 1),
150 CMD_READ_SSSS((byte) 0x30, 1),
153 * write back system info
155 CMD_WRITE_SSSS((byte) 0x31, 1),
160 CMD_READ_RAINDATA((byte) 0x34, 1),
163 * write back rain data
165 CMD_WRITE_RAINDATA((byte) 0x35, 1),
170 CMD_READ_GAIN((byte) 0x36, 1),
173 * write back rain gain
175 CMD_WRITE_GAIN((byte) 0x37, 1),
178 * read sensor set offset calibration value
180 CMD_READ_CALIBRATION((byte) 0x38, 1),
183 * write back sensor set offset value
185 CMD_WRITE_CALIBRATION((byte) 0x39, 1),
190 CMD_READ_SENSOR_ID((byte) 0x3A, 1),
193 * write back Sensors ID
195 CMD_WRITE_SENSOR_ID((byte) 0x3B, 1),
198 * this is reserved for newly added sensors
200 CMD_READ_SENSOR_ID_NEW((byte) 0x3C, 2),
205 CMD_WRITE_REBOOT((byte) 0x40, 1),
210 CMD_WRITE_RESET((byte) 0x41, 1),
212 CMD_READ_CUSTOMIZED_PATH((byte) 0x51, 1),
214 CMD_WRITE_CUSTOMIZED_PATH((byte) 0x52, 1),
219 CMD_GET_CO2_OFFSET((byte) 0x53, 1),
224 CMD_SET_CO2_OFFSET((byte) 0x54, 1),
227 * read rain reset time
229 CMD_READ_RSTRAIN_TIME((byte) 0x55, 1),
232 * write back rain reset time
234 CMD_WRITE_RSTRAIN_TIME((byte) 0x56, 1),
237 * read rain data including piezo (wh90)
239 CMD_READ_RAIN((byte) 0x57, 2),
244 CMD_WRITE_RAIN((byte) 0x58, 1);
246 private final byte code;
247 private final int sizeBytes;
249 Command(byte code, int sizeBytes) {
251 this.sizeBytes = sizeBytes;
254 public byte[] getPayload() {
255 byte size = 3; // + rest of payload / not yet implemented
256 return new byte[] { (byte) 0xff, (byte) 0xff, code, size, (byte) (code + size) };
259 public byte[] getPayloadAlternative() {
260 if (sizeBytes == 2) {
261 return new byte[] { (byte) 0xff, (byte) 0xff, code, 0, (byte) (sizeBytes + 2),
262 (byte) ((code + sizeBytes + 2) % 0xff) };
265 return new byte[] { (byte) 0xff, (byte) 0xff, code, size, (byte) ((code + size) % 0xff) };
268 public boolean isHeaderValid(byte[] data) {
269 if (data.length < 4 + sizeBytes) {
272 return data[0] == (byte) 0xff && data[1] == (byte) 0xff && data[2] == code;
275 public boolean isResponseValid(byte[] data) {
276 return isHeaderValid(data) && Utils.validateChecksum(data, sizeBytes);
279 public int getSizeBytes() {