refactor lora payload timing
Bump the batch payload codec to schema v4 with separate meter-time and UTC anchors, then use meter seconds for sparse batch slotting and receiver reconstruction. Update the current 868 MHz bench configuration, allow ACKs from configured receiver short IDs, improve AP-to-STA recovery, quiet the test build, and document the changed protocol in the README.
This commit is contained in:
@@ -10,7 +10,8 @@ static void fill_sparse_batch(BatchInput &in) {
|
||||
memset(&in, 0, sizeof(in));
|
||||
in.sender_id = 1;
|
||||
in.batch_id = 42;
|
||||
in.t_last = 1700000000;
|
||||
in.meter_t_last = 123456789;
|
||||
in.ts_utc_last = 1700000000;
|
||||
in.present_mask = (1UL << 0) | (1UL << 2) | (1UL << 3) | (1UL << 10) | (1UL << 29);
|
||||
in.n = 5;
|
||||
in.battery_mV = 3750;
|
||||
@@ -45,7 +46,8 @@ static void fill_full_batch(BatchInput &in) {
|
||||
memset(&in, 0, sizeof(in));
|
||||
in.sender_id = 1;
|
||||
in.batch_id = 0xBEEF;
|
||||
in.t_last = 1769904999;
|
||||
in.meter_t_last = 1769904999 - 29;
|
||||
in.ts_utc_last = 1769904999;
|
||||
in.present_mask = 0x3FFFFFFFUL;
|
||||
in.n = kMaxSamples;
|
||||
in.battery_mV = 4095;
|
||||
@@ -65,7 +67,8 @@ static void fill_full_batch(BatchInput &in) {
|
||||
static void assert_batch_equals(const BatchInput &expected, const BatchInput &actual) {
|
||||
TEST_ASSERT_EQUAL_UINT16(expected.sender_id, actual.sender_id);
|
||||
TEST_ASSERT_EQUAL_UINT16(expected.batch_id, actual.batch_id);
|
||||
TEST_ASSERT_EQUAL_UINT32(expected.t_last, actual.t_last);
|
||||
TEST_ASSERT_EQUAL_UINT32(expected.meter_t_last, actual.meter_t_last);
|
||||
TEST_ASSERT_EQUAL_UINT32(expected.ts_utc_last, actual.ts_utc_last);
|
||||
TEST_ASSERT_EQUAL_UINT32(expected.present_mask, actual.present_mask);
|
||||
TEST_ASSERT_EQUAL_UINT8(expected.n, actual.n);
|
||||
TEST_ASSERT_EQUAL_UINT16(expected.battery_mV, actual.battery_mV);
|
||||
@@ -89,14 +92,14 @@ static void assert_batch_equals(const BatchInput &expected, const BatchInput &ac
|
||||
}
|
||||
}
|
||||
|
||||
static void test_encode_decode_roundtrip_schema_v3() {
|
||||
static void test_encode_decode_roundtrip_schema_v4() {
|
||||
BatchInput in = {};
|
||||
fill_sparse_batch(in);
|
||||
|
||||
uint8_t encoded[256] = {};
|
||||
size_t encoded_len = 0;
|
||||
TEST_ASSERT_TRUE(encode_batch(in, encoded, sizeof(encoded), &encoded_len));
|
||||
TEST_ASSERT_TRUE(encoded_len > 24);
|
||||
TEST_ASSERT_TRUE(encoded_len > 28);
|
||||
|
||||
BatchInput out = {};
|
||||
TEST_ASSERT_TRUE(decode_batch(encoded, encoded_len, &out));
|
||||
@@ -199,12 +202,22 @@ static void test_encode_rejects_invalid_n_and_regression_cases() {
|
||||
}
|
||||
|
||||
static const uint8_t VECTOR_SYNC_EMPTY[] = {
|
||||
0xB3, 0xDD, 0x03, 0x01, 0x01, 0x00, 0x34, 0x12, 0xE4, 0x97, 0x7E, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA6, 0x0E,
|
||||
0xB3, 0xDD, 0x04, 0x01, 0x01, 0x00, 0x34, 0x12,
|
||||
0x15, 0xCD, 0x5B, 0x07,
|
||||
0xE4, 0x97, 0x7E, 0x69,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00,
|
||||
0xA6, 0x0E,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
static const uint8_t VECTOR_SPARSE_5[] = {
|
||||
0xB3, 0xDD, 0x03, 0x01, 0x01, 0x00, 0x2A, 0x00, 0x00, 0xF1, 0x53, 0x65, 0x0D, 0x04, 0x00, 0x20, 0x05, 0xA6, 0x0E,
|
||||
0x02, 0x01, 0x03, 0x02, 0x01, 0xA0, 0x86, 0x01, 0x00, 0x01, 0x31, 0x00, 0x96, 0x01, 0x88, 0xFF, 0x3C, 0xA0, 0x1F,
|
||||
0xB3, 0xDD, 0x04, 0x01, 0x01, 0x00, 0x2A, 0x00,
|
||||
0x15, 0xCD, 0x5B, 0x07,
|
||||
0x00, 0xF1, 0x53, 0x65,
|
||||
0x0D, 0x04, 0x00, 0x20,
|
||||
0x05, 0xA6, 0x0E,
|
||||
0x02, 0x01, 0x03, 0x02, 0x01,
|
||||
0xA0, 0x86, 0x01, 0x00, 0x01, 0x31, 0x00, 0x96, 0x01, 0x88, 0xFF, 0x3C, 0xA0, 0x1F,
|
||||
0x9F, 0x1F, 0x9C, 0x09, 0x32, 0x00, 0x9F, 0x1F, 0xB4, 0x1F, 0xA0, 0x1F, 0xAB, 0x20, 0x00, 0x00, 0x14, 0x9F, 0x1F,
|
||||
0xA0, 0x1F, 0x14};
|
||||
|
||||
@@ -224,7 +237,8 @@ static void test_payload_golden_vectors() {
|
||||
BatchInput expected_sync = {};
|
||||
expected_sync.sender_id = 1;
|
||||
expected_sync.batch_id = 0x1234;
|
||||
expected_sync.t_last = 1769904100;
|
||||
expected_sync.meter_t_last = 123456789;
|
||||
expected_sync.ts_utc_last = 1769904100;
|
||||
expected_sync.present_mask = 0;
|
||||
expected_sync.n = 0;
|
||||
expected_sync.battery_mV = 3750;
|
||||
@@ -267,7 +281,7 @@ static void test_payload_golden_vectors() {
|
||||
void setup() {
|
||||
dd3_legacy_core_force_link();
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_encode_decode_roundtrip_schema_v3);
|
||||
RUN_TEST(test_encode_decode_roundtrip_schema_v4);
|
||||
RUN_TEST(test_decode_rejects_bad_magic_schema_flags);
|
||||
RUN_TEST(test_decode_rejects_truncated_and_length_mismatch);
|
||||
RUN_TEST(test_encode_and_decode_reject_invalid_present_mask);
|
||||
|
||||
Reference in New Issue
Block a user