]> git.basschouten.com Git - openhab-addons.git/blob
12626c8c8023ef662218cc6589e35d3c804e25fc
[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.loxone.internal.types;
14
15 /**
16  * A header of a binary message received from Loxone Miniserver on a websocket connection.
17  *
18  * @author Pawel Pieczul - initial contribution
19  *
20  */
21 public class LxWsBinaryHeader {
22     /**
23      * Type of a binary message received from the Miniserver
24      *
25      * @author Pawel Pieczul
26      *
27      */
28     public enum LxWsMessageType {
29         /**
30          * Text message - jetty websocket client will pass it on automatically to a callback
31          */
32         TEXT_MESSAGE,
33         /**
34          * Binary file
35          */
36         BINARY_FILE,
37         /**
38          * A set of value states for controls that changed their state
39          */
40         EVENT_TABLE_OF_VALUE_STATES,
41         /**
42          * A set of text states for controls that changed their state
43          */
44         EVENT_TABLE_OF_TEXT_STATES,
45         EVENT_TABLE_OF_DAYTIMER_STATES,
46         OUT_OF_SERVICE_INDICATOR,
47         /**
48          * Response to keepalive request message
49          */
50         KEEPALIVE_RESPONSE,
51         EVENT_TABLE_OF_WEATHER_STATES,
52         /**
53          * Unknown header
54          */
55         UNKNOWN
56     }
57
58     private LxWsMessageType type = LxWsMessageType.UNKNOWN;
59
60     /**
61      * Create header from binary buffer at a given offset
62      *
63      * @param buffer buffer with received message
64      * @param offset offset in bytes at which header is expected
65      */
66     public LxWsBinaryHeader(byte[] buffer, int offset) throws IndexOutOfBoundsException {
67         if (buffer[offset] != 0x03) {
68             return;
69         }
70         switch (buffer[offset + 1]) {
71             case 0:
72                 type = LxWsMessageType.TEXT_MESSAGE;
73                 break;
74             case 1:
75                 type = LxWsMessageType.BINARY_FILE;
76                 break;
77             case 2:
78                 type = LxWsMessageType.EVENT_TABLE_OF_VALUE_STATES;
79                 break;
80             case 3:
81                 type = LxWsMessageType.EVENT_TABLE_OF_TEXT_STATES;
82                 break;
83             case 4:
84                 type = LxWsMessageType.EVENT_TABLE_OF_DAYTIMER_STATES;
85                 break;
86             case 5:
87                 type = LxWsMessageType.OUT_OF_SERVICE_INDICATOR;
88                 break;
89             case 6:
90                 type = LxWsMessageType.KEEPALIVE_RESPONSE;
91                 break;
92             case 7:
93                 type = LxWsMessageType.EVENT_TABLE_OF_WEATHER_STATES;
94                 break;
95             default:
96                 type = LxWsMessageType.UNKNOWN;
97                 break;
98         }
99         // These fields are not used today , but left it for future reference
100         // estimated = ((buffer[offset + 2] & 0x01) != 0);
101         // length = ByteBuffer.wrap(buffer, offset + 3, 4).getInt();
102     }
103
104     public LxWsMessageType getType() {
105         return type;
106     }
107 }