source: xplra/src/plugin/src/xplra/Protocol.h@ 113:14139defbd04

Last change on this file since 113:14139defbd04 was 113:14139defbd04, checked in by István Váradi <ivaradi@…>, 17 months ago

Set the plugin version to 30

File size: 8.1 KB
Line 
1// Copyright (c) 2013 by István Váradi
2
3// This file is part of XPLRA, a remote-access plugin for X-Plane
4
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7
8// 1. Redistributions of source code must retain the above copyright notice, this
9// list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25// The views and conclusions contained in the software and documentation are those
26// of the authors and should not be interpreted as representing official policies,
27// either expressed or implied, of the FreeBSD Project.
28
29#ifndef XPLRA_PROTOCOL_H
30#define XPLRA_PROTOCOL_H
31//------------------------------------------------------------------------------
32
33#include <cstdlib>
34#include <inttypes.h>
35
36//------------------------------------------------------------------------------
37
38namespace xplra {
39
40//------------------------------------------------------------------------------
41
42/**
43 * Constants and helpers for the protocol.
44 */
45class Protocol
46{
47public:
48 /**
49 * Command: get the value of a single dataref.
50 */
51 static const uint8_t COMMAND_GET_SINGLE = 0x01;
52
53 /**
54 * Command: set the value of a single dataref.
55 */
56 static const uint8_t COMMAND_SET_SINGLE = 0x02;
57
58 /**
59 * Command: get the value of a multiple datarefs.
60 */
61 static const uint8_t COMMAND_GET_MULTI = 0x03;
62
63 /**
64 * Command: set the value of a multiple datarefs.
65 */
66 static const uint8_t COMMAND_SET_MULTI = 0x04;
67
68 /**
69 * Command: register a multiple-data query request
70 */
71 static const uint8_t COMMAND_REGISTER_GET_MULTI = 0x11;
72
73 /**
74 * Command: unregister a multiple-data query request
75 */
76 static const uint8_t COMMAND_UNREGISTER_GET_MULTI = 0x12;
77
78 /**
79 * Command: execute a registered multiple-data query request
80 */
81 static const uint8_t COMMAND_EXECUTE_GET_MULTI = 0x13;
82
83 /**
84 * Command: register a multiple-data update request
85 */
86 static const uint8_t COMMAND_REGISTER_SET_MULTI = 0x21;
87
88 /**
89 * Command: unregister a multiple-data update request
90 */
91 static const uint8_t COMMAND_UNREGISTER_SET_MULTI = 0x22;
92
93 /**
94 * Command: execute a registered multiple-data update request
95 */
96 static const uint8_t COMMAND_EXECUTE_SET_MULTI = 0x23;
97
98 /**
99 * Command: get the versions of the simulator
100 */
101 static const uint8_t COMMAND_GET_VERSIONS = 0x31;
102
103 /**
104 * Command: reload the plugins
105 */
106 static const uint8_t COMMAND_RELOAD_PLUGINS = 0x32;
107
108 /**
109 * Command: save the current situation.
110 *
111 * Followed by a string containing the path of the file to save
112 * relative to the X-System directory.
113 */
114 static const uint8_t COMMAND_SAVE_SITUATION = 0x33;
115
116 /**
117 * Command: show a message in the message window.
118 */
119 static const uint8_t COMMAND_SHOW_MESSAGE = 0x41;
120
121 /**
122 * Command: register a set of hotkeys for the client. Old hotkeys,
123 * if any, are forgotten.
124 *
125 * The command is followed by the following data:
126 * - The number of the hotkeys defined (U32).
127 * - The code of the hotkeys (U16*number of the hotkeys).
128 * The lower byte is the same as the X-Plane virtual key code
129 * (the same as the ASCII code for numbers and upper-case letters),
130 * the upper one is a logical OR of the HOTKEY_MODIFIER_XXX
131 * codes.
132 *
133 * The reply consists of a result code only. It may fail with an
134 * invalid length code if the number of hotkeys is too large.
135 */
136 static const uint8_t COMMAND_REGISTER_HOTKEYS = 0x51;
137
138 /**
139 * Command: query the hotkeys.
140 *
141 * The reply consists of a result code, followed by the following
142 * data, if the result code is RESULT_OK:
143 * - The number of hotkeys defined (U32).
144 * - An array of U8 values each being 0 or 1 depending on whether
145 * the corresponding hotkey has been pressed since the last
146 * query (or the registration, whichever is later). The value at
147 * index i corresponds to the hotkey code at index i in the
148 * array passed with COMMAND_REGISTER_HOTKEYS.
149 *
150 * If not hotkey has been registered, the number of hotkeys is
151 * returned as 0.
152 */
153 static const uint8_t COMMAND_QUERY_HOTKEYS = 0x52;
154
155 /**
156 * Command: unregister the previously registered hotkeys.
157 *
158 * The reply is a result code.
159 */
160 static const uint8_t COMMAND_UNREGISTER_HOTKEYS = 0x53;
161
162 /**
163 * Data type: int
164 */
165 static const uint8_t TYPE_INT = 0x01;
166
167 /**
168 * Data type: float
169 */
170 static const uint8_t TYPE_FLOAT = 0x02;
171
172 /**
173 * Data type: double
174 */
175 static const uint8_t TYPE_DOUBLE = 0x03;
176
177 /**
178 * Data type: float array
179 */
180 static const uint8_t TYPE_FLOAT_ARRAY = 0x11;
181
182 /**
183 * Data type: int array
184 */
185 static const uint8_t TYPE_INT_ARRAY = 0x12;
186
187 /**
188 * Data type: byte array
189 */
190 static const uint8_t TYPE_BYTE_ARRAY = 0x13;
191
192 /**
193 * Result code: no error, everything is OK.
194 */
195 static const uint8_t RESULT_OK = 0x00;
196
197 /**
198 * Result code: invalid command
199 */
200 static const uint8_t RESULT_INVALID_COMMAND = 0x01;
201
202 /**
203 * Result code: unknown dataref
204 */
205 static const uint8_t RESULT_UNKNOWN_DATAREF = 0x02;
206
207 /**
208 * Result code: invalid type
209 */
210 static const uint8_t RESULT_INVALID_TYPE = 0x03;
211
212 /**
213 * Result code: invalid length
214 */
215 static const uint8_t RESULT_INVALID_LENGTH = 0x04;
216
217 /**
218 * Result code: invalid offset
219 */
220 static const uint8_t RESULT_INVALID_OFFSET = 0x05;
221
222 /**
223 * Result code: invalid count
224 */
225 static const uint8_t RESULT_INVALID_COUNT = 0x06;
226
227 /**
228 * Result code: invalid ID
229 */
230 static const uint8_t RESULT_INVALID_ID = 0x07;
231
232 /**
233 * Result code: invalid duration
234 */
235 static const uint8_t RESULT_INVALID_DURATION = 0x08;
236
237 /**
238 * Result code: other error
239 */
240 static const uint8_t RESULT_OTHER_ERROR = 0xff;
241
242 /**
243 * Hotkey modifier: shift
244 */
245 static const uint16_t HOTKEY_MODIFIER_SHIFT = 0x0100;
246
247 /**
248 * Hotkey modifier: control
249 */
250 static const uint16_t HOTKEY_MODIFIER_CONTROL = 0x0200;
251
252 /**
253 * The maximal length we accept (in order to protect ourselves).
254 */
255 static const int MAX_LENGTH = 2048;
256
257 /**
258 * The maximal count of requests in a multiple-data query or
259 * update.
260 */
261 static const size_t MAX_MULTI_COUNT = 1024;
262
263 /**
264 * The maximal message duration
265 */
266 static constexpr float MAX_MESSAGE_DURATION = 5*60;
267
268 /**
269 * The maximal number of hotkeys that can be registered for a
270 * client.
271 */
272 static const size_t MAX_HOTKEY_COUNT = 128;
273
274 /**
275 * The version of the plugin.
276 */
277 static const int version = 30;
278};
279
280//------------------------------------------------------------------------------
281
282} /* namespace xplra */
283
284//------------------------------------------------------------------------------
285#endif // XPLRA_PROTOCOL_H
286
287// Local Variables:
288// mode: C++
289// c-basic-offset: 4
290// indent-tabs-mode: nil
291// End:
Note: See TracBrowser for help on using the repository browser.