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.openhab.binding.enocean.internal.Helper;
18 import org.openhab.binding.enocean.internal.messages.Response;
22 * @author Daniel Weber - Initial contribution
24 public class RDLearnedClientsResponse extends Response {
26 public class LearnedClient {
27 public byte[] clientId;
28 public byte[] controllerId;
29 public int mailboxIndex;
32 LearnedClient[] learnedClients;
34 public RDLearnedClientsResponse(Response response) {
35 this(response.getPayload().length, response.getOptionalPayload().length,
36 Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
39 RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) {
40 super(dataLength, optionalDataLength, payload);
42 if (payload == null || ((payload.length - 1) % 9) != 0) {
48 learnedClients = new LearnedClient[(payload.length - 1) / 9];
49 for (int i = 0; i < learnedClients.length; i++) {
50 LearnedClient client = new LearnedClient();
51 client.clientId = Arrays.copyOfRange(payload, 1 + i * 9, 1 + i * 9 + 4);
52 client.controllerId = Arrays.copyOfRange(payload, 5 + i * 9, 5 + i * 9 + 4);
53 client.mailboxIndex = payload[9 + i * 9] & 0xFF;
54 learnedClients[i] = client;
58 public LearnedClient[] getLearnedClients() {
59 return learnedClients;