]> git.basschouten.com Git - openhab-addons.git/blob
649b071d6833a725425226cd7636a896f563f539
[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;
14
15 import java.security.InvalidParameterException;
16
17 /**
18  *
19  * @author Daniel Weber - Initial contribution
20  */
21 public class Response extends BasePacket {
22
23     public enum ResponseType {
24         RET_OK((byte) 0x00),
25         RET_ERROR((byte) 0x01),
26         RET_NOT_SUPPORTED((byte) 0x02),
27         RET_WRONG_PARAM((byte) 0x03),
28         RET_OPERATION_DENIED((byte) 0x04),
29         RET_LOCK_SET((byte) 0x05),
30         RET_BUFFER_TO_SMALL((byte) 0x06),
31         RET_NO_FREE_BUFFER((byte) 0x07),
32         RET_FLASH_HW_ERROR((byte) 0x82),
33         RET_BASEID_OUT_OF_RANGE((byte) 0x90),
34         RET_BASEID_MAX_REACHED((byte) 0x91);
35
36         private byte value;
37
38         ResponseType(byte value) {
39             this.value = value;
40         }
41
42         public byte getValue() {
43             return this.value;
44         }
45
46         public static ResponseType getResponsetype(byte value) {
47             for (ResponseType t : ResponseType.values()) {
48                 if (t.value == value) {
49                     return t;
50                 }
51             }
52
53             throw new InvalidParameterException("Unknown response type");
54         }
55     }
56
57     protected ResponseType responseType;
58     protected boolean _isValid = false;
59
60     public Response(int dataLength, int optionalDataLength, byte[] payload) {
61         super(dataLength, optionalDataLength, ESPPacketType.RESPONSE, payload);
62
63         try {
64             responseType = ResponseType.getResponsetype(payload[0]);
65         } catch (Exception e) {
66             responseType = ResponseType.RET_ERROR;
67         }
68     }
69
70     public ResponseType getResponseType() {
71         return responseType;
72     }
73
74     public boolean isOK() {
75         return responseType == ResponseType.RET_OK;
76     }
77
78     public boolean isValid() {
79         return _isValid;
80     }
81 }