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.enocean.internal.messages.responses;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.enocean.internal.Helper;
19 import org.openhab.binding.enocean.internal.messages.Response;
23 * @author Daniel Weber - Initial contribution
26 public class RDLearnedClientsResponse extends Response {
28 public class LearnedClient {
29 public byte[] clientId = new byte[0];
30 public byte[] controllerId = new byte[0];
31 public int mailboxIndex;
34 LearnedClient[] learnedClients = new LearnedClient[0];
36 public RDLearnedClientsResponse(Response response) {
37 this(response.getPayload().length, response.getOptionalPayload().length,
38 Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
41 RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) {
42 super(dataLength, optionalDataLength, payload);
44 if (payload.length == 0 || (payload.length - 1) % 9 != 0) {
50 learnedClients = new LearnedClient[(payload.length - 1) / 9];
51 for (int i = 0; i < learnedClients.length; i++) {
52 LearnedClient client = new LearnedClient();
53 client.clientId = Arrays.copyOfRange(payload, 1 + i * 9, 1 + i * 9 + 4);
54 client.controllerId = Arrays.copyOfRange(payload, 5 + i * 9, 5 + i * 9 + 4);
55 client.mailboxIndex = payload[9 + i * 9] & 0xFF;
56 learnedClients[i] = client;
60 public LearnedClient[] getLearnedClients() {
61 return learnedClients;