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:
parent
ff7a28ff59
commit
4304013d62
|
|
@ -36,6 +36,9 @@
|
||||||
using namespace M17;
|
using namespace M17;
|
||||||
|
|
||||||
#ifdef ENABLE_DEMOD_LOG
|
#ifdef ENABLE_DEMOD_LOG
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int16_t sample;
|
int16_t sample;
|
||||||
|
|
@ -56,10 +59,14 @@ log_entry_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static RingBuffer< log_entry_t, LOG_QUEUE > logBuf;
|
static RingBuffer< log_entry_t, LOG_QUEUE > logBuf;
|
||||||
|
static std::atomic_bool dumpData;
|
||||||
static bool logRunning;
|
static bool logRunning;
|
||||||
|
static bool trigEnable;
|
||||||
|
static bool triggered;
|
||||||
|
static uint8_t trigCnt;
|
||||||
static pthread_t logThread;
|
static pthread_t logThread;
|
||||||
|
|
||||||
void *logFunc(void *arg)
|
static void *logFunc(void *arg)
|
||||||
{
|
{
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
|
|
@ -68,25 +75,39 @@ void *logFunc(void *arg)
|
||||||
fprintf(csv_log, "Sample,Convolution,Threshold,Index,Max,Min,Symbol,I\n");
|
fprintf(csv_log, "Sample,Convolution,Threshold,Index,Max,Min,Symbol,I\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint8_t emptyCtr = 0;
|
||||||
|
|
||||||
while(logRunning)
|
while(logRunning)
|
||||||
{
|
{
|
||||||
log_entry_t entry;
|
if(dumpData)
|
||||||
logBuf.pop(entry, true);
|
{
|
||||||
|
// Log up to four entries filled with zeroes before terminating
|
||||||
|
// the dump.
|
||||||
|
log_entry_t entry;
|
||||||
|
memset(&entry, 0x00, sizeof(log_entry_t));
|
||||||
|
if(logBuf.pop(entry, false) == false) emptyCtr++;
|
||||||
|
|
||||||
#ifdef PLATFORM_LINUX
|
if(emptyCtr >= 4)
|
||||||
fprintf(csv_log, "%" PRId16 ",%d,%f,%d,%f,%f,%d,%d\n",
|
{
|
||||||
entry.sample,
|
dumpData = false;
|
||||||
entry.conv,
|
emptyCtr = 0;
|
||||||
entry.conv_th,
|
}
|
||||||
entry.sample_index,
|
|
||||||
entry.qnt_pos_avg,
|
#ifdef PLATFORM_LINUX
|
||||||
entry.qnt_neg_avg,
|
fprintf(csv_log, "%" PRId16 ",%d,%f,%d,%f,%f,%d,%d\n",
|
||||||
entry.symbol,
|
entry.sample,
|
||||||
entry.frame_index);
|
entry.conv,
|
||||||
fflush(csv_log);
|
entry.conv_th,
|
||||||
#else
|
entry.sample_index,
|
||||||
vcom_writeBlock(&entry, sizeof(log_entry_t));
|
entry.qnt_pos_avg,
|
||||||
#endif
|
entry.qnt_neg_avg,
|
||||||
|
entry.symbol,
|
||||||
|
entry.frame_index);
|
||||||
|
fflush(csv_log);
|
||||||
|
#else
|
||||||
|
vcom_writeBlock(&entry, sizeof(log_entry_t));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PLATFORM_LINUX
|
#ifdef PLATFORM_LINUX
|
||||||
|
|
@ -95,6 +116,29 @@ void *logFunc(void *arg)
|
||||||
|
|
||||||
return NULL;
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -130,6 +174,10 @@ void M17Demodulator::init()
|
||||||
|
|
||||||
#ifdef ENABLE_DEMOD_LOG
|
#ifdef ENABLE_DEMOD_LOG
|
||||||
logRunning = true;
|
logRunning = true;
|
||||||
|
triggered = false;
|
||||||
|
dumpData = false;
|
||||||
|
trigEnable = false;
|
||||||
|
trigCnt = 0;
|
||||||
pthread_create(&logThread, NULL, logFunc, NULL);
|
pthread_create(&logThread, NULL, logFunc, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +319,7 @@ sync_t M17Demodulator::nextFrameSync(int32_t offset)
|
||||||
0.0,0.0,0,0
|
0.0,0.0,0,0
|
||||||
};
|
};
|
||||||
|
|
||||||
logBuf.push(log, false);
|
pushLog(log);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Positive correlation peak -> frame syncword
|
// Positive correlation peak -> frame syncword
|
||||||
|
|
@ -346,7 +394,7 @@ int32_t M17Demodulator::syncwordSweep(int32_t offset)
|
||||||
0.0,0.0,0,0
|
0.0,0.0,0,0
|
||||||
};
|
};
|
||||||
|
|
||||||
logBuf.push(log, false);
|
pushLog(log);
|
||||||
#endif
|
#endif
|
||||||
if (conv > max_conv)
|
if (conv > max_conv)
|
||||||
{
|
{
|
||||||
|
|
@ -426,7 +474,7 @@ bool M17Demodulator::update()
|
||||||
frame_index
|
frame_index
|
||||||
};
|
};
|
||||||
|
|
||||||
logBuf.push(log, false);
|
pushLog(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -457,10 +505,24 @@ bool M17Demodulator::update()
|
||||||
frame_index = 0;
|
frame_index = 0;
|
||||||
newFrame = true;
|
newFrame = true;
|
||||||
phase = 0;
|
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
|
// Correct syncword found
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_DEMOD_LOG
|
||||||
|
trigEnable = true;
|
||||||
|
#endif
|
||||||
locked = true;
|
locked = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locate syncword to correct clock skew between Tx and Rx
|
// Locate syncword to correct clock skew between Tx and Rx
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue