]> git.basschouten.com Git - openhab-addons.git/blob
6bf9de5ed16036132d28226a219a38a85bc1535b
[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.onewire.internal.owserver;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link OwserverMessageType} provides the owserver protocol message type
19  *
20  * @author Jan N. Klug - Initial contribution
21  */
22
23 @NonNullByDefault
24 public enum OwserverMessageType {
25     ERROR(0x00000000),
26     NOP(0x00000001),
27     READ(0x00000002),
28     WRITE(0x00000003),
29     DIR(0x00000004),
30     SIZE(0x00000005),
31     PRESENT(0x00000006),
32     DIRALL(0x00000007),
33     GET(0x00000008),
34     DIRALLSLASH(0x00000009),
35     GETSLASH(0x0000000a);
36
37     private final int messageType;
38
39     OwserverMessageType(int messageType) {
40         this.messageType = messageType;
41     }
42
43     /**
44      * get the this message type's numeric representation
45      *
46      * @return integer value of this message type
47      */
48     public int getValue() {
49         return messageType;
50     }
51
52     /**
53      * return a new OwMessageType from an integer
54      *
55      * @param messageType the message type as integer
56      * @return OwMessageType
57      */
58     public static OwserverMessageType fromInt(int messageType) throws IllegalArgumentException {
59         for (OwserverMessageType value : values()) {
60             if (value.getValue() == messageType) {
61                 return value;
62             }
63         }
64         throw new IllegalArgumentException();
65     }
66 }