]> git.basschouten.com Git - openhab-addons.git/blob
6c114878e81e21804e709efc6d205f38f01ff20d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.enocean.internal.messages.responses;
14
15 import java.util.Arrays;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.enocean.internal.Helper;
19 import org.openhab.binding.enocean.internal.messages.Response;
20
21 /**
22  *
23  * @author Daniel Weber - Initial contribution
24  */
25 @NonNullByDefault
26 public class RDLearnedClientsResponse extends Response {
27
28     public class LearnedClient {
29         public byte[] clientId = new byte[0];
30         public byte[] controllerId = new byte[0];
31         public int mailboxIndex;
32     }
33
34     LearnedClient[] learnedClients = new LearnedClient[0];
35
36     public RDLearnedClientsResponse(Response response) {
37         this(response.getPayload().length, response.getOptionalPayload().length,
38                 Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
39     }
40
41     RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) {
42         super(dataLength, optionalDataLength, payload);
43
44         if (payload.length == 0 || (payload.length - 1) % 9 != 0) {
45             return;
46         } else {
47             isValid = true;
48         }
49
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;
57         }
58     }
59
60     public LearnedClient[] getLearnedClients() {
61         return learnedClients;
62     }
63 }