summaryrefslogtreecommitdiff
path: root/src/input_common/udp/protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/udp/protocol.h')
-rw-r--r--src/input_common/udp/protocol.h32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/input_common/udp/protocol.h b/src/input_common/udp/protocol.h
index 3ba4d1fc8..2b31846db 100644
--- a/src/input_common/udp/protocol.h
+++ b/src/input_common/udp/protocol.h
@@ -35,6 +35,7 @@ struct Header {
35 ///> the data 35 ///> the data
36 Type type{}; 36 Type type{};
37}; 37};
38
38static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size"); 39static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size");
39static_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");
40 41
@@ -54,7 +55,9 @@ constexpr Type GetMessageType();
54 55
55namespace Request { 56namespace Request {
56 57
57struct Version {}; 58struct Version {
59};
60
58/** 61/**
59 * Requests the server to send information about what controllers are plugged into the ports 62 * Requests the server to send information about what controllers are plugged into the ports
60 * In citra's case, we only have one controller, so for simplicity's sake, we can just send a 63 * In citra's case, we only have one controller, so for simplicity's sake, we can just send a
@@ -62,12 +65,14 @@ struct Version {};
62 * nice to make this configurable 65 * nice to make this configurable
63 */ 66 */
64constexpr u32 MAX_PORTS = 4; 67constexpr u32 MAX_PORTS = 4;
68
65struct PortInfo { 69struct PortInfo {
66 u32_le pad_count{}; ///> Number of ports to request data for 70 u32_le pad_count{}; ///> Number of ports to request data for
67 std::array<u8, MAX_PORTS> port; 71 std::array<u8, MAX_PORTS> port;
68}; 72};
73
69static_assert(std::is_trivially_copyable_v<PortInfo>, 74static_assert(std::is_trivially_copyable_v<PortInfo>,
70 "UDP Request PortInfo is not trivially copyable"); 75 "UDP Request PortInfo is not trivially copyable");
71 76
72/** 77/**
73 * Request the latest pad information from the server. If the server hasn't received this message 78 * Request the latest pad information from the server. If the server hasn't received this message
@@ -80,6 +85,7 @@ struct PadData {
80 Id, 85 Id,
81 Mac, 86 Mac,
82 }; 87 };
88
83 /// Determines which method will be used as a look up for the controller 89 /// Determines which method will be used as a look up for the controller
84 Flags flags{}; 90 Flags flags{};
85 /// Index of the port of the controller to retrieve data about 91 /// Index of the port of the controller to retrieve data about
@@ -87,9 +93,10 @@ struct PadData {
87 /// Mac address of the controller to retrieve data about 93 /// Mac address of the controller to retrieve data about
88 MacAddress mac; 94 MacAddress mac;
89}; 95};
96
90static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size"); 97static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size");
91static_assert(std::is_trivially_copyable_v<PadData>, 98static_assert(std::is_trivially_copyable_v<PadData>,
92 "UDP Request PadData is not trivially copyable"); 99 "UDP Request PadData is not trivially copyable");
93 100
94/** 101/**
95 * Creates a message with the proper header data that can be sent to the server. 102 * Creates a message with the proper header data that can be sent to the server.
@@ -114,9 +121,10 @@ namespace Response {
114struct Version { 121struct Version {
115 u16_le version{}; 122 u16_le version{};
116}; 123};
124
117static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size"); 125static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size");
118static_assert(std::is_trivially_copyable_v<Version>, 126static_assert(std::is_trivially_copyable_v<Version>,
119 "UDP Response Version is not trivially copyable"); 127 "UDP Response Version is not trivially copyable");
120 128
121struct PortInfo { 129struct PortInfo {
122 u8 id{}; 130 u8 id{};
@@ -127,9 +135,10 @@ struct PortInfo {
127 u8 battery{}; 135 u8 battery{};
128 u8 is_pad_active{}; 136 u8 is_pad_active{};
129}; 137};
138
130static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size"); 139static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size");
131static_assert(std::is_trivially_copyable_v<PortInfo>, 140static_assert(std::is_trivially_copyable_v<PortInfo>,
132 "UDP Response PortInfo is not trivially copyable"); 141 "UDP Response PortInfo is not trivially copyable");
133 142
134#pragma pack(push, 1) 143#pragma pack(push, 1)
135struct PadData { 144struct PadData {
@@ -206,16 +215,16 @@ struct PadData {
206 215
207static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size "); 216static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size ");
208static_assert(std::is_trivially_copyable_v<PadData>, 217static_assert(std::is_trivially_copyable_v<PadData>,
209 "UDP Response PadData is not trivially copyable"); 218 "UDP Response PadData is not trivially copyable");
210 219
211static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE, 220static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE,
212 "UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>"); 221 "UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>");
213 222
214static_assert(sizeof(PadData::AnalogButton) == 12, 223static_assert(sizeof(PadData::AnalogButton) == 12,
215 "UDP Response AnalogButton struct has wrong size "); 224 "UDP Response AnalogButton struct has wrong size ");
216static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size "); 225static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size ");
217static_assert(sizeof(PadData::Accelerometer) == 12, 226static_assert(sizeof(PadData::Accelerometer) == 12,
218 "UDP Response Accelerometer struct has wrong size "); 227 "UDP Response Accelerometer struct has wrong size ");
219static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size "); 228static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size ");
220 229
221/** 230/**
@@ -232,22 +241,27 @@ template <>
232constexpr Type GetMessageType<Request::Version>() { 241constexpr Type GetMessageType<Request::Version>() {
233 return Type::Version; 242 return Type::Version;
234} 243}
244
235template <> 245template <>
236constexpr Type GetMessageType<Request::PortInfo>() { 246constexpr Type GetMessageType<Request::PortInfo>() {
237 return Type::PortInfo; 247 return Type::PortInfo;
238} 248}
249
239template <> 250template <>
240constexpr Type GetMessageType<Request::PadData>() { 251constexpr Type GetMessageType<Request::PadData>() {
241 return Type::PadData; 252 return Type::PadData;
242} 253}
254
243template <> 255template <>
244constexpr Type GetMessageType<Response::Version>() { 256constexpr Type GetMessageType<Response::Version>() {
245 return Type::Version; 257 return Type::Version;
246} 258}
259
247template <> 260template <>
248constexpr Type GetMessageType<Response::PortInfo>() { 261constexpr Type GetMessageType<Response::PortInfo>() {
249 return Type::PortInfo; 262 return Type::PortInfo;
250} 263}
264
251template <> 265template <>
252constexpr Type GetMessageType<Response::PadData>() { 266constexpr Type GetMessageType<Response::PadData>() {
253 return Type::PadData; 267 return Type::PadData;