Address second part of review comments
This commit is contained in:
parent
0fe11746fc
commit
bbd85a495a
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
bool WaitFor(const std::chrono::duration<Duration>& time) {
|
bool WaitFor(const std::chrono::duration<Duration>& time) {
|
||||||
std::unique_lock<std::mutex> lk(mutex);
|
std::unique_lock lk{mutex};
|
||||||
if (!condvar.wait_for(lk, time, [this] { return is_set; }))
|
if (!condvar.wait_for(lk, time, [this] { return is_set; }))
|
||||||
return false;
|
return false;
|
||||||
is_set = false;
|
is_set = false;
|
||||||
|
|
|
@ -212,10 +212,11 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie
|
||||||
bool result = success_event.WaitFor(std::chrono::seconds(8));
|
bool result = success_event.WaitFor(std::chrono::seconds(8));
|
||||||
socket.Stop();
|
socket.Stop();
|
||||||
worker_thread.join();
|
worker_thread.join();
|
||||||
if (result)
|
if (result) {
|
||||||
success_callback();
|
success_callback();
|
||||||
else
|
} else {
|
||||||
failure_callback();
|
failure_callback();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
@ -228,8 +229,10 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
|
||||||
std::thread([=] {
|
std::thread([=] {
|
||||||
constexpr u16 CALIBRATION_THRESHOLD = 100;
|
constexpr u16 CALIBRATION_THRESHOLD = 100;
|
||||||
|
|
||||||
u16 min_x{UINT16_MAX}, min_y{UINT16_MAX};
|
u16 min_x{UINT16_MAX};
|
||||||
u16 max_x{}, max_y{};
|
u16 min_y{UINT16_MAX};
|
||||||
|
u16 max_x{};
|
||||||
|
u16 max_y{};
|
||||||
|
|
||||||
Status current_status{Status::Initialized};
|
Status current_status{Status::Initialized};
|
||||||
SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
|
SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
|
||||||
|
@ -239,8 +242,9 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
|
||||||
current_status = Status::Ready;
|
current_status = Status::Ready;
|
||||||
status_callback(current_status);
|
status_callback(current_status);
|
||||||
}
|
}
|
||||||
if (!data.touch_1.is_active)
|
if (!data.touch_1.is_active) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x,
|
LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x,
|
||||||
data.touch_1.y);
|
data.touch_1.y);
|
||||||
min_x = std::min(min_x, static_cast<u16>(data.touch_1.x));
|
min_x = std::min(min_x, static_cast<u16>(data.touch_1.x));
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
namespace InputCommon::CemuhookUDP {
|
namespace InputCommon::CemuhookUDP {
|
||||||
|
|
||||||
static constexpr u16 DEFAULT_PORT = 26760;
|
constexpr u16 DEFAULT_PORT = 26760;
|
||||||
static constexpr const char* DEFAULT_ADDR = "127.0.0.1";
|
constexpr char DEFAULT_ADDR[] = "127.0.0.1";
|
||||||
|
|
||||||
class Socket;
|
class Socket;
|
||||||
|
|
||||||
|
|
|
@ -32,21 +32,21 @@ namespace Response {
|
||||||
std::optional<Type> Validate(u8* data, std::size_t size) {
|
std::optional<Type> Validate(u8* data, std::size_t size) {
|
||||||
if (size < sizeof(Header)) {
|
if (size < sizeof(Header)) {
|
||||||
LOG_DEBUG(Input, "Invalid UDP packet received");
|
LOG_DEBUG(Input, "Invalid UDP packet received");
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
Header header{};
|
Header header{};
|
||||||
std::memcpy(&header, data, sizeof(Header));
|
std::memcpy(&header, data, sizeof(Header));
|
||||||
if (header.magic != SERVER_MAGIC) {
|
if (header.magic != SERVER_MAGIC) {
|
||||||
LOG_ERROR(Input, "UDP Packet has an unexpected magic value");
|
LOG_ERROR(Input, "UDP Packet has an unexpected magic value");
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
if (header.protocol_version != PROTOCOL_VERSION) {
|
if (header.protocol_version != PROTOCOL_VERSION) {
|
||||||
LOG_ERROR(Input, "UDP Packet protocol mismatch");
|
LOG_ERROR(Input, "UDP Packet protocol mismatch");
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
if (header.type < Type::Version || header.type > Type::PadData) {
|
if (header.type < Type::Version || header.type > Type::PadData) {
|
||||||
LOG_ERROR(Input, "UDP Packet is an unknown type");
|
LOG_ERROR(Input, "UDP Packet is an unknown type");
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packet size must equal sizeof(Header) + sizeof(Data)
|
// Packet size must equal sizeof(Header) + sizeof(Data)
|
||||||
|
@ -59,7 +59,7 @@ std::optional<Type> Validate(u8* data, std::size_t size) {
|
||||||
Input,
|
Input,
|
||||||
"UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}",
|
"UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}",
|
||||||
size, header.payload_length, data_len + sizeof(Type));
|
size, header.payload_length, data_len + sizeof(Type));
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 crc32 = header.crc;
|
const u32 crc32 = header.crc;
|
||||||
|
@ -70,7 +70,7 @@ std::optional<Type> Validate(u8* data, std::size_t size) {
|
||||||
result.process_bytes(data, data_len + sizeof(Header));
|
result.process_bytes(data, data_len + sizeof(Header));
|
||||||
if (crc32 != result.checksum()) {
|
if (crc32 != result.checksum()) {
|
||||||
LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc));
|
LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc));
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return header.type;
|
return header.type;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue