]> git.basschouten.com Git - openhab-addons.git/blob
8c8671a65bc44db8b3a9c77204acd7a987173c71
[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.openhab.binding.enocean.internal.Helper;
18 import org.openhab.binding.enocean.internal.messages.Response;
19
20 /**
21  *
22  * @author Daniel Weber - Initial contribution
23  */
24 public class RDLearnedClientsResponse extends Response {
25
26     public class LearnedClient {
27         public byte[] clientId;
28         public byte[] controllerId;
29         public int mailboxIndex;
30     }
31
32     LearnedClient[] learnedClients;
33
34     public RDLearnedClientsResponse(Response response) {
35         this(response.getPayload().length, response.getOptionalPayload().length,
36                 Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
37     }
38
39     RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) {
40         super(dataLength, optionalDataLength, payload);
41
42         if (payload == null || ((payload.length - 1) % 9) != 0) {
43             return;
44         } else {
45             _isValid = true;
46         }
47
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;
55         }
56     }
57
58     public LearnedClient[] getLearnedClients() {
59         return learnedClients;
60     }
61 }