Add dlogf printf formatting, ipv4::to_string helper, clean up string building

This commit is contained in:
Ian Gulliver
2026-04-11 08:21:59 +09:00
parent c35c1de76a
commit 3a3c5873c3
5 changed files with 32 additions and 7 deletions

View File

@@ -72,7 +72,11 @@ void dispatch_schedule_ms(uint32_t ms, std::function<void()> fn) {
uint8_t err_buf[256];
span_writer err_out(err_buf, sizeof(err_buf));
auto err = encode_response_into(err_out, msg->message_id,
DeviceError{2, "response too large: " + std::to_string(data.size())});
[&]{
char m[48];
snprintf(m, sizeof(m), "response too large: %zu", data.size());
return DeviceError{2, m};
}());
if (err) usb.send(std::span<const uint8_t>{err_buf, *err});
}
});

View File

@@ -44,9 +44,7 @@ static void test_ping(const responder& resp, ipv4::ip4_addr dst_ip) {
return;
}
*done = true;
std::string ip_str = std::to_string(src_ip[0]) + "." + std::to_string(src_ip[1]) + "." +
std::to_string(src_ip[2]) + "." + std::to_string(src_ip[3]);
resp.respond(ResponseTest{true, {"reply from " + ip_str}});
resp.respond(ResponseTest{true, {"reply from " + ipv4::to_string(src_ip)}});
};
net_add_frame_callback(*cb);