mcu-its-g5: decoded header as JSON on mcu-its-g5/decoded, 1 Hz per station
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Successful in 58s

Message type, station type and id, position, speed and heading from the
GeoNetworking header, so consumers don't need an ASN.1 decoder. Outside
its/<node>/#, so the EMQX bridge keeps it off OpenTrafficMap.
This commit is contained in:
randy committed 2026-11-19 00:24:44 +01:00
1 parent 3676c0bbcc
commit 547dea26e3
3 files changed
+39

No files matched your search

+25
View File
@@ -13,6 +13,7 @@ namespace its_g5_decode {
struct Info {
uint16_t port{0}; // BTP destination port, 0 = none
uint8_t station_type{0}; // ETSI station type from the GN address
uint64_t addr{0}; // GN address (M bit, station type, MID), identifies the station
bool secured{false}; // carried in an ETSI TS 103 097 signed packet (signature not verified)
double lat{0}, lon{0}; // degrees
float speed_kmh{0};
@@ -116,6 +117,8 @@ inline bool parse(const std::vector<uint8_t> &frame, Info &out) {
// Long position vector: GN address (8), timestamp (4), lat, lon (1/10 µdeg), PAI | speed, heading
out.station_type = (f[pv] >> 2) & 0x1F;
for (size_t k = 0; k < 8; k++)
out.addr = (out.addr << 8) | f[pv + k];
out.lat = be32(f + pv + 12) / 1e7;
out.lon = be32(f + pv + 16) / 1e7;
int16_t speed = be16(f + pv + 20) & 0x7FFF;
@@ -151,4 +154,26 @@ inline bool handle(const std::vector<uint8_t> &frame) {
return true;
}
// Rate limit per station: true if addr was not let through in the last period_ms.
// ponytail: 32 slots, the oldest is evicted; with more stations in range some publish more often.
inline bool due(uint64_t addr, uint32_t now, uint32_t period_ms) {
static struct {
uint64_t addr;
uint32_t ms;
} slots[32]{};
auto *slot = &slots[0];
for (auto &s : slots) {
if (s.addr == addr) {
slot = &s;
break;
}
if (now - s.ms > now - slot->ms)
slot = &s;
}
if (slot->addr == addr && now - slot->ms < period_ms)
return false;
*slot = {addr, now};
return true;
}
} // namespace its_g5_decode