Switch to IPv4 zeroconf, add test framework with discovery test, fix serial enumeration

This commit is contained in:
Ian Gulliver
2026-04-07 06:58:39 +09:00
parent b8c0e6be66
commit e60479bad8
14 changed files with 308 additions and 33 deletions

View File

@@ -2,13 +2,29 @@
#include <cstdint>
#include <span>
#include <vector>
#include "wire.h"
#include "w6300.h"
using handler_fn = std::vector<std::vector<uint8_t>> (*)(uint32_t message_id, std::span<const uint8_t> payload);
struct handler_entry {
int8_t type_id;
std::vector<std::vector<uint8_t>> (*handle)(uint32_t message_id);
handler_fn handle;
};
template <typename Req, auto Fn>
std::vector<std::vector<uint8_t>> typed_handler(uint32_t message_id, std::span<const uint8_t> payload) {
msgpack::parser p(payload.data(), static_cast<int>(payload.size()));
Req req;
auto tup = req.as_tuple();
auto r = msgpack::unpack(p, tup);
if (!r) {
return {encode_response(message_id, DeviceError{1, "decode request ext_id=" +
std::to_string(Req::ext_id) + ": msgpack error " + std::to_string(static_cast<int>(r.error()))})};
}
return Fn(message_id, req);
}
void dispatch_init();
[[noreturn]] void dispatch_run(std::span<const handler_entry> handlers,
std::span<const w6300::socket_id> sockets = {});