Updated M17 demodulator debug logger: now log data is continously updated and dumped only in case of a missed sync after lock has been acquired.

This commit is contained in:
Silvano Seva 2022-05-24 12:23:51 +02:00
parent ff7a28ff59
commit 4304013d62
1 changed files with 82 additions and 20 deletions

View File

@ -36,6 +36,9 @@
using namespace M17;
#ifdef ENABLE_DEMOD_LOG
#include <atomic>
typedef struct
{
int16_t sample;
@ -56,10 +59,14 @@ log_entry_t;
#endif
static RingBuffer< log_entry_t, LOG_QUEUE > logBuf;
static std::atomic_bool dumpData;
static bool logRunning;
static bool trigEnable;
static bool triggered;
static uint8_t trigCnt;
static pthread_t logThread;
void *logFunc(void *arg)
static void *logFunc(void *arg)
{
(void) arg;
@ -68,10 +75,23 @@ void *logFunc(void *arg)
fprintf(csv_log, "Sample,Convolution,Threshold,Index,Max,Min,Symbol,I\n");
#endif
uint8_t emptyCtr = 0;
while(logRunning)
{
if(dumpData)
{
// Log up to four entries filled with zeroes before terminating
// the dump.
log_entry_t entry;
logBuf.pop(entry, true);
memset(&entry, 0x00, sizeof(log_entry_t));
if(logBuf.pop(entry, false) == false) emptyCtr++;
if(emptyCtr >= 4)
{
dumpData = false;
emptyCtr = 0;
}
#ifdef PLATFORM_LINUX
fprintf(csv_log, "%" PRId16 ",%d,%f,%d,%f,%f,%d,%d\n",
@ -88,6 +108,7 @@ void *logFunc(void *arg)
vcom_writeBlock(&entry, sizeof(log_entry_t));
#endif
}
}
#ifdef PLATFORM_LINUX
fclose(csv_log);
@ -95,6 +116,29 @@ void *logFunc(void *arg)
return NULL;
}
static inline void pushLog(const log_entry_t& e)
{
/*
* 1) do not push data to log while dump is in progress
* 2) if triggered, increase the counter
* 3) log twenty entries after the trigger and then start dump
* 4) if buffer is full, erase the oldest element
* 5) push data without blocking
*/
if(dumpData) return;
if(triggered) trigCnt++;
if(trigCnt >= 20)
{
dumpData = true;
triggered = false;
trigCnt = 0;
}
if(logBuf.full()) logBuf.eraseElement();
logBuf.push(e, false);
}
#endif
@ -130,6 +174,10 @@ void M17Demodulator::init()
#ifdef ENABLE_DEMOD_LOG
logRunning = true;
triggered = false;
dumpData = false;
trigEnable = false;
trigCnt = 0;
pthread_create(&logThread, NULL, logFunc, NULL);
#endif
}
@ -271,7 +319,7 @@ sync_t M17Demodulator::nextFrameSync(int32_t offset)
0.0,0.0,0,0
};
logBuf.push(log, false);
pushLog(log);
#endif
// Positive correlation peak -> frame syncword
@ -346,7 +394,7 @@ int32_t M17Demodulator::syncwordSweep(int32_t offset)
0.0,0.0,0,0
};
logBuf.push(log, false);
pushLog(log);
#endif
if (conv > max_conv)
{
@ -426,7 +474,7 @@ bool M17Demodulator::update()
frame_index
};
logBuf.push(log, false);
pushLog(log);
}
}
#endif
@ -457,11 +505,25 @@ bool M17Demodulator::update()
frame_index = 0;
newFrame = true;
phase = 0;
#ifdef ENABLE_DEMOD_LOG
// Trigger a data dump when lock is lost.
if((dumpData == false) && (trigEnable == true))
{
trigEnable = false;
triggered = true;
}
#endif
}
// Correct syncword found
else
{
#ifdef ENABLE_DEMOD_LOG
trigEnable = true;
#endif
locked = true;
}
}
// Locate syncword to correct clock skew between Tx and Rx
if (frame_index == M17_SYNCWORD_SYMBOLS + SYNC_SWEEP_OFFSET)