今日已更新 339 条资讯 | 累计 19899 条内容
关于我们

标签:#msg

找到 1 篇相关文章

AI 资讯

A small C++ library for sending structured commands and telemetry between devices — no schema files, just add your parameters and serialize

If you've ever tried to build a simple command/telemetry protocol between a PC and a fleet of SDR receivers, sensors, or embedded devices, you know the usual options aren't great: Roll your own binary format — fast, but you end up writing and maintaining custom serialization code for every device type, and debugging mismatched structs across machines is painful. Protobuf / FlatBuffers — robust, but require you to define your message layout in a schema file upfront, run a code generator as part of your build, and commit to a fixed structure. Adding a new device type or a new parameter means editing the schema, regenerating, recompiling everything. JSON over the wire — easy to debug, but heavy for anything real-time or bandwidth-constrained. I ran into this while working on a multi-SDR receiver system and ended up writing MessageFrame — a small C++17 library that lets you build structured messages dynamically, without any schema files or code generation. The basic idea Instead of defining a struct for each device type, you address each parameter with two strings — a device name and a parameter name — and the library handles the rest: // One message, multiple devices, assembled at runtime msgframe :: MessageFrame msg ( MSG_TELEMETRY , TYPE_PERIODIC , src = 1 , tgt = 2 ); msg . add ( "sdr_1" , "rx_gain" , VALUE ( 30.0 )); msg . add ( "sdr_1" , "center_freq" , VALUE ( 915'000'000.0 )); msg . add ( "sdr_1" , "sample_rate" , VALUE ( 2'000'000.0 )); msg . add ( "sdr_2" , "rx_gain" , VALUE ( 25.0 )); msg . add ( "sdr_2" , "lock_status" , VALUE ( true )); msg . add ( "psu_1" , "voltage" , VALUE ( 12.04 )); msg . add ( "psu_1" , "temp_c" , VALUE ( 47.3 )); // Attach raw IQ data alongside the parameters std :: vector < uint8_t > iq_buffer = { 0x01 , 0x02 , 0x03 , 0x04 }; msg . add_attachment ( "raw_iq" , std :: move ( iq_buffer )); // Serialize into a buffer, send over whatever transport you use std :: vector < uint8_t > out ; msg . serialize ( out ); send_udp ( out . data (),

2026-07-02 原文 →