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