You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

55 lines
1.8 KiB

/* SPDX-License-Identifier: MIT
* Copyright (c) 2026 Dan Chokola, KD2HSG */
/* Decode one buffer of modem-rate samples (cf32, osr = 2) with
* cm_receive_frame and print the result (tools/check_c.py drives it).
*
* cm_rxvec SF BW EFFORT FILE.cf32 [FILE.cf32 ...]
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "cm.h"
int main(int argc, char **argv)
{
if (argc < 5) {
fprintf(stderr, "usage: %s SF BW EFFORT FILE.cf32 ...\n", argv[0]);
return 2;
}
cm_phy p;
cm_phy_init(&p, atoi(argv[1]), atof(argv[2]), 223.58e6);
int effort = atoi(argv[3]);
cm_rx *rx = cm_rx_new(&p);
static const char *stage[] = {"no_sync", "header_fail", "payload_fail", "ok"};
for (int a = 4; a < argc; a++) {
FILE *f = fopen(argv[a], "rb");
if (!f) {
perror(argv[a]);
return 1;
}
fseek(f, 0, SEEK_END);
long n = ftell(f) / (long)sizeof(cf32);
fseek(f, 0, SEEK_SET);
cf32 *b = malloc(sizeof(cf32) * (size_t)n);
cf64 *x = malloc(sizeof(cf64) * (size_t)n);
if (fread(b, sizeof(cf32), (size_t)n, f) != (size_t)n)
return 1;
fclose(f);
for (long i = 0; i < n; i++)
x[i] = b[i];
cm_result r;
clock_t t0 = clock();
cm_receive_frame(rx, x, (int)n, 0, effort, 4.0, &r);
double dt = (double)(clock() - t0) / CLOCKS_PER_SEC;
printf("%s %s tau0=%.3f f_hz=%.2f snr=%.2f ramp=%d drift=%d dd=%d cpu=%.4f mac=",
argv[a], stage[r.stage], r.sync.tau0, r.sync.f_hz, r.snr_db, r.ramp_retry,
r.drift_retry, r.dd_passes, dt);
for (int i = 0; i < r.mac_len; i++)
printf("%02x", r.mac[i]);
printf("\n");
free(b);
free(x);
}
cm_rx_free(rx);
return 0;
}