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.bluetooth.govee.internal.command.hygrometer;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.bluetooth.gattserial.GattMessage;
20 * @author Connor Petty - Initial contribution
24 public class GoveeMessage implements GattMessage {
26 private byte[] payload;
28 public GoveeMessage(byte[] payload) {
29 this.payload = payload;
32 public GoveeMessage(byte commandType, byte commandCode, byte @Nullable [] data) {
33 payload = new byte[20];
34 payload[0] = commandType;
35 payload[1] = commandCode;
37 System.arraycopy(data, 0, payload, 2, data.length);
39 payload[19] = calculateCrc(payload, 19);
42 public byte getCommandType() {
46 public byte getCommandCode() {
50 protected static byte calculateCrc(byte[] bArr, int i) {
52 for (int i2 = 1; i2 < i; i2++) {
53 b = (byte) (b ^ bArr[i2]);
58 public byte @Nullable [] getData() {
59 byte[] data = new byte[17];
60 System.arraycopy(payload, 2, data, 0, Math.min(payload.length - 2, 17));
65 public byte[] getPayload() {