Rebuild obu-firmware on Niklas Dathe's microbu-firmware
Replace the vanetza-idf port with his current station firmware (microbu-firmware e4e4bd8: main/, components/microbu_v2x, components/vanetza, external/vanetza) and re-apply the MicrOBU additions, each marked "MicrOBU:" in the sources: - V2X_RX (opcode 0x90): every received ITS message, signed or not, through gn_unwrap.c, because the stack drops unsigned and foreign-root traffic. 0x85 is the spec's RAW_FRAME and 0x86 is reserved. The body is built in v2x_rx.hpp. - Unsigned transmission (geonet.c) for security profile 1 or station security 0, from a random MAC per configuration. - Radio polled from STATION_CONFIGURE on; manual country policy, TX power read-back, static RX buffer, short frames ignored. - Battery guard (battery_policy.hpp): deep sleep below 3.30 V with no phone on USB. - No USB writes without a host; last_frame_ms() for the guard. - 80 KB NVS with the app at 0x20000, 8 MB flash, XIAO ESP32-C5 board, 20 dBm. Remove the old C firmware, the bench listener and the old vanetza-idf copy. Add docs/station-link.tex as revision 2 of the interface reference (V2X_RX, unsigned sending, battery rule, revision history). Add 39 host unit tests (make firmware in test/host) next to the existing chain, replay, fuzz and battery tests, and point tools/station_status_watch.py at the new CONFIRM-based status.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
// Host tests for the battery policy (battery_monitor.hpp) and the STATUS battery extension
|
||||
// (link_protocol.cpp). No ESP-IDF involved: both sources compile unmodified on the PC.
|
||||
#include "battery_monitor.hpp"
|
||||
#include "link_protocol.hpp"
|
||||
// Host tests for the battery policy (battery_policy.hpp). No ESP-IDF involved: it compiles unmodified on the PC.
|
||||
#include "battery_policy.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -12,12 +10,12 @@ static int failures = 0;
|
||||
#define CHECK(cond) do { if (!(cond)) { std::printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #cond); ++failures; } } while (0)
|
||||
|
||||
// Feeds the same sample n times, 5 s apart, starting at t_ms.
|
||||
static void feed(BatteryMonitor& m, std::uint16_t mv, int n, bool usb, std::uint32_t& t_ms) {
|
||||
static void feed(BatteryPolicy& m, std::uint16_t mv, int n, bool usb, std::uint32_t& t_ms) {
|
||||
for (int i = 0; i < n; ++i) { m.update(mv, usb, t_ms); t_ms += 5000; }
|
||||
}
|
||||
|
||||
static void test_smoothing_and_validity() {
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
CHECK(m.millivolts() == 0); // nothing measured yet
|
||||
m.update(4100, false, 0);
|
||||
CHECK(m.millivolts() == 4100); // first sample taken as is, no ramp from zero
|
||||
@@ -32,7 +30,7 @@ static void test_smoothing_and_validity() {
|
||||
}
|
||||
|
||||
static void test_warning_hysteresis() {
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
std::uint32_t t = 0;
|
||||
feed(m, 3700, 3, false, t);
|
||||
CHECK(!m.low());
|
||||
@@ -46,7 +44,7 @@ static void test_warning_hysteresis() {
|
||||
|
||||
static void test_shutdown_rules() {
|
||||
{ // sustained low, no USB, after the grace period
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
std::uint32_t t = 120000;
|
||||
feed(m, 3250, 5, false, t);
|
||||
CHECK(m.critical() && !m.shutdown_due()); // five samples are not enough
|
||||
@@ -54,7 +52,7 @@ static void test_shutdown_rules() {
|
||||
CHECK(m.shutdown_due());
|
||||
}
|
||||
{ // a phone on USB powers the board: never shut down, and the count restarts
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
std::uint32_t t = 120000;
|
||||
feed(m, 3250, 5, false, t);
|
||||
feed(m, 3250, 1, true, t);
|
||||
@@ -65,7 +63,7 @@ static void test_shutdown_rules() {
|
||||
CHECK(m.shutdown_due());
|
||||
}
|
||||
{ // not within the first minute after boot
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
std::uint32_t t = 0;
|
||||
feed(m, 3250, 11, false, t); // 0..50 s
|
||||
CHECK(!m.shutdown_due());
|
||||
@@ -73,7 +71,7 @@ static void test_shutdown_rules() {
|
||||
CHECK(m.shutdown_due());
|
||||
}
|
||||
{ // a dip that recovers (TX sag) does not count
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
std::uint32_t t = 120000;
|
||||
feed(m, 3250, 4, false, t);
|
||||
feed(m, 3900, 10, false, t);
|
||||
@@ -81,13 +79,13 @@ static void test_shutdown_rules() {
|
||||
CHECK(!m.shutdown_due());
|
||||
}
|
||||
{ // a normal cell never trips it
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
std::uint32_t t = 120000;
|
||||
feed(m, 3800, 100, false, t);
|
||||
CHECK(!m.shutdown_due() && !m.low() && !m.critical());
|
||||
}
|
||||
{ // no cell / no sensor: no shutdown
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
std::uint32_t t = 120000;
|
||||
feed(m, 0, 100, false, t);
|
||||
CHECK(!m.shutdown_due());
|
||||
@@ -95,7 +93,7 @@ static void test_shutdown_rules() {
|
||||
}
|
||||
|
||||
static void test_resume() {
|
||||
BatteryMonitor m;
|
||||
BatteryPolicy m;
|
||||
CHECK(!m.resume_ok(3300));
|
||||
CHECK(!m.resume_ok(3599));
|
||||
CHECK(m.resume_ok(3600));
|
||||
@@ -103,48 +101,12 @@ static void test_resume() {
|
||||
CHECK(m.resume_ok(0)); // cannot judge: run
|
||||
}
|
||||
|
||||
static link::Status sample_status() {
|
||||
link::Status s;
|
||||
s.uptime_ms = 123456; s.configured = 1; s.tickets = 7; s.signed_messages = 42; s.poti_updates = 9;
|
||||
s.its_time_ms = 0x0102030405060708ULL;
|
||||
s.battery_mv = 3871; s.battery_flags = link::battery_flag_low;
|
||||
return s;
|
||||
}
|
||||
|
||||
static void test_status_protocol() {
|
||||
const auto body = link::encode(sample_status());
|
||||
CHECK(body.size() == link::status_size_battery);
|
||||
CHECK(body.size() == 106);
|
||||
link::Status d;
|
||||
CHECK(link::decode(body, d));
|
||||
CHECK(d.battery_mv == 3871 && d.battery_flags == link::battery_flag_low);
|
||||
CHECK(d.uptime_ms == 123456 && d.tickets == 7 && d.its_time_ms == 0x0102030405060708ULL);
|
||||
|
||||
// the 103-octet layout of the colleague's station (and of this firmware before the battery)
|
||||
link::Bytes legacy(body.begin(), body.begin() + link::status_size_base);
|
||||
link::Status l;
|
||||
l.battery_mv = 999; l.battery_flags = 0xFF;
|
||||
CHECK(link::decode(legacy, l));
|
||||
CHECK(l.battery_mv == 0 && l.battery_flags == 0);
|
||||
CHECK(l.uptime_ms == 123456 && l.its_time_ms == 0x0102030405060708ULL);
|
||||
|
||||
// trailing octets of a later extension are ignored; half a field is malformed
|
||||
link::Bytes longer = body;
|
||||
longer.push_back(0xEE); longer.push_back(0xEE);
|
||||
link::Status x;
|
||||
CHECK(link::decode(longer, x) && x.battery_mv == 3871);
|
||||
CHECK(!link::decode(link::Bytes(body.begin(), body.begin() + 104), x));
|
||||
CHECK(!link::decode(link::Bytes(body.begin(), body.begin() + 105), x));
|
||||
CHECK(!link::decode(link::Bytes(body.begin(), body.begin() + 102), x));
|
||||
CHECK(!link::decode(link::Bytes(), x));
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_smoothing_and_validity();
|
||||
test_warning_hysteresis();
|
||||
test_shutdown_rules();
|
||||
test_resume();
|
||||
test_status_protocol();
|
||||
if (failures) { std::printf("%d check(s) failed\n", failures); return EXIT_FAILURE; }
|
||||
std::printf("battery: all checks passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user