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