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