From e87704f1198929472b036d9f3d7b6eb98551fdb7 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Wed, 6 May 2020 20:08:30 -0400 Subject: [PATCH] Experiments in computing and setting drift automatically --- lib/js8/js8a_params.f90 | 2 +- lib/js8/js8dec.f90 | 5 ++-- mainwindow.cpp | 59 ++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/lib/js8/js8a_params.f90 b/lib/js8/js8a_params.f90 index 44db61b..e98959f 100644 --- a/lib/js8/js8a_params.f90 +++ b/lib/js8/js8a_params.f90 @@ -2,7 +2,7 @@ parameter (NCOSTAS=1) !Which JS8 Costas Arrays to use (1=original, 2=three symmetrical costas) -parameter (NSPS=1920, NTXDUR=15, NDOWNSPS=32, NDD=100, JZ=32) ! 50 Hz 6.250 baud 16 wpm -25.0dB (1.0Eb/N0) 12.64s +parameter (NSPS=1920, NTXDUR=15, NDOWNSPS=32, NDD=100, JZ=36) ! 50 Hz 6.250 baud 16 wpm -25.0dB (1.0Eb/N0) 12.64s parameter (AZ=12000.0/(1.0*NSPS)*0.64d0) !Dedupe overlap in Hz parameter (ASTART=0.5) !Start delay in seconds diff --git a/lib/js8/js8dec.f90 b/lib/js8/js8dec.f90 index af73b12..d3e123c 100644 --- a/lib/js8/js8dec.f90 +++ b/lib/js8/js8dec.f90 @@ -225,7 +225,7 @@ subroutine js8dec(dd0,icos,newdat,synconly,nQSOProgress,nfqso,nftx,ndepth,lapon, endif if(synconly) then - write(*,*) ' candidate X ', 'f', f1, 'sync', nsync, 'xdt', xdt + write(*,*) ' candidate X ', 'f1', f1, 'sync', nsync, 'xdt', xdt flush(6) endif @@ -424,9 +424,8 @@ subroutine js8dec(dd0,icos,newdat,synconly,nQSOProgress,nfqso,nftx,ndepth,lapon, if(nbadcrc.eq.0) then if(synconly) then - write(*,*) ' decode X ', 'f1', f1, 'sync', sync, 'xdt', xdt2 + write(*,*) ' decode X ', 'f1', f1, 'sync', (sync*10), 'xdt', xdt2 flush(6) - return endif decoded0=decoded diff --git a/mainwindow.cpp b/mainwindow.cpp index 963e6f7..4d70593 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4872,6 +4872,10 @@ void MainWindow::processDecodedLine(QByteArray t){ bool bAvgMsg=false; int navg=0; + + static bool hasNewDrift = false; + static int newDrift = 0; + if(t.indexOf("") >= 0) { if(t.indexOf("f1") >= 0){ auto segs = QString(t.trimmed()).split(QRegExp("[\\s\\t]+"), QString::SkipEmptyParts); @@ -4885,37 +4889,36 @@ void MainWindow::processDecodedLine(QByteArray t){ auto xdt1 = QString(segs.at(8)); auto xdt = int(xdt1.toFloat()); - if(abs(xdt) <= 1.28){ - //if(s > 7 && s < 10){ - // m_wideGraph->drawLine(QColor(Qt::white), f, f + computeBandwidthForSubmode(m_nSubMode)); - //} else if (s < 15){ - // m_wideGraph->drawLine(QColor(Qt::darkMagenta), f, f + computeBandwidthForSubmode(m_nSubMode)); - //} else { - /* - int secs = DriftingDateTime::currentDateTimeUtc().secsTo(nextTransmitCycle()); - int txtime = computeFramesNeededForDecode(m_nSubMode)/RX_SAMPLE_RATE; - qDebug() << "seconds til transmit" << secs << "time offset" << xdt << "potential drift" << (secs-xdt)*1000; - setDrift((secs+xdt-txtime)*1000); - */ + if(abs(xdt) <= 2){ + if(s < 10){ + m_wideGraph->drawLine(QColor(Qt::darkCyan), f, f + computeBandwidthForSubmode(m_nSubMode)); + } else if (s <= 21){ + m_wideGraph->drawLine(QColor(Qt::white), f, f + computeBandwidthForSubmode(m_nSubMode)); + } + } + + if(t.contains("decode X")){ auto now = QDateTime::currentDateTimeUtc(); - int n = 0; - int nPos = m_TRperiod - (now.time().second() % m_TRperiod); - int nNeg = (now.time().second() % m_TRperiod) - m_TRperiod; + float n = 0; + float nPos = m_TRperiod - (now.time().second() % m_TRperiod); + float nNeg = (now.time().second() % m_TRperiod) - m_TRperiod; + float offset = m_TRperiod - computeFramesNeededForDecode(m_nSubMode)/RX_SAMPLE_RATE + xdt; - if(abs(nNeg) < nPos){ - n = nNeg; + if(qAbs(nNeg) < nPos){ + n = nNeg + offset; } else { - n = nPos; + n = nPos - offset; } + int xdtmin = qMin(n*1000, (float)DriftingDateTime::drift()); + int xdtmax = qMax(n*1000, (float)DriftingDateTime::drift()); - int xdtmin = qMin(n*1000, (int)DriftingDateTime::drift()); - int xdtmax = qMax(n*1000, (int)DriftingDateTime::drift()); - setDrift(xdtmin + (xdtmax-xdtmin)/2); - - m_wideGraph->drawLine(QColor(Qt::red), f, f + computeBandwidthForSubmode(m_nSubMode)); - //} + m_wideGraph->drawLine(QColor(Qt::red), f, f + computeBandwidthForSubmode(m_nSubMode)); + int oldNewDrift = newDrift; + newDrift = (xdtmin + (xdtmax-xdtmin)/2); + newDrift = qMin(oldNewDrift, newDrift) + (qMax(oldNewDrift, newDrift)-qMin(oldNewDrift, newDrift))/2; + hasNewDrift = true; } } } @@ -4931,6 +4934,14 @@ void MainWindow::processDecodedLine(QByteArray t){ } if(t.indexOf("") >= 0) { + + if(hasNewDrift){ + int oldDrift = DriftingDateTime::drift(); + newDrift = qMin(oldDrift, newDrift) + (qMax(oldDrift, newDrift)-qMin(oldDrift, newDrift))/2; + setDrift(newDrift); + hasNewDrift = false; + } + m_bDecoded = t.mid(16).trimmed().toInt() > 0; int mswait=3*1000*m_TRperiod/4; if(!m_diskData) killFileTimer.start(mswait); //Kill in 3/4 period