]> git.basschouten.com Git - openhab-addons.git/blob
e041586aaf3fb9fdd6cb35b343c9b4df5da5ccef
[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.messages.Response;
19 import org.openhab.core.util.HexUtils;
20
21 /**
22  *
23  * @author Daniel Weber - Initial contribution
24  */
25 @NonNullByDefault
26 public class RDVersionResponse extends Response {
27
28     protected String appVersion = "";
29     protected String apiVersion = "";
30     protected String chipId = "";
31     protected String description = "";
32
33     public RDVersionResponse(Response response) {
34         this(response.getPayload().length, 0, response.getPayload());
35     }
36
37     RDVersionResponse(int dataLength, int optionalDataLength, byte[] payload) {
38         super(dataLength, optionalDataLength, payload);
39
40         if (payload.length < 33) {
41             return;
42         }
43
44         try {
45             appVersion = String.format("%d.%d.%d.%d", payload[1] & 0xff, payload[2] & 0xff, payload[3] & 0xff,
46                     payload[4] & 0xff);
47             apiVersion = String.format("%d.%d.%d.%d", payload[5] & 0xff, payload[6] & 0xff, payload[7] & 0xff,
48                     payload[8] & 0xff);
49
50             chipId = HexUtils.bytesToHex(Arrays.copyOfRange(payload, 9, 13));
51
52             StringBuffer sb = new StringBuffer();
53             for (int i = 17; i < payload.length; i++) {
54                 sb.append((char) (payload[i] & 0xff));
55             }
56             description = sb.toString();
57             isValid = true;
58
59         } catch (Exception e) {
60             responseType = ResponseType.RET_ERROR;
61         }
62     }
63
64     public String getAPPVersion() {
65         return appVersion;
66     }
67
68     public String getAPIVersion() {
69         return apiVersion;
70     }
71
72     public String getChipID() {
73         return chipId;
74     }
75
76     public String getDescription() {
77         return description;
78     }
79 }