diff options
Diffstat (limited to 'src/input_common/udp/protocol.h')
| -rw-r--r-- | src/input_common/udp/protocol.h | 32 |
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 | |||
| 38 | static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size"); | 39 | static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size"); |
| 39 | static_assert(std::is_trivially_copyable_v<Header>, "UDP Message Header is not trivially copyable"); | 40 | static_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 | ||
| 55 | namespace Request { | 56 | namespace Request { |
| 56 | 57 | ||
| 57 | struct Version {}; | 58 | struct 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 | */ |
| 64 | constexpr u32 MAX_PORTS = 4; | 67 | constexpr u32 MAX_PORTS = 4; |
| 68 | |||
| 65 | struct PortInfo { | 69 | struct 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 | |||
| 69 | static_assert(std::is_trivially_copyable_v<PortInfo>, | 74 | static_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 | |||
| 90 | static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size"); | 97 | static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size"); |
| 91 | static_assert(std::is_trivially_copyable_v<PadData>, | 98 | static_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 { | |||
| 114 | struct Version { | 121 | struct Version { |
| 115 | u16_le version{}; | 122 | u16_le version{}; |
| 116 | }; | 123 | }; |
| 124 | |||
| 117 | static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size"); | 125 | static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size"); |
| 118 | static_assert(std::is_trivially_copyable_v<Version>, | 126 | static_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 | ||
| 121 | struct PortInfo { | 129 | struct 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 | |||
| 130 | static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size"); | 139 | static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size"); |
| 131 | static_assert(std::is_trivially_copyable_v<PortInfo>, | 140 | static_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) |
| 135 | struct PadData { | 144 | struct PadData { |
| @@ -206,16 +215,16 @@ struct PadData { | |||
| 206 | 215 | ||
| 207 | static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size "); | 216 | static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size "); |
| 208 | static_assert(std::is_trivially_copyable_v<PadData>, | 217 | static_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 | ||
| 211 | static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE, | 220 | static_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 | ||
| 214 | static_assert(sizeof(PadData::AnalogButton) == 12, | 223 | static_assert(sizeof(PadData::AnalogButton) == 12, |
| 215 | "UDP Response AnalogButton struct has wrong size "); | 224 | "UDP Response AnalogButton struct has wrong size "); |
| 216 | static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size "); | 225 | static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size "); |
| 217 | static_assert(sizeof(PadData::Accelerometer) == 12, | 226 | static_assert(sizeof(PadData::Accelerometer) == 12, |
| 218 | "UDP Response Accelerometer struct has wrong size "); | 227 | "UDP Response Accelerometer struct has wrong size "); |
| 219 | static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size "); | 228 | static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size "); |
| 220 | 229 | ||
| 221 | /** | 230 | /** |
| @@ -232,22 +241,27 @@ template <> | |||
| 232 | constexpr Type GetMessageType<Request::Version>() { | 241 | constexpr Type GetMessageType<Request::Version>() { |
| 233 | return Type::Version; | 242 | return Type::Version; |
| 234 | } | 243 | } |
| 244 | |||
| 235 | template <> | 245 | template <> |
| 236 | constexpr Type GetMessageType<Request::PortInfo>() { | 246 | constexpr Type GetMessageType<Request::PortInfo>() { |
| 237 | return Type::PortInfo; | 247 | return Type::PortInfo; |
| 238 | } | 248 | } |
| 249 | |||
| 239 | template <> | 250 | template <> |
| 240 | constexpr Type GetMessageType<Request::PadData>() { | 251 | constexpr Type GetMessageType<Request::PadData>() { |
| 241 | return Type::PadData; | 252 | return Type::PadData; |
| 242 | } | 253 | } |
| 254 | |||
| 243 | template <> | 255 | template <> |
| 244 | constexpr Type GetMessageType<Response::Version>() { | 256 | constexpr Type GetMessageType<Response::Version>() { |
| 245 | return Type::Version; | 257 | return Type::Version; |
| 246 | } | 258 | } |
| 259 | |||
| 247 | template <> | 260 | template <> |
| 248 | constexpr Type GetMessageType<Response::PortInfo>() { | 261 | constexpr Type GetMessageType<Response::PortInfo>() { |
| 249 | return Type::PortInfo; | 262 | return Type::PortInfo; |
| 250 | } | 263 | } |
| 264 | |||
| 251 | template <> | 265 | template <> |
| 252 | constexpr Type GetMessageType<Response::PadData>() { | 266 | constexpr Type GetMessageType<Response::PadData>() { |
| 253 | return Type::PadData; | 267 | return Type::PadData; |