Add repeater protocol and device firmware features
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Host tool: feed captured post-sync payload bytes (hex on argv[1]) through
|
||||
// the firmware's T1 classification/decode path exactly as handle_rx does.
|
||||
// Prints the decode result for cross-checking against a known transmitted
|
||||
// frame. Not part of run_tests.sh; used by ad-hoc RF verification.
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wmbus.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) { fprintf(stderr, "usage: %s HEXBYTES\n", argv[0]); return 2; }
|
||||
size_t hexlen = strlen(argv[1]);
|
||||
static uint8_t buf[512];
|
||||
size_t n = hexlen / 2;
|
||||
if (n > sizeof(buf)) n = sizeof(buf);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
unsigned v;
|
||||
if (sscanf(argv[1] + 2 * i, "%2x", &v) != 1) return 2;
|
||||
buf[i] = (uint8_t)v;
|
||||
}
|
||||
|
||||
int lfield = wmbus_3of6_first_byte(buf, n);
|
||||
printf("lfield=%d\n", lfield);
|
||||
if (lfield < 9) return 1;
|
||||
int total = wmbus_frame_total_len(WMBUS_FRAME_A, (uint8_t)lfield);
|
||||
printf("total=%d coded_len=%d have=%zu\n",
|
||||
total, total > 0 ? wmbus_3of6_coded_len(total) : -1, n);
|
||||
if (total < 0 || wmbus_3of6_coded_len(total) > (int)n) return 1;
|
||||
static uint8_t frame[512];
|
||||
int bad = wmbus_3of6_decode(buf, n, frame, total);
|
||||
int crc = wmbus_check_crc(WMBUS_FRAME_A, frame, total);
|
||||
printf("bad_codes=%d crc_ok=%d\nframe=", bad, crc);
|
||||
for (int i = 0; i < total; i++) printf("%02X", frame[i]);
|
||||
printf("\n");
|
||||
return crc ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user