MACRAW-only: simplify send/recv API, remove non-MACRAW code paths and unused types
This commit is contained in:
@@ -29,44 +29,36 @@ static ResponseTest test_discovery() {
|
||||
ResponseTest resp;
|
||||
resp.pass = true;
|
||||
|
||||
w6300::ip_address dest = {};
|
||||
std::copy(picomap_discovery_ip.begin(), picomap_discovery_ip.end(), dest.ip.begin());
|
||||
dest.len = 4;
|
||||
|
||||
w6300::set_socket_dest_mac(test_socket, picomap_discovery_mac);
|
||||
|
||||
auto req = encode_request(0, RequestInfo{});
|
||||
auto send_result = w6300::sendto(test_socket, std::span<const uint8_t>{req}, dest,
|
||||
w6300::port_num{PICOMAP_DISCOVERY_PORT});
|
||||
auto send_result = w6300::send(test_socket, std::span<const uint8_t>{req});
|
||||
if (!send_result) {
|
||||
resp.pass = false;
|
||||
resp.messages.push_back("sendto: error " + std::to_string(static_cast<int>(send_result.error())));
|
||||
resp.messages.push_back("send: error " + std::to_string(static_cast<int>(send_result.error())));
|
||||
return resp;
|
||||
}
|
||||
|
||||
uint8_t rx_buf[512];
|
||||
w6300::ip_address src_addr = {};
|
||||
w6300::port_num src_port{0};
|
||||
|
||||
auto deadline = make_timeout_time_ms(5000);
|
||||
std::expected<uint16_t, w6300::sock_error> recv_result = std::unexpected(w6300::sock_error::busy);
|
||||
while (get_absolute_time() < deadline) {
|
||||
recv_result = w6300::recvfrom(test_socket, std::span{rx_buf}, src_addr, src_port);
|
||||
recv_result = w6300::recv(test_socket, std::span{rx_buf});
|
||||
if (recv_result || recv_result.error() != w6300::sock_error::busy) break;
|
||||
}
|
||||
|
||||
if (!recv_result) {
|
||||
resp.pass = false;
|
||||
if (recv_result.error() == w6300::sock_error::busy) {
|
||||
resp.messages.push_back("recvfrom: timed out after 5s");
|
||||
resp.messages.push_back("recv: timed out after 5s");
|
||||
} else {
|
||||
resp.messages.push_back("recvfrom: error " + std::to_string(static_cast<int>(recv_result.error())));
|
||||
resp.messages.push_back("recv: error " + std::to_string(static_cast<int>(recv_result.error())));
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
resp.messages.push_back("received " + std::to_string(*recv_result) + " bytes from port " +
|
||||
std::to_string(static_cast<uint16_t>(src_port)));
|
||||
resp.messages.push_back("received " + std::to_string(*recv_result) + " bytes");
|
||||
|
||||
auto info = decode_response<ResponseInfo>(rx_buf, *recv_result);
|
||||
if (!info) {
|
||||
|
||||
Reference in New Issue
Block a user