Reorganised logging inside M17 demodulator, logging is disabled by default.

On non-linux devices log data is printed on the serial port in raw binary format.
pull/68/head
Silvano Seva 2022-05-13 14:43:26 +02:00
rodzic 6be567a781
commit 1f77c2af6c
2 zmienionych plików z 84 dodań i 56 usunięć

Wyświetl plik

@ -136,17 +136,6 @@ private:
uint8_t lsf_syncword_bytes[2] = {0x55, 0xf7}; uint8_t lsf_syncword_bytes[2] = {0x55, 0xf7};
uint8_t stream_syncword_bytes[2] = {0xff, 0x5d}; uint8_t stream_syncword_bytes[2] = {0xff, 0x5d};
typedef struct {
int16_t sample;
int32_t conv;
float conv_th;
int32_t sample_index;
float qnt_pos_avg;
float qnt_neg_avg;
int32_t symbol;
int32_t frame_index;
} demod_log;
/* /*
* Buffers * Buffers
*/ */
@ -162,9 +151,6 @@ private:
bool newFrame; ///< A new frame has been fully decoded. bool newFrame; ///< A new frame has been fully decoded.
int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer
uint16_t phase; ///< Phase of the signal w.r.t. sampling uint16_t phase; ///< Phase of the signal w.r.t. sampling
#ifdef PLATFORM_LINUX
FILE *csv_log; ///< Used under Linux to hold the log file
#endif
/* /*
* State variables * State variables
@ -256,11 +242,6 @@ private:
*/ */
uint8_t hammingDistance(uint8_t x, uint8_t y); uint8_t hammingDistance(uint8_t x, uint8_t y);
/**
* Append a sample to the log
*/
void appendLog(demod_log *log);
}; };
} /* M17 */ } /* M17 */

Wyświetl plik

@ -24,19 +24,74 @@
#include <M17/M17DSP.h> #include <M17/M17DSP.h>
#include <M17/M17Utils.h> #include <M17/M17Utils.h>
#include <interfaces/audio_stream.h> #include <interfaces/audio_stream.h>
#include <interfaces/gpio.h>
#include <math.h> #include <math.h>
#include <cstring> #include <cstring>
#include <stdio.h> #include <stdio.h>
#include <interfaces/graphics.h>
#include <deque> #include <deque>
#include <ringbuf.h>
#include <usb_vcom.h>
#ifdef PLATFORM_LINUX // #define ENABLE_DEMOD_LOG
#include <emulator.h>
#endif
using namespace M17; using namespace M17;
#ifdef ENABLE_DEMOD_LOG
typedef struct
{
int16_t sample;
int32_t conv;
float conv_th;
int32_t sample_index;
float qnt_pos_avg;
float qnt_neg_avg;
int32_t symbol;
int32_t frame_index;
}
log_entry_t;
static RingBuffer< log_entry_t, 128 > logBuf;
static bool logRunning;
static pthread_t logThread;
void *logFunc(void *arg)
{
(void) arg;
#ifdef PLATFORM_LINUX
FILE *csv_log = fopen("demod_log.csv", "w");
fprintf(csv_log, "Sample,Convolution,Threshold,Index,Max,Min,Symbol,I\n");
#endif
while(logRunning)
{
log_entry_t entry;
logBuf.pop(entry, true);
#ifdef PLATFORM_LINUX
fprintf(csv_log, "%" PRId16 ",%d,%f,%d,%f,%f,%d,%d\n",
entry.sample,
entry.conv,
entry.conv_th,
entry.sample_index,
entry.qnt_pos_avg,
entry.qnt_neg_avg,
entry.symbol,
entry.frame_index);
fflush(csv_log);
#else
vcom_writeBlock(&entry, sizeof(log_entry_t));
#endif
}
#ifdef PLATFORM_LINUX
fclose(csv_log);
#endif
return NULL;
}
#endif
M17Demodulator::M17Demodulator() M17Demodulator::M17Demodulator()
{ {
@ -67,10 +122,10 @@ void M17Demodulator::init()
locked = false; locked = false;
newFrame = false; newFrame = false;
#ifdef PLATFORM_LINUX #ifdef ENABLE_DEMOD_LOG
csv_log = fopen("demod_log.csv", "w"); logRunning = true;
fprintf(csv_log, "Sample,Convolution,Threshold,Index,Max,Min,Symbol,I\n"); pthread_create(&logThread, NULL, logFunc, NULL);
#endif // PLATFORM_MOD17 #endif
} }
void M17Demodulator::terminate() void M17Demodulator::terminate()
@ -80,8 +135,9 @@ void M17Demodulator::terminate()
delete activeFrame; delete activeFrame;
delete[] rawFrame; delete[] rawFrame;
delete idleFrame; delete idleFrame;
#ifdef PLATFORM_LINUX
fclose(csv_log); #ifdef ENABLE_DEMOD_LOG
logRunning = false;
#endif #endif
} }
@ -188,14 +244,19 @@ sync_t M17Demodulator::nextFrameSync(int32_t offset)
int32_t conv = convolution(i, stream_syncword, M17_SYNCWORD_SYMBOLS); int32_t conv = convolution(i, stream_syncword, M17_SYNCWORD_SYMBOLS);
updateCorrelationStats(conv); updateCorrelationStats(conv);
#ifdef ENABLE_DEMOD_LOG
// Log syncword search // Log syncword search
demod_log log = { log_entry_t log =
{
(i < 0) ? basebandBridge[M17_BRIDGE_SIZE + i] : baseband.data[i], (i < 0) ? basebandBridge[M17_BRIDGE_SIZE + i] : baseband.data[i],
conv, conv,
CONV_THRESHOLD_FACTOR * getCorrelationStddev(), CONV_THRESHOLD_FACTOR * getCorrelationStddev(),
i, i,
0.0,0.0,0,0}; 0.0,0.0,0,0
appendLog(&log); };
logBuf.push(log, false);
#endif
// Positive correlation peak -> frame syncword // Positive correlation peak -> frame syncword
if (conv > (getCorrelationStddev() * CONV_THRESHOLD_FACTOR)) if (conv > (getCorrelationStddev() * CONV_THRESHOLD_FACTOR))
@ -248,25 +309,6 @@ uint8_t M17Demodulator::hammingDistance(uint8_t x, uint8_t y)
return __builtin_popcount(x ^ y); return __builtin_popcount(x ^ y);
} }
#ifdef PLATFORM_LINUX
void M17Demodulator::appendLog(demod_log *log) {
fprintf(csv_log, "%" PRId16 ",%d,%f,%d,%f,%f,%d,%d\n",
log->sample,
log->conv,
log->conv_th,
log->sample_index,
log->qnt_pos_avg,
log->qnt_neg_avg,
log->symbol,
log->frame_index);
fflush(csv_log);
}
#else
void M17Demodulator::appendLog(demod_log *log) {
// TODO: Add log to circular queue
}
#endif
bool M17Demodulator::update() bool M17Demodulator::update()
{ {
M17::sync_t syncword = { 0, false }; M17::sync_t syncword = { 0, false };
@ -318,22 +360,27 @@ bool M17Demodulator::update()
updateQuantizationStats(frame_index, symbol_index); updateQuantizationStats(frame_index, symbol_index);
int8_t symbol = quantize(symbol_index); int8_t symbol = quantize(symbol_index);
#ifdef ENABLE_DEMOD_LOG
// Log quantization // Log quantization
for (int i = -2; i <= 2; i++) for (int i = -2; i <= 2; i++)
{ {
if ((symbol_index + i) >= 0 && if ((symbol_index + i) >= 0 &&
(symbol_index + i) < static_cast<int32_t> (baseband.len)) (symbol_index + i) < static_cast<int32_t> (baseband.len))
{ {
demod_log log = { log_entry_t log =
{
baseband.data[symbol_index + i], baseband.data[symbol_index + i],
0,0.0,symbol_index + i, 0,0.0,symbol_index + i,
qnt_pos_avg / 2.0f, qnt_pos_avg / 2.0f,
qnt_neg_avg / 2.0f, qnt_neg_avg / 2.0f,
symbol, symbol,
frame_index}; frame_index
appendLog(&log); };
logBuf.push(log, false);
} }
} }
#endif
setSymbol<M17_FRAME_BYTES>(*activeFrame, frame_index, symbol); setSymbol<M17_FRAME_BYTES>(*activeFrame, frame_index, symbol);
decoded_syms++; decoded_syms++;