Add msgpack wire protocol with halfsiphash checksums

This commit is contained in:
Ian Gulliver
2026-04-03 16:59:11 +09:00
parent b076cce34a
commit db6f005bef
33 changed files with 5928 additions and 3 deletions

View File

@@ -1,6 +1,38 @@
#include <stdio.h>
#include <string.h>
#include <vector>
#include "pico/stdlib.h"
#include "pico/bootrom.h"
#include "msgpackpp.h"
#include "halfsiphash.h"
static constexpr uint8_t hash_key[8] = {};
struct RebootingBootsel {
static constexpr int8_t ext_id = 1;
auto as_tuple() const { return std::tie(); }
};
struct Envelope {
static constexpr int8_t ext_id = 0;
uint32_t checksum;
std::vector<uint8_t> payload;
auto as_tuple() const { return std::tie(checksum, payload); }
};
static std::vector<uint8_t> pack_envelope(const std::vector<uint8_t> &payload) {
uint32_t checksum = halfsiphash::hash32(payload.data(), payload.size(), hash_key);
msgpackpp::packer p;
p.pack(Envelope{checksum, payload});
return p.get_payload();
}
static void send_bytes(const std::vector<uint8_t> &data) {
for (auto b : data) {
putchar(b);
}
stdio_flush();
}
int main() {
stdio_init_all();
@@ -10,6 +42,11 @@ int main() {
if (c == 'p') {
printf("p");
} else if (c == 'b') {
msgpackpp::packer inner;
inner.pack(RebootingBootsel{});
auto msg = pack_envelope(inner.get_payload());
send_bytes(msg);
sleep_ms(100);
reset_usb_boot(0, 0);
}
}