Clean up debug output
This commit is contained in:
parent
876bafd6f9
commit
0ed7109335
|
@ -143,7 +143,6 @@ float correlator_get_mean_frequency_deviation(correlator_ctx_t *ctx, size_t L, f
|
|||
for(size_t m = m0; m < ctx->search_sequence_len; m++) {
|
||||
size_t nm = (n + m) & ctx->buffer_size_mask;
|
||||
z[m - m0] = ctx->search_sequence[m] * ctx->input_history[nm];
|
||||
printf("%+.6f%+.6fj - %+.6f%+.6fj\n", crealf(ctx->search_sequence[m]), cimagf(ctx->search_sequence[m]), crealf(ctx->input_history[nm]), cimagf(ctx->input_history[nm]));
|
||||
}
|
||||
|
||||
/* Louise & Regiannini frequency estimator */
|
||||
|
|
|
@ -12,6 +12,14 @@
|
|||
#define HEADER_SIZE_BYTES 4
|
||||
#define FREQ_EST_L 8
|
||||
|
||||
#define SHOW_DEBUG_LOG 0
|
||||
|
||||
#if SHOW_DEBUG_LOG
|
||||
# define DEBUG_LOG(...) fprintf(stderr, __VA_ARGS__)
|
||||
#else
|
||||
# define DEBUG_LOG(...) {}
|
||||
#endif
|
||||
|
||||
static void update_nco_pll(nco_crcf nco, float phase_error)
|
||||
{
|
||||
static const float pll_alpha = 0.05f; // phase adjustment factor
|
||||
|
@ -32,29 +40,29 @@ static bool acquire_preamble(layer1_rx_t *rx, const float complex sample)
|
|||
|
||||
if(cabsf(corr_out) > 0.5f * preamble_get_symbol_count()) {
|
||||
// Preamble found!
|
||||
printf("Preamble found: %.3f > %.3f\n", cabsf(corr_out), 0.5f * preamble_get_symbol_count());
|
||||
DEBUG_LOG("Preamble found: %.3f > %.3f\n", cabsf(corr_out), 0.5f * preamble_get_symbol_count());
|
||||
|
||||
float phase_offset;
|
||||
float mean_frequency_error = correlator_get_mean_frequency_deviation(&rx->preamble_correlator, FREQ_EST_L, &phase_offset);
|
||||
|
||||
printf("Phase offset: %.6f rad\n", phase_offset);
|
||||
printf("Preamble frequency deviation: %.6f rad/symbol\n", mean_frequency_error);
|
||||
DEBUG_LOG("Phase offset: %.6f rad\n", phase_offset);
|
||||
DEBUG_LOG("Preamble frequency deviation: %.6f rad/symbol\n", mean_frequency_error);
|
||||
|
||||
// Set the fine carrier correction NCO to the values estimated from the preamble
|
||||
nco_crcf_set_frequency(rx->carrier_fine_nco, mean_frequency_error / RRC_SPS * 0.5f);
|
||||
nco_crcf_set_phase(rx->carrier_fine_nco, phase_offset);
|
||||
|
||||
printf("New estimated carrier frequency: %.6f + %.6f\n", nco_crcf_get_frequency(rx->carrier_coarse_nco), nco_crcf_get_frequency(rx->carrier_fine_nco));
|
||||
DEBUG_LOG("New estimated carrier frequency: %.6f + %.6f\n", nco_crcf_get_frequency(rx->carrier_coarse_nco), nco_crcf_get_frequency(rx->carrier_fine_nco));
|
||||
|
||||
//float complex input_history[preamble_get_symbol_count()];
|
||||
//correlator_get_input_history(&rx->preamble_correlator, input_history);
|
||||
|
||||
//printf("import numpy as np\n");
|
||||
//printf("import matplotlib.pyplot as pp\n");
|
||||
//DEBUG_LOG("import numpy as np\n");
|
||||
//DEBUG_LOG("import matplotlib.pyplot as pp\n");
|
||||
//print_complex_array("pre", preamble_get_symbols(), preamble_get_symbol_count());
|
||||
//print_complex_array("recv", input_history, preamble_get_symbol_count());
|
||||
//printf("pp.plot(np.angle(recv * pre.conj()))\n");
|
||||
//printf("pp.show()\n");
|
||||
//DEBUG_LOG("pp.plot(np.angle(recv * pre.conj()))\n");
|
||||
//DEBUG_LOG("pp.show()\n");
|
||||
|
||||
// start over with frequency estimation when preamble search restarts.
|
||||
freq_est_history_write_idx = 0;
|
||||
|
@ -71,7 +79,7 @@ static bool acquire_preamble(layer1_rx_t *rx, const float complex sample)
|
|||
float freq_adjustment = (freq_est / RRC_SPS) * 0.3f;
|
||||
nco_crcf_adjust_frequency(rx->carrier_coarse_nco, freq_adjustment);
|
||||
|
||||
printf("Frequency adjustment: %.6f - carrier frequency: %.6f\n", freq_adjustment, nco_crcf_get_frequency(rx->carrier_coarse_nco));
|
||||
DEBUG_LOG("Frequency adjustment: %.6f - carrier frequency: %.6f\n", freq_adjustment, nco_crcf_get_frequency(rx->carrier_coarse_nco));
|
||||
|
||||
freq_est_history_write_idx = 0;
|
||||
}
|
||||
|
@ -123,7 +131,7 @@ result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t
|
|||
modem_demodulate(rx->hdr_demod, mixed_sample, &sym_demod);
|
||||
|
||||
float phase_error = modem_get_demodulator_phase_error(rx->hdr_demod);
|
||||
printf("Sym: %d; Phase error: %f\n", sym_demod, phase_error);
|
||||
DEBUG_LOG("Sym: %d; Phase error: %f\n", sym_demod, phase_error);
|
||||
|
||||
update_nco_pll(rx->carrier_fine_nco, phase_error);
|
||||
|
||||
|
@ -150,10 +158,10 @@ result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t
|
|||
rx->payload_len_enc_bytes = fec_get_enc_msg_length(PAYLOAD_CHANNEL_CODE, rx->payload_len_bytes);
|
||||
rx->payload_len_symbols = (rx->payload_len_enc_bytes * 8 + payload_bps - 1) / payload_bps;
|
||||
|
||||
printf("=== DECODED HEADER ===\n");
|
||||
printf("Payload length: %u symbols, %u bytes encoded, %u bytes decoded\n", rx->payload_len_symbols, rx->payload_len_enc_bytes, rx->payload_len_bytes);
|
||||
printf("CRC16: 0x%04x\n", rx->payload_crc);
|
||||
printf("======================\n");
|
||||
DEBUG_LOG("=== DECODED HEADER ===\n");
|
||||
DEBUG_LOG("Payload length: %u symbols, %u bytes encoded, %u bytes decoded\n", rx->payload_len_symbols, rx->payload_len_enc_bytes, rx->payload_len_bytes);
|
||||
DEBUG_LOG("CRC16: 0x%04x\n", rx->payload_crc);
|
||||
DEBUG_LOG("======================\n");
|
||||
|
||||
//dump_array_cf(symbols_cpx, symbol_counter, 1.0f, "/tmp/hdr.cpx");
|
||||
|
||||
|
@ -169,7 +177,7 @@ result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t
|
|||
modem_demodulate(rx->payload_demod, mixed_sample, &sym_demod);
|
||||
|
||||
float phase_error = modem_get_demodulator_phase_error(rx->payload_demod);
|
||||
printf("Sym: %d; Phase error: %f\n", sym_demod, phase_error);
|
||||
DEBUG_LOG("Sym: %d; Phase error: %f\n", sym_demod, phase_error);
|
||||
|
||||
update_nco_pll(rx->carrier_fine_nco, phase_error);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ result_t layer1_tx_add_packet_to_burst(layer1_tx_t *tx, const uint8_t *data, siz
|
|||
result_t res = transmission_ramp_up(&tx->transmission, get_write_ptr(tx), &len);
|
||||
|
||||
if(res != OK) {
|
||||
printf("Ramp-up requires %zd samples at offset %zd.\n", len, tx->samples_used);
|
||||
fprintf(stderr, "Ramp-up requires %zd samples at offset %zd.\n", len, tx->samples_used);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ result_t layer1_tx_add_packet_to_burst(layer1_tx_t *tx, const uint8_t *data, siz
|
|||
result_t res = transmission_filter_packet(&tx->transmission, msg_mod, nsyms, get_write_ptr(tx), &len);
|
||||
|
||||
if(res != OK) {
|
||||
printf("Packet requires %zd samples at offset %zd.\n", len, tx->samples_used);
|
||||
fprintf(stderr, "Packet requires %zd samples at offset %zd.\n", len, tx->samples_used);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ result_t layer1_tx_finalize_burst(layer1_tx_t *tx)
|
|||
result_t res = transmission_ramp_down(&tx->transmission, get_write_ptr(tx), &len);
|
||||
|
||||
if(res != OK) {
|
||||
printf("Ramp-down requires %zd samples at offset %zd.\n", len, tx->samples_used);
|
||||
fprintf(stderr, "Ramp-down requires %zd samples at offset %zd.\n", len, tx->samples_used);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
#define RESULT_CHECK(stmt) { \
|
||||
result_t res = stmt; \
|
||||
if(res != OK) { \
|
||||
printf("Error %d in %s:%d!", res, __FILE__, __LINE__); \
|
||||
fprintf(stderr, "Error %d in %s:%d!", res, __FILE__, __LINE__); \
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
void print_complex_array(const char *varname, float complex const *array, size_t len)
|
||||
{
|
||||
printf("%s=np.array([%f%+fj", varname, crealf(array[0]), cimagf(array[0]));
|
||||
fprintf(stderr, "%s=np.array([%f%+fj", varname, crealf(array[0]), cimagf(array[0]));
|
||||
for(size_t k = 1; k < len; k++) {
|
||||
printf(", %f%+fj", crealf(array[k]), cimagf(array[k]));
|
||||
fprintf(stderr, ", %f%+fj", crealf(array[k]), cimagf(array[k]));
|
||||
}
|
||||
printf("])\n");
|
||||
fprintf(stderr, "])\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,17 +31,17 @@ void cb_rx(rx_evt_t evt, uint8_t *packet_data, size_t packet_len)
|
|||
switch(evt)
|
||||
{
|
||||
case RX_EVT_CHECKSUM_ERROR:
|
||||
printf("Received a message of %zu bytes, but decoding failed.\n", packet_len);
|
||||
fprintf(stderr, "Received a message of %zu bytes, but decoding failed.\n", packet_len);
|
||||
break;
|
||||
|
||||
case RX_EVT_PACKET_RECEIVED:
|
||||
printf("=== DECODED PAYLOAD ===\n");
|
||||
printf("%s\n", packet_data);
|
||||
printf("=======================\n");
|
||||
fprintf(stderr, "=== DECODED PAYLOAD ===\n");
|
||||
fprintf(stderr, "%s\n", packet_data);
|
||||
fprintf(stderr, "=======================\n");
|
||||
break;
|
||||
|
||||
case RX_EVT_PREAMBLE_FOUND:
|
||||
printf("Found preamble!");
|
||||
fprintf(stderr, "Found preamble!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -95,5 +95,5 @@ int main(void)
|
|||
layer1_tx_shutdown(&tx);
|
||||
layer1_rx_shutdown(&rx);
|
||||
|
||||
printf("Done.\n");
|
||||
fprintf(stderr, "Done.\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue