From 60b0c5b98442d0da7529069ff2d598d345e9f89c Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Tue, 13 Jul 2021 12:48:28 -0400 Subject: [PATCH] Implement mock real-time input for MAP65: read data from a .tf2 file, with appropriate delays to approximate real-time data rate. --- map65/libm65/CMakeLists.txt | 1 + map65/soundin.cpp | 68 +++++++++++++++++++++++++++++++++++-- map65/soundin.h | 3 ++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/map65/libm65/CMakeLists.txt b/map65/libm65/CMakeLists.txt index fe5ee170c..826459094 100644 --- a/map65/libm65/CMakeLists.txt +++ b/map65/libm65/CMakeLists.txt @@ -62,6 +62,7 @@ set (libm65_FSRCS packjt.f90 pfxdump.f90 polfit.f90 + read_tf2.f90 recvpkt.f90 rfile3a.f90 s3avg.f90 diff --git a/map65/soundin.cpp b/map65/soundin.cpp index 0e50f2935..d82efb5d7 100644 --- a/map65/soundin.cpp +++ b/map65/soundin.cpp @@ -164,10 +164,16 @@ void SoundInThread::run() //SoundInThread::run() { quitExecution = false; + QFile f("mockRTfiles.txt"); + m_mockRT=f.exists(); + + if(m_mockRT) { + inputMockRT(); //"Mock realtime" input from a .tf2 file + return; + } + if (m_net) { -// qDebug() << "Start inputUDP()"; - inputUDP(); -// qDebug() << "Finished inputUDP()"; + inputUDP(); //Network input from Linrad (or equivalent) return; } @@ -449,3 +455,59 @@ void SoundInThread::inputUDP() } delete udpSocket; } + + +//--------------------------------------------------------------- inputMockRT() +void SoundInThread::inputMockRT() +{ + bool qe = quitExecution; + int ntr0=99; + int k=0; + int nsec; + int ntr; + int nhsym0=0; + int iz=174; + int nBusy=0; + int mstr=0; + int mswait=0; + + // Main loop for mock realtime input of data from .tf2 files + while (!qe) { + qe = quitExecution; + if (qe) break; + qint64 ms = QDateTime::currentMSecsSinceEpoch(); // Time according to this computer + mstr = ms % (1000*m_TRperiod); + nsec = (ms % 86400000l) / 1000; + ntr = nsec % m_TRperiod; + +// Reset buffer pointer and symbol number at start of minute + if(ntr < ntr0 or !m_monitoring or m_TRperiod!=m_TRperiod0) { + k=0; + nhsym0=0; + m_TRperiod0=m_TRperiod; + } + ntr0=ntr; + + if(m_monitoring) { + // If buffer will not overflow, move data into datcom_ + if ((k+iz) <= 60*96000) { + if(k>mstr*96) { + mswait=(k-mstr*96)/96; + msleep(mswait); + } + read_tf2_(&k); + } + m_hsym=(k-2048)*11025.0/(2048.0*m_rate); + if(m_hsym != nhsym0) { + if(m_dataSinkBusy) { + nBusy++; + } else { + m_dataSinkBusy=true; + emit readyForFFT(k); //Signal to compute new FFTs + } + nhsym0=m_hsym; + } + } + } +} + diff --git a/map65/soundin.h b/map65/soundin.h index 369cf1d71..98261e05e 100644 --- a/map65/soundin.h +++ b/map65/soundin.h @@ -56,6 +56,7 @@ public slots: private: void inputUDP(); + void inputMockRT(); double m_fAdd; bool m_net; @@ -63,6 +64,7 @@ private: bool m_bForceCenterFreq; bool m_IQswap; bool m_10db; + bool m_mockRT; double m_dForceCenterFreq; qint32 m_nrx; qint32 m_hsym; @@ -77,6 +79,7 @@ private: extern "C" { void recvpkt_(int* nsam, quint16* iblk, qint8* nrx, int* k, double s1[], double s2[], double s3[]); + void read_tf2_(int* k); } #endif // SOUNDIN_H