Monado OpenXR Runtime
wmr_protocol.h
Go to the documentation of this file.
1// Copyright 2018, Philipp Zabel.
2// Copyright 2020-2021, N Madsen.
3// Copyright 2020-2021, Collabora, Ltd.
4// SPDX-License-Identifier: BSL-1.0
5/*!
6 * @file
7 * @brief WMR and MS HoloLens protocol constants, structures and helpers header
8 * @author Philipp Zabel <philipp.zabel@gmail.com>
9 * @author nima01 <nima_zero_one@protonmail.com>
10 * @ingroup drv_wmr
11 */
12
13#pragma once
14
15#include "math/m_vec2.h"
16
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22
23/*!
24 * WMR and MS HoloLens Sensors protocol constants and structures
25 *
26 * @addtogroup drv_wmr
27 * @{
28 */
29
30#define WMR_FEATURE_BUFFER_SIZE 497
31#define WMR_MS_HOLOLENS_NS_PER_TICK 100
32
33// Messages types specific to WMR Hololens Sensors devices
34#define WMR_MS_HOLOLENS_MSG_SENSORS 0x01
35#define WMR_MS_HOLOLENS_MSG_CONTROL 0x02 // Firmware read control responses
36#define WMR_MS_HOLOLENS_MSG_DEBUG 0x03
37#define WMR_MS_HOLOLENS_MSG_BT_IFACE 0x05 /* Bluetooth interface */
38#define WMR_MS_HOLOLENS_MSG_LEFT_CONTROLLER 0x06 /* Left controller */
39#define WMR_MS_HOLOLENS_MSG_RIGHT_CONTROLLER 0x0E /* Right controller */
40#define WMR_MS_HOLOLENS_MSG_BT_CONTROL 0x16 /* BT control message on Reverb G2 & Odyssey+ */
41#define WMR_MS_HOLOLENS_MSG_CONTROLLER_STATUS 0x17
42
43// Messages types specific to WMR Hololens Sensors' companion devices
44#define WMR_CONTROL_MSG_IPD_VALUE 0x01
45#define WMR_CONTROL_MSG_UNKNOWN_02 0x02 // Seen in relation to proximity events on Reverb G1
46#define WMR_CONTROL_MSG_DEVICE_STATUS 0x05 // Seen in relation screen state changes on Reverb G1
47
48// Message sub-types for WMR_MS_HOLOLENS_MSG_BT_IFACE WMR Hololens Sensors message
49#define WMR_BT_IFACE_MSG_DEBUG 0x19
50
51// Controller status codes for WMR_MS_HOLOLENS_MSG_CONTROLLER_STATUS status message
52#define WMR_CONTROLLER_STATUS_UNPAIRED 0x0
53#define WMR_CONTROLLER_STATUS_OFFLINE 0x1
54#define WMR_CONTROLLER_STATUS_ONLINE 0x2
55
56/* Messages we can send the G2 via WMR_MS_HOLOLENS_MSG_BT_CONTROL */
57enum wmr_bt_control_msg
58{
59 WMR_BT_CONTROL_MSG_ONLINE_STATUS = 0x04,
60 WMR_BT_CONTROL_MSG_PAIR = 0x05,
61 WMR_BT_CONTROL_MSG_UNPAIR = 0x06,
62 WMR_BT_CONTROL_MSG_PAIRING_STATUS = 0x08,
63 WMR_BT_CONTROL_MSG_CMD_STATUS = 0x09,
64};
65
66#define STR_TO_U32(s) ((uint32_t)(((s)[0]) | ((s)[1] << 8) | ((s)[2] << 16) | ((s)[3] << 24)))
67#define WMR_MAGIC STR_TO_U32("Dlo+")
68
69#define WMR_MIN_EXPOSURE 60
70#define WMR_MAX_OBSERVED_EXPOSURE 6000
71#define WMR_MAX_EXPOSURE 9000
72#define WMR_MIN_GAIN 16
73#define WMR_MAX_GAIN 255
74
75static const unsigned char hololens_sensors_imu_on[64] = {0x02, 0x07};
76
77
79{
80 uint8_t id;
81 uint16_t temperature[4];
82 uint64_t gyro_timestamp[4];
83 int16_t gyro[3][4 * 8];
84 uint64_t accel_timestamp[4];
85 int32_t accel[3][4];
86 uint64_t video_timestamp[4];
87};
88
90{
91 uint32_t json_start;
92 uint32_t json_size;
93 char manufacturer[0x40];
94 char device[0x40];
95 char serial[0x40];
96 char uid[0x26];
97 char unk[0xd5];
98 char name[0x40];
99 char revision[0x20];
100 char revision_date[0x20];
101};
102
103/*!
104 * @}
105 */
106
107
108/*!
109 * WMR and MS HoloLens Sensors protocol helpers
110 *
111 * @addtogroup drv_wmr
112 * @{
113 */
114
115void
116vec3_from_hololens_accel(int32_t sample[3][4], int i, struct xrt_vec3 *out_vec);
117
118void
119vec3_from_hololens_gyro(int16_t sample[3][32], int i, struct xrt_vec3 *out_vec);
120
121
122static inline uint8_t
123read8(const unsigned char **buffer)
124{
125 uint8_t ret = **buffer;
126 *buffer += 1;
127 return ret;
128}
129
130static inline int16_t
131read16(const unsigned char **buffer)
132{
133 int16_t ret = (*(*buffer + 0) << 0) | //
134 (*(*buffer + 1) << 8);
135 *buffer += 2;
136 return ret;
137}
138
139static inline int32_t
140read24(const unsigned char **buffer)
141{
142 // Note: Preserve sign by shifting up to write MSB
143 int32_t ret = (*(*buffer + 0) << 8) | (*(*buffer + 1) << 16) | (*(*buffer + 2) << 24);
144 *buffer += 3;
145
146 // restore 24 bit scale again
147 return ret >> 8;
148}
149
150static inline int32_t
151read32(const unsigned char **buffer)
152{
153 int32_t ret = (*(*buffer + 0) << 0) | //
154 (*(*buffer + 1) << 8) | //
155 (*(*buffer + 2) << 16) | //
156 (*(*buffer + 3) << 24);
157 *buffer += 4;
158 return ret;
159}
160
161static inline uint64_t
162read64(const unsigned char **buffer)
163{
164 uint64_t ret = ((uint64_t) * (*buffer + 0) << 0) | //
165 ((uint64_t) * (*buffer + 1) << 8) | //
166 ((uint64_t) * (*buffer + 2) << 16) | //
167 ((uint64_t) * (*buffer + 3) << 24) | //
168 ((uint64_t) * (*buffer + 4) << 32) | //
169 ((uint64_t) * (*buffer + 5) << 40) | //
170 ((uint64_t) * (*buffer + 6) << 48) | //
171 ((uint64_t) * (*buffer + 7) << 56);
172 *buffer += 8;
173 return ret;
174}
175
176/*!
177 * @}
178 */
179
180
181#ifdef __cplusplus
182}
183#endif
C vec2 math library.
Definition: wmr_protocol.h:79
Definition: wmr_protocol.h:90
A 3 element vector with single floats.
Definition: xrt_defines.h:271