The open source OpenXR runtime
at main 190 lines 3.8 kB view raw
1// Copyright 2020-2023, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Interface to remote driver. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @ingroup drv_remote 8 */ 9 10#pragma once 11 12// winsock2.h must be included before windows.h, or the winsock interface will be 13// defined instead of the winsock2 interface. 14// Given that some of the Monado headers could include windows.h, winsock2 is to be 15// included before anything else. 16// As a consequence, this header must also be the first included in the file using 17// it. 18#include "xrt/xrt_config_os.h" 19#ifdef XRT_OS_WINDOWS 20#include <winsock2.h> // For SOCKET 21#endif 22 23#include "xrt/xrt_defines.h" 24#include "util/u_logging.h" 25 26#ifdef __cplusplus 27extern "C" { 28#endif 29 30 31struct xrt_system_devices; 32struct xrt_space_overseer; 33struct xrt_session_event_sink; 34 35/*! 36 * @defgroup drv_remote Remote debugging driver 37 * @ingroup drv 38 * 39 * @brief Driver for creating remote debugging devices. 40 */ 41 42/*! 43 * @dir drivers/remote 44 * 45 * @brief @ref drv_remote files. 46 */ 47 48#ifdef XRT_OS_WINDOWS 49/*! 50 * The type for a socket descriptor 51 * 52 * On Windows, this is a SOCKET. 53 */ 54typedef SOCKET r_socket_t; 55#else 56/*! 57 * The type for a socket descriptor 58 * 59 * On non-Windows, this is a file descriptor. 60 */ 61typedef int r_socket_t; 62#endif 63 64/*! 65 * Header value to be set in the packet. 66 * 67 * @ingroup drv_remote 68 */ 69#define R_HEADER_VALUE (*(uint64_t *)"mndrmt3\0") 70 71/*! 72 * Data per controller. 73 */ 74struct r_remote_controller_data 75{ 76 struct xrt_pose pose; 77 struct xrt_vec3 linear_velocity; 78 struct xrt_vec3 angular_velocity; 79 80 float hand_curl[5]; 81 82 struct xrt_vec1 trigger_value; 83 struct xrt_vec1 squeeze_value; 84 struct xrt_vec1 squeeze_force; 85 struct xrt_vec2 thumbstick; 86 struct xrt_vec1 trackpad_force; 87 struct xrt_vec2 trackpad; 88 89 bool hand_tracking_active; 90 bool active; 91 92 bool system_click; 93 bool system_touch; 94 bool a_click; 95 bool a_touch; 96 bool b_click; 97 bool b_touch; 98 bool trigger_click; 99 bool trigger_touch; 100 bool thumbstick_click; 101 bool thumbstick_touch; 102 bool trackpad_touch; 103 bool _pad0; 104 bool _pad1; 105 bool _pad2; 106 // active(2) + bools(11) + pad(3) = 16 107}; 108 109struct r_head_data 110{ 111 struct 112 { 113 //! The field of view values of this view. 114 struct xrt_fov fov; 115 116 //! The pose of this view relative to @ref r_head_data::center. 117 struct xrt_pose pose; 118 119 //! Padded to fov(16) + pose(16 + 12) + 4 = 48 120 uint32_t _pad; 121 } views[2]; 122 123 //! The center of the head, in OpenXR terms the view space. 124 struct xrt_pose center; 125 126 //! Is the per view data valid and should be used? 127 bool per_view_data_valid; 128 129 //! pose(16 + 12) bool(1) + pad(3) = 32. 130 bool _pad0, _pad1, _pad2; 131}; 132 133/*! 134 * Remote data sent from the debugger to the hub. 135 * 136 * @ingroup drv_remote 137 */ 138struct r_remote_data 139{ 140 uint64_t header; 141 142 struct r_head_data head; 143 144 struct r_remote_controller_data left, right; 145}; 146 147/*! 148 * Shared connection. 149 * 150 * @ingroup drv_remote 151 */ 152struct r_remote_connection 153{ 154 //! Logging level to be used. 155 enum u_logging_level log_level; 156 157 //! Socket. 158 r_socket_t fd; 159}; 160 161/*! 162 * Creates the remote system devices. 163 * 164 * @ingroup drv_remote 165 */ 166xrt_result_t 167r_create_devices(uint16_t port, 168 uint32_t view_count, 169 struct xrt_session_event_sink *broadcast, 170 struct xrt_system_devices **out_xsysd, 171 struct xrt_space_overseer **out_xso); 172 173/*! 174 * Initializes and connects the connection. 175 * 176 * @ingroup drv_remote 177 */ 178r_socket_t 179r_remote_connection_init(struct r_remote_connection *rc, const char *addr, uint16_t port); 180 181int 182r_remote_connection_read_one(struct r_remote_connection *rc, struct r_remote_data *data); 183 184int 185r_remote_connection_write_one(struct r_remote_connection *rc, const struct r_remote_data *data); 186 187 188#ifdef __cplusplus 189} 190#endif