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;
15 import java.io.ByteArrayOutputStream;
16 import java.io.IOException;
17 import java.util.Random;
20 * Generates a UDP request to discover Homematic CCU gateways.
22 * @author Gerhard Riegler - Initial contribution
25 public class Eq3UdpRequest {
26 private static final byte UDP_IDENTIFY = 73;
27 private static final byte UDP_SEPARATOR = 0;
29 private static final int senderId = new Random().nextInt() & 0xFFFFFF;
30 private static final String EQ3_DEVICE_TYPE = "eQ3-*";
31 private static final String EQ3_SERIAL_NUMBER = "*";
34 * Returns the Eq3 Serialnumber.
36 public static String getEq3SerialNumber() {
37 return EQ3_SERIAL_NUMBER;
41 * Returns the sender id.
43 public static int getSenderId() {
48 * Creates the UDP request.
50 public byte[] getBytes() throws IOException {
51 ByteArrayOutputStream baos = new ByteArrayOutputStream();
53 for (int i = 2; i >= 0; i--) {
54 byte temp = (byte) (senderId >> i * 8 & 0xFF);
57 baos.write(UDP_SEPARATOR);
58 baos.write(EQ3_DEVICE_TYPE.getBytes());
59 baos.write(UDP_SEPARATOR);
60 baos.write(EQ3_SERIAL_NUMBER.getBytes());
61 baos.write(UDP_SEPARATOR);
62 baos.write(UDP_IDENTIFY);
63 return baos.toByteArray();