feat: add HIL diagnostics and meter health handling

This commit is contained in:
2026-08-17 22:33:04 +02:00
parent bc2ac6e8f6
commit aa25aa2c12
30 changed files with 2108 additions and 236 deletions
+9
View File
@@ -1,4 +1,5 @@
#include "lora_transport.h"
#include "hil_trace.h"
#include <LoRa.h>
#include <SPI.h>
#include <math.h>
@@ -13,6 +14,7 @@ static void note_reject(RxRejectReason reason) {
if (now_ms - g_last_rx_reject_log_ms >= 1000) {
g_last_rx_reject_log_ms = now_ms;
Serial.printf("lora_rx: reject reason=%s\n", rx_reject_reason_text(reason));
hil_trace_eventf("lora_reject", "\"reason\":\"%s\"", rx_reject_reason_text(reason));
}
}
}
@@ -84,6 +86,13 @@ bool lora_send(const LoraPacket &pkt) {
buffer[idx++] = static_cast<uint8_t>(crc >> 8);
buffer[idx++] = static_cast<uint8_t>(crc & 0xFF);
if (pkt.payload_type == PayloadType::MeterBatch && hil_fault_take(HilFault::CorruptChunk) && idx > 7) {
// Flip a payload byte after calculating the frame CRC so the receiver's
// production CRC path rejects this one HIL frame.
buffer[5 + (pkt.payload_len > 6 ? 6 : 0)] ^= 0x01;
hil_trace_event("fault_injected", "\"fault\":\"corrupt_chunk\"");
}
LoRa.beginPacket();
if (SERIAL_DEBUG_MODE) {
t2 = millis();