summaryrefslogtreecommitdiff
path: root/src/input_common/udp/protocol.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/udp/protocol.h101
1 files changed, 54 insertions, 47 deletions
diff --git a/src/input_common/udp/protocol.h b/src/input_common/udp/protocol.h
index d31bbeb89..1b521860a 100644
--- a/src/input_common/udp/protocol.h
+++ b/src/input_common/udp/protocol.h
@@ -26,15 +26,15 @@ enum class Type : u32 {
26}; 26};
27 27
28struct Header { 28struct Header {
29 u32_le magic; 29 u32_le magic{};
30 u16_le protocol_version; 30 u16_le protocol_version{};
31 u16_le payload_length; 31 u16_le payload_length{};
32 u32_le crc; 32 u32_le crc{};
33 u32_le id; 33 u32_le id{};
34 ///> In the protocol, the type of the packet is not part of the header, but its convenient to 34 ///> In the protocol, the type of the packet is not part of the header, but its convenient to
35 ///> include in the header so the callee doesn't have to duplicate the type twice when building 35 ///> include in the header so the callee doesn't have to duplicate the type twice when building
36 ///> the data 36 ///> the data
37 Type type; 37 Type type{};
38}; 38};
39static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size"); 39static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size");
40static_assert(std::is_trivially_copyable_v<Header>, "UDP Message Header is not trivially copyable"); 40static_assert(std::is_trivially_copyable_v<Header>, "UDP Message Header is not trivially copyable");
@@ -45,7 +45,7 @@ constexpr MacAddress EMPTY_MAC_ADDRESS = {0, 0, 0, 0, 0, 0};
45#pragma pack(push, 1) 45#pragma pack(push, 1)
46template <typename T> 46template <typename T>
47struct Message { 47struct Message {
48 Header header; 48 Header header{};
49 T data; 49 T data;
50}; 50};
51#pragma pack(pop) 51#pragma pack(pop)
@@ -64,7 +64,7 @@ struct Version {};
64 */ 64 */
65constexpr u32 MAX_PORTS = 4; 65constexpr u32 MAX_PORTS = 4;
66struct PortInfo { 66struct PortInfo {
67 u32_le pad_count; ///> Number of ports to request data for 67 u32_le pad_count{}; ///> Number of ports to request data for
68 std::array<u8, MAX_PORTS> port; 68 std::array<u8, MAX_PORTS> port;
69}; 69};
70static_assert(std::is_trivially_copyable_v<PortInfo>, 70static_assert(std::is_trivially_copyable_v<PortInfo>,
@@ -82,9 +82,9 @@ struct PadData {
82 Mac, 82 Mac,
83 }; 83 };
84 /// Determines which method will be used as a look up for the controller 84 /// Determines which method will be used as a look up for the controller
85 Flags flags; 85 Flags flags{};
86 /// Index of the port of the controller to retrieve data about 86 /// Index of the port of the controller to retrieve data about
87 u8 port_id; 87 u8 port_id{};
88 /// Mac address of the controller to retrieve data about 88 /// Mac address of the controller to retrieve data about
89 MacAddress mac; 89 MacAddress mac;
90}; 90};
@@ -113,20 +113,20 @@ Message<T> Create(const T data, const u32 client_id = 0) {
113namespace Response { 113namespace Response {
114 114
115struct Version { 115struct Version {
116 u16_le version; 116 u16_le version{};
117}; 117};
118static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size"); 118static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size");
119static_assert(std::is_trivially_copyable_v<Version>, 119static_assert(std::is_trivially_copyable_v<Version>,
120 "UDP Response Version is not trivially copyable"); 120 "UDP Response Version is not trivially copyable");
121 121
122struct PortInfo { 122struct PortInfo {
123 u8 id; 123 u8 id{};
124 u8 state; 124 u8 state{};
125 u8 model; 125 u8 model{};
126 u8 connection_type; 126 u8 connection_type{};
127 MacAddress mac; 127 MacAddress mac;
128 u8 battery; 128 u8 battery{};
129 u8 is_pad_active; 129 u8 is_pad_active{};
130}; 130};
131static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size"); 131static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size");
132static_assert(std::is_trivially_copyable_v<PortInfo>, 132static_assert(std::is_trivially_copyable_v<PortInfo>,
@@ -134,10 +134,10 @@ static_assert(std::is_trivially_copyable_v<PortInfo>,
134 134
135#pragma pack(push, 1) 135#pragma pack(push, 1)
136struct PadData { 136struct PadData {
137 PortInfo info; 137 PortInfo info{};
138 u32_le packet_counter; 138 u32_le packet_counter{};
139 139
140 u16_le digital_button; 140 u16_le digital_button{};
141 // The following union isn't trivially copyable but we don't use this input anyway. 141 // The following union isn't trivially copyable but we don't use this input anyway.
142 // union DigitalButton { 142 // union DigitalButton {
143 // u16_le button; 143 // u16_le button;
@@ -161,46 +161,46 @@ struct PadData {
161 161
162 u8 home; 162 u8 home;
163 /// If the device supports a "click" on the touchpad, this will change to 1 when a click happens 163 /// If the device supports a "click" on the touchpad, this will change to 1 when a click happens
164 u8 touch_hard_press; 164 u8 touch_hard_press{};
165 u8 left_stick_x; 165 u8 left_stick_x{};
166 u8 left_stick_y; 166 u8 left_stick_y{};
167 u8 right_stick_x; 167 u8 right_stick_x{};
168 u8 right_stick_y; 168 u8 right_stick_y{};
169 169
170 struct AnalogButton { 170 struct AnalogButton {
171 u8 button_8; 171 u8 button_8{};
172 u8 button_7; 172 u8 button_7{};
173 u8 button_6; 173 u8 button_6{};
174 u8 button_5; 174 u8 button_5{};
175 u8 button_12; 175 u8 button_12{};
176 u8 button_11; 176 u8 button_11{};
177 u8 button_10; 177 u8 button_10{};
178 u8 button_9; 178 u8 button_9{};
179 u8 button_16; 179 u8 button_16{};
180 u8 button_15; 180 u8 button_15{};
181 u8 button_14; 181 u8 button_14{};
182 u8 button_13; 182 u8 button_13{};
183 } analog_button; 183 } analog_button;
184 184
185 struct TouchPad { 185 struct TouchPad {
186 u8 is_active; 186 u8 is_active{};
187 u8 id; 187 u8 id{};
188 u16_le x; 188 u16_le x{};
189 u16_le y; 189 u16_le y{};
190 } touch_1, touch_2; 190 } touch_1, touch_2;
191 191
192 u64_le motion_timestamp; 192 u64_le motion_timestamp;
193 193
194 struct Accelerometer { 194 struct Accelerometer {
195 float x; 195 float x{};
196 float y; 196 float y{};
197 float z; 197 float z{};
198 } accel; 198 } accel;
199 199
200 struct Gyroscope { 200 struct Gyroscope {
201 float pitch; 201 float pitch{};
202 float yaw; 202 float yaw{};
203 float roll; 203 float roll{};
204 } gyro; 204 } gyro;
205}; 205};
206#pragma pack(pop) 206#pragma pack(pop)
@@ -212,6 +212,13 @@ static_assert(std::is_trivially_copyable_v<PadData>,
212static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE, 212static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE,
213 "UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>"); 213 "UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>");
214 214
215static_assert(sizeof(PadData::AnalogButton) == 12,
216 "UDP Response AnalogButton struct has wrong size ");
217static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size ");
218static_assert(sizeof(PadData::Accelerometer) == 12,
219 "UDP Response Accelerometer struct has wrong size ");
220static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size ");
221
215/** 222/**
216 * Create a Response Message from the data 223 * Create a Response Message from the data
217 * @param data array of bytes sent from the server 224 * @param data array of bytes sent from the server