test_rx_file: add JSON logging (controllable via JSONLOGGER define)

This commit is contained in:
Simon Ruderich 2024-05-09 19:05:24 +02:00
parent 33df7132ef
commit 657ac4faa3
2 changed files with 33 additions and 15 deletions

View file

@ -94,6 +94,9 @@ add_executable(
../src/var_array.c
../src/var_array.h
../src/config.h
../src/jsonlogger.c
../src/jsonlogger.h
../src/debug_structs.h
layer1/test_rx_file.c
)

View file

@ -4,6 +4,7 @@
#include <liquid/liquid.h>
#include "jsonlogger.h"
#include "layer1/rx.h"
#include "config.h"
@ -20,12 +21,9 @@
#define CHUNKSIZE_RF (CHUNKSIZE_INPUT/2)
#define CHUNKSIZE_BB (CHUNKSIZE_RF/SDR_OVERSAMPLING)
static struct {
size_t preambles_found;
size_t successful_decodes;
size_t failed_decodes;
size_t header_errors;
} m_stats;
#define JSONLOGGER 0
static rx_stats_t m_rx_stats;
static result_t sdr_rf_to_baseband(nco_crcf nco, firdecim_crcf decim,
@ -69,11 +67,11 @@ void cb_rx(rx_evt_t evt, const layer1_rx_t *rx, uint8_t *packet_data, size_t pac
//fprintf(stderr, "=== FAILED PAYLOAD ===\n");
//hexdump(packet_data, packet_len);
//fprintf(stderr, "=======================\n");
m_stats.failed_decodes++;
m_rx_stats.failed_decodes++;
break;
case RX_EVT_HEADER_ERROR:
m_stats.header_errors++;
m_rx_stats.header_errors++;
break;
case RX_EVT_PACKET_RECEIVED:
@ -82,18 +80,24 @@ void cb_rx(rx_evt_t evt, const layer1_rx_t *rx, uint8_t *packet_data, size_t pac
//hexdump(packet_data, packet_len < 64 ? packet_len : 64);
//fprintf(stderr, "====================================\n");
m_stats.successful_decodes++;
m_rx_stats.successful_decodes++;
break;
case RX_EVT_PREAMBLE_FOUND:
//fprintf(stderr, "Found preamble!\n");
m_stats.preambles_found++;
m_rx_stats.preambles_found++;
break;
case RX_EVT_PACKET_DEBUG_INFO_COMPLETE:
// FIXME: print debug info
#if JSONLOGGER
jsonlogger_log_rx_packet_info(&rx->packet_debug_info);
#endif
break;
}
#if JSONLOGGER
jsonlogger_log_rx_stats(&m_rx_stats);
#endif
}
@ -112,6 +116,13 @@ int main(int argc, char **argv)
// ** Initialize **
#if JSONLOGGER
if(!jsonlogger_init("jsonlog_test.fifo")) {
fprintf(stderr, "Could not initialize JSON logger.\n");
return EXIT_FAILURE;
}
#endif
firdecim_crcf decim = firdecim_crcf_create_kaiser(SDR_OVERSAMPLING, 9, 60.0f);
nco_crcf rx_nco = nco_crcf_create(LIQUID_NCO);
nco_crcf_set_frequency(rx_nco, 2 * 3.14159 * SDR_RX_IF_SHIFT / SDR_RX_SAMPLING_RATE);
@ -147,13 +158,13 @@ int main(int argc, char **argv)
RESULT_CHECK(layer1_rx_process(&rx, bb_samples, n_bb_samples));
fprintf(stderr, "Receiver statistics:\n");
fprintf(stderr, " Preambles found: %8zd\n", m_stats.preambles_found);
fprintf(stderr, " Preambles found: %8zd\n", m_rx_stats.preambles_found);
fprintf(stderr, " Successful decodes: %8zd (%6.2f %%)\n",
m_stats.successful_decodes, m_stats.successful_decodes * 100.0f / m_stats.preambles_found);
m_rx_stats.successful_decodes, m_rx_stats.successful_decodes * 100.0f / m_rx_stats.preambles_found);
fprintf(stderr, " Header errors: %8zd (%6.2f %%)\n",
m_stats.header_errors, m_stats.header_errors * 100.0f / m_stats.preambles_found);
m_rx_stats.header_errors, m_rx_stats.header_errors * 100.0f / m_rx_stats.preambles_found);
fprintf(stderr, " Failed decodes: %8zd (%6.2f %%)\n",
m_stats.failed_decodes, m_stats.failed_decodes * 100.0f / m_stats.preambles_found);
m_rx_stats.failed_decodes, m_rx_stats.failed_decodes * 100.0f / m_rx_stats.preambles_found);
}
@ -161,5 +172,9 @@ int main(int argc, char **argv)
layer1_rx_shutdown(&rx);
#if JSONLOGGER
jsonlogger_shutdown();
#endif
fprintf(stderr, "Done.\n");
}