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.homematic.internal.discovery.eq3udp;
16 * Extracts a UDP response from a Homematic CCU gateway.
18 * @author Gerhard Riegler - Initial contribution
21 public class Eq3UdpResponse {
23 private String deviceTypeId;
24 private String serialNumber;
27 * Extracts the received UDP response.
29 public Eq3UdpResponse(byte[] buffer) throws IndexOutOfBoundsException {
31 byte protocolVersion = buffer[(index++)];
32 if (protocolVersion == 2) {
33 senderId = readInt(buffer, index, 3);
36 deviceTypeId = readString(buffer, index++);
37 index += deviceTypeId.length();
38 serialNumber = readString(buffer, index);
42 * Returns the device type of the gateway.
44 public String getDeviceTypeId() {
49 * Returns the serial number of the gateway.
51 public String getSerialNumber() {
56 * Returns true, if this response is from a Homematic CCU gateway.
58 public boolean isValid() {
59 return this.senderId == Eq3UdpRequest.getSenderId()
60 && (deviceTypeId.startsWith("eQ3-HM-CCU") || deviceTypeId.startsWith("eQ3-HmIP-CCU3"))
61 && !serialNumber.contains(Eq3UdpRequest.getEq3SerialNumber());
64 private String readString(byte[] data, int index) throws IndexOutOfBoundsException {
66 for (int i = index; i < data.length; i++) {
70 result += (char) data[i];
75 private int readInt(byte[] data, int index, int length) throws IndexOutOfBoundsException {
77 for (int n = index; n < index + length; n++) {
79 result |= data[n] & 0xFF;
85 public String toString() {
86 return String.format("%s[deviceTypeId=%s,serialNumber=%s]", getClass().getSimpleName(), deviceTypeId,