diff options
Diffstat (limited to 'qmap')
| -rw-r--r-- | qmap/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | qmap/getsvn.cmake | 16 | ||||
| -rw-r--r-- | qmap/libqmap/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | qmap/libqmap/getcand2.f90 | 15 | ||||
| -rw-r--r-- | qmap/libqmap/q65b.f90 | 79 | ||||
| -rw-r--r-- | qmap/libqmap/qmapa.f90 | 9 | ||||
| -rw-r--r-- | qmap/livecq_parser.cpp | 28 | ||||
| -rw-r--r-- | qmap/livecq_parser.h | 7 | ||||
| -rw-r--r-- | qmap/mainwindow.cpp | 91 | ||||
| -rw-r--r-- | qmap/mainwindow.h | 4 | ||||
| -rw-r--r-- | qmap/map65_config.h.in | 4 |
11 files changed, 126 insertions, 130 deletions
diff --git a/qmap/CMakeLists.txt b/qmap/CMakeLists.txt index 4a4e43ba..cf930f04 100644 --- a/qmap/CMakeLists.txt +++ b/qmap/CMakeLists.txt @@ -7,6 +7,7 @@ set (qmap_CXXSRCS getfile.cpp livecq_parser.cpp main.cpp + ../Network/LiveCQUpload.cpp mainwindow.cpp meterwidget.cpp plotter.cpp diff --git a/qmap/getsvn.cmake b/qmap/getsvn.cmake deleted file mode 100644 index d1007b2c..00000000 --- a/qmap/getsvn.cmake +++ /dev/null @@ -1,16 +0,0 @@ -find_package (Subversion) -if (Subversion_FOUND AND EXISTS ${PROJECT_SOURCE_DIR}/.svn) - # the FindSubversion.cmake module is part of the standard distribution - include (FindSubversion) - # extract working copy information for SOURCE_DIR into MY_XXX variables - Subversion_WC_INFO (${SOURCE_DIR} MY) - # write a file with the SVNVERSION define - file (WRITE svnversion.h.txt "#define SVNVERSION ${MY_WC_REVISION}\n") -else (Subversion_FOUND AND EXISTS ${PROJECT_SOURCE_DIR}/.svn) - file (WRITE svnversion.h.txt "#define SVNVERSION local\n") -endif (Subversion_FOUND AND EXISTS ${PROJECT_SOURCE_DIR}/.svn) - -# copy the file to the final header only if the version changes -# reduces needless rebuilds -execute_process (COMMAND ${CMAKE_COMMAND} -E copy_if_different - svnversion.h.txt svnversion.h) diff --git a/qmap/libqmap/CMakeLists.txt b/qmap/libqmap/CMakeLists.txt index 5480486b..44d6e1b2 100644 --- a/qmap/libqmap/CMakeLists.txt +++ b/qmap/libqmap/CMakeLists.txt @@ -2,6 +2,7 @@ set (libq65_FSRCS # Modules come first: qmap_decode_ipc.f90 cacb_mod.f90 + getcand2.f90 # Non-module Fortran routines: astro.f90 @@ -16,7 +17,6 @@ set (libq65_FSRCS ftninit.f90 # ftnquit.f90 geocentric.f90 - getcand2.f90 grid2deg.f90 indexx.f90 lorentzian.f90 diff --git a/qmap/libqmap/getcand2.f90 b/qmap/libqmap/getcand2.f90 index c98c3088..61ecc18c 100644 --- a/qmap/libqmap/getcand2.f90 +++ b/qmap/libqmap/getcand2.f90 @@ -1,8 +1,4 @@ -subroutine getcand2(ss,savg0,nts_q65,nagain,nhsym,ntx30a,ntx30b, & - ntol,f0_selected,bAlso30,cand,ncand2) - -! Get candidates for Q65 decodes, based on presence of sync tone. - +module qmap_candidates_mod type candidate real :: snr !Relative S/N of sync detection real :: f !Freq of sync tone, 0 to 96000 Hz @@ -11,6 +7,13 @@ subroutine getcand2(ss,savg0,nts_q65,nagain,nhsym,ntx30a,ntx30b, & integer :: iseq !0 for first half-minute, 1 for second half end type candidate +contains + +subroutine getcand2(ss,savg0,nts_q65,nagain,nhsym,ntx30a,ntx30b, & + ntol,f0_selected,bAlso30,cand,ncand2) + +! Get candidates for Q65 decodes, based on presence of sync tone. + parameter (NFFT=32768) !FFTs done in symspec() parameter (MAX_CANDIDATES=50) type(candidate) :: cand(MAX_CANDIDATES) @@ -22,6 +25,7 @@ subroutine getcand2(ss,savg0,nts_q65,nagain,nhsym,ntx30a,ntx30b, & logical*1 bAlso30 data nseg/16/,npct/40/ + ncand2=0 if(savg0(NFFT).eq.0) return !Avoid a program crash when spectrum is empty savg=savg0 !Save the original spectrum @@ -117,3 +121,4 @@ subroutine getcand2(ss,savg0,nts_q65,nagain,nhsym,ntx30a,ntx30b, & return end subroutine getcand2 +end module qmap_candidates_mod diff --git a/qmap/libqmap/q65b.f90 b/qmap/libqmap/q65b.f90 index 619f785d..b6234588 100644 --- a/qmap/libqmap/q65b.f90 +++ b/qmap/libqmap/q65b.f90 @@ -1,3 +1,42 @@ +module qmap_q65_samples_mod + use iso_fortran_env, only: int16 + implicit none +contains + subroutine build_q65_samples(k0,nfft2,df,iseq,iwave) + use cacb_mod, only: ca + integer, intent(in) :: k0,nfft2,iseq + real, intent(in) :: df + integer(int16), intent(out) :: iwave(:) + integer, parameter :: MAXFFT2=336000 + complex cx(0:MAXFFT2-1),cz(0:MAXFFT2) + save cx,cz + integer i,j,ja,jb + real fac,r + + fac=1.0/nfft2 + cx(0:nfft2-1)=fac*ca(k0:k0+nfft2-1) + cz(0:MAXFFT2-1)=cx + cz(MAXFFT2)=0. + ja=nint(500.0/df) + jb=nint(2500.0/df) + do i=0,ja + r=0.5*(1.0+cos(i*3.14159/ja)) + cz(ja-i)=r*cz(ja-i) + cz(jb+i)=r*cz(jb+i) + enddo + cz(ja+jb+1:)=0. + + call four2a(cz,2*nfft2,1,1,-1) + do i=0,nfft2-1 + j=nfft2-1-i + iwave(2*i+2)=nint(real(cz(j))) + iwave(2*i+1)=nint(aimag(cz(j))) + enddo + iwave(2*nfft2+1:)=0 + if(iseq.eq.1) iwave(1:360000)=iwave(360001:720000) + end subroutine build_q65_samples +end module qmap_q65_samples_mod + subroutine q65b(nutc,nqd,fcenter,nfcal,nfsample,ikhz,mousedf,ntol, & ntrperiod,iseq,mycall0,hiscall0,hisgrid,mode_q65,f0,fqso,nkhz_center, & newdat,nagain,bClickDecode,max_drift,offset,ndepth,datetime,nCFOM, & @@ -15,7 +54,8 @@ subroutine q65b(nutc,nqd,fcenter,nfcal,nfsample,ikhz,mousedf,ntol, & use qmap_decode_ipc, only: max_decode_rows, decode_row_length, & ndecodes, result, result2 use iso_fortran_env, only: int16 - use cacb_mod, only: ca, init_cacb + use cacb_mod, only: init_cacb + use qmap_q65_samples_mod, only: build_q65_samples parameter (MAXFFT1=5376000) !56*96000 parameter (MAXFFT2=336000) !56*6000 (downsampled by 1/16) @@ -24,7 +64,6 @@ subroutine q65b(nutc,nqd,fcenter,nfcal,nfsample,ikhz,mousedf,ntol, & type(hdr) h integer(int16) iwave(300*12000) integer offset - complex cx(0:MAXFFT2-1),cz(0:MAXFFT2) real*8 fcenter,freq0,freq1 logical*1 bClickDecode character*12 mycall0,hiscall0 @@ -54,39 +93,7 @@ subroutine q65b(nutc,nqd,fcenter,nfcal,nfsample,ikhz,mousedf,ntol, & nh=nfft2/2 k0=nint((ipk*df3-1000.0)/df) if(k0.lt.nh .or. k0.gt.MAXFFT1-nfft2+1) go to 900 - fac=1.0/nfft2 - cx(0:nfft2-1)=fac*ca(k0:k0+nfft2-1) - -! Here cx is frequency-domain data around the selected -! QSO frequency, taken from the full-length FFT computed in fftbig(). -! Values for fsample, nfft1, nfft2, df, and the downsampled data rate -! are as follows: - -! fSample nfft1 df nfft2 fDownSampled -! (Hz) (Hz) (Hz) -!---------------------------------------------------- -! 96000 5376000 0.017857143 336000 6000.000 - - cz(0:MAXFFT2-1)=cx - cz(MAXFFT2)=0. -! Roll off below 500 Hz and above 2500 Hz. - ja=nint(500.0/df) - jb=nint(2500.0/df) - do i=0,ja - r=0.5*(1.0+cos(i*3.14159/ja)) - cz(ja-i)=r*cz(ja-i) - cz(jb+i)=r*cz(jb+i) - enddo - cz(ja+jb+1:)=0. - -!Transform to time domain (real), fsample=12000 Hz - call four2a(cz,2*nfft2,1,1,-1) - do i=0,nfft2-1 - j=nfft2-1-i - iwave(2*i+2)=nint(real(cz(j))) !Note the reversed order! - iwave(2*i+1)=nint(aimag(cz(j))) - enddo - iwave(2*nfft2+1:)=0 + call build_q65_samples(k0,nfft2,df,iseq,iwave) nsubmode=mode_q65-1 nfa=990 !Tight limits around ipk for the wideband decode @@ -97,8 +104,6 @@ subroutine q65b(nutc,nqd,fcenter,nfcal,nfsample,ikhz,mousedf,ntol, & endif nsnr0=-99 !Default snr for no decode - if(iseq.eq.1) iwave(1:360000)=iwave(360001:720000) - csubmode(1:2)='60' csubmode(3:3)=char(ichar('A')+nsubmode) nhhmmss=100*nutc diff --git a/qmap/libqmap/qmapa.f90 b/qmap/libqmap/qmapa.f90 index 2b785622..02ccf2c2 100644 --- a/qmap/libqmap/qmapa.f90 +++ b/qmap/libqmap/qmapa.f90 @@ -7,14 +7,7 @@ subroutine qmapa(dd,ss,savg,newdat,nutc,fcenter,ntol,nfa,nfb, & use timer_module, only: timer use qmap_decode_ipc, only: ndecodes, ncand2 - - type candidate - real :: snr !Relative S/N of sync detection - real :: f !Freq of sync tone, 0 to 96000 Hz - real :: xdt !DT of matching sync pattern, -1.0 to +4.0 s - integer :: ntrperiod !60 for Q65-60x, 30 for Q65-30x - integer :: iseq !0 for first half-minute, 1 for second half - end type candidate + use qmap_candidates_mod, only: candidate, getcand2 type good_decode real :: f !Freq of sync tone, 0 to 96000 Hz diff --git a/qmap/livecq_parser.cpp b/qmap/livecq_parser.cpp index e43ec5ce..6396bf9a 100644 --- a/qmap/livecq_parser.cpp +++ b/qmap/livecq_parser.cpp @@ -92,4 +92,32 @@ namespace QMapLiveCQ record = parsed; return true; } + + QDateTime spotTime(QString const& decodeTime, QDateTime const& nowUtc) + { + if ((decodeTime.size() != 4 && decodeTime.size() != 6) || !nowUtc.isValid()) { + return {}; + } + for (auto const character : decodeTime) { + if (!character.isDigit()) { + return {}; + } + } + QTime const time {decodeTime.mid(0, 2).toInt(), decodeTime.mid(2, 2).toInt(), + decodeTime.size() == 6 ? decodeTime.mid(4, 2).toInt() : 0}; + if (!time.isValid()) { + return {}; + } + + auto const now = nowUtc.toUTC(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QDateTime result {now.date(), time, QTimeZone::UTC}; +#else + QDateTime result {now.date(), time, Qt::UTC}; +#endif + if (result > now.addSecs(60)) { + result = result.addDays(-1); + } + return result; + } } diff --git a/qmap/livecq_parser.h b/qmap/livecq_parser.h index aa80bb10..d1941b0a 100644 --- a/qmap/livecq_parser.h +++ b/qmap/livecq_parser.h @@ -1,6 +1,7 @@ #ifndef QMAP_LIVE_CQ_PARSER_H #define QMAP_LIVE_CQ_PARSER_H +#include <QDateTime> #include <QString> #include <QStringList> @@ -16,6 +17,12 @@ namespace QMapLiveCQ }; bool parse(QStringList const& tokens, int frequencyOffset, Record& record); + + // UTC date and time of a decode whose time is given as "hhmmss" or "hhmm". + // The date is today's (from nowUtc), or yesterday's when that would put the + // decode more than a minute in the future (a period that began before + // midnight). Invalid if the time is malformed. + QDateTime spotTime(QString const& decodeTime, QDateTime const& nowUtc); } #endif diff --git a/qmap/mainwindow.cpp b/qmap/mainwindow.cpp index 7f3b5352..aafce2c6 100644 --- a/qmap/mainwindow.cpp +++ b/qmap/mainwindow.cpp @@ -25,14 +25,11 @@ #include "qmap_ipc.h" #include "qmap_decode_record.h" #include "validators/LiveCQCallsign.hpp" +#include "../Network/LiveCQUpload.hpp" #include <QCoreApplication> //liveCQ -#include <QNetworkAccessManager> //liveCQ -#include <QNetworkRequest> -#include <QNetworkReply> #include <QUrl> #include <QUrlQuery> -#include <QEventLoop> #define NFFT 32768 @@ -378,6 +375,10 @@ void MainWindow::readSettings() } m_w3szUrl=settings.value("w3szUrl",true).toBool(); //liveCQ m_otherUrl=settings.value("otherUrl","").toString(); //liveCQ + m_livecq = std::make_unique<LiveCQUpload>(this); + m_livecq->setUserAgent(http_user_agent().toUtf8()); + connect(m_livecq.get(), &LiveCQUpload::errorOccurred, this, + [](QString const& error) { qDebug() << error; }); ui->fAddComboBox->setVisible(ui->actionFadd_controls->isChecked()); ui->fAdd_label->setVisible(ui->actionFadd_controls->isChecked()); ui->pbSet->setVisible(ui->actionFadd_controls->isChecked()); @@ -1133,7 +1134,7 @@ void MainWindow::CreateLiveCQ(QStringList cqliveText) QStringList bandInfo; bandInfo = ui->labFreq->text().split(".",SkipEmptyParts); QString bandFreq = bandInfo.at(0); - QString theDate = ui->labUTC->text().trimmed().mid(0,12); + auto const nowUtc = QDateTime::currentDateTimeUtc(); QList<QStringList> decodeList; for (const QString &item : cqliveText) { @@ -1142,6 +1143,12 @@ void MainWindow::CreateLiveCQ(QStringList cqliveText) if (!QMapLiveCQ::parse(thePieces, freqOffset, record)) { continue; } + // Built from numbers only: going through the month name shown in labUTC + // failed on non-English Windows and uploaded an empty date. + auto const spotTime = QMapLiveCQ::spotTime(thePieces.at(0), nowUtc); + if (!spotTime.isValid()) { + continue; + } qDebug () << "item is: " << item; if (m_myCall.length() >= 3 && m_myGrid.length() >= 4) { QString theCall = record.callsign; @@ -1162,7 +1169,7 @@ void MainWindow::CreateLiveCQ(QStringList cqliveText) thePostLine.insert(8, theCall); //dx call thePostLine.insert(9, theGrid); //dx grid thePostLine.insert(10, m_myGrid.toUpper()); //myGrid - thePostLine.insert(11, theDate); //the date + thePostLine.insert(11, spotTime.toString("yyyy-MM-ddTHH:mm:ss") + "Z"); //utc date and time thePostLine.insert(12, m_myCall.toUpper()); //myCall thePostLine.insert(13, "--"); //txpol decodeList.append(thePostLine); @@ -1184,64 +1191,32 @@ void MainWindow::sendLiveCQData(QList<QStringList>decodeList) theUrl = m_otherUrl; } - QNetworkAccessManager *manager = new QNetworkAccessManager(this); - QUrl url(theUrl); - QNetworkRequest request(url); - QByteArray userAgent = (QCoreApplication::applicationName() + " v" - + QCoreApplication::applicationVersion()).toUtf8(); - request.setRawHeader("User-Agent", userAgent); - request.setRawHeader("X-Custom-User-Agent", userAgent); - request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + if (!m_livecq->setEndpoint(QUrl {theUrl})) return; for (const QStringList &thePostLine : decodeList) { - QString utcdatetimestringOriginal = thePostLine.at(11) + " " + thePostLine.at(3); - QDateTime utcdatetimeUTC = QDateTime::fromString(utcdatetimestringOriginal, "yyyy MMM dd HHmmss"); - utcdatetimeUTC.setTimeSpec((Qt::UTC)); - QString utcdatetimeUTCString = utcdatetimeUTC.toString("yyyy-MM-ddTHH:mm:ss"); - utcdatetimeUTCString = utcdatetimeUTCString + "Z"; - - QString postString = "skedfreq=" + thePostLine.at(0) + "&rxfreq=" + thePostLine.at(1) + "&rpol=" + thePostLine.at(2) + "&dt=" + thePostLine.at(4) + "&dB=" + thePostLine.at(5) + "&msgtype=" + thePostLine.at(7) + "&callsign=" + thePostLine.at(8) + "&grid=" + thePostLine.at(9) + "&mode=" + thePostLine.at(6) + "&utcdatetime=" + utcdatetimeUTCString + "&spotter=" + thePostLine.at(12) + "&spottergrid=" + thePostLine.at(10) + "&txpol=" + thePostLine.at(13) + "&apptype=QMAP"; - - QByteArray postByteArray = postString.toUtf8(); - request.setRawHeader("Content-Length",QByteArray::number(postByteArray.size())); - - - try { - QNetworkReply *reply = manager->post(request,postByteArray); - QObject::connect(reply, &QNetworkReply::finished, this, &MainWindow::handleReply); - } - catch (const std::exception& e) { - // Handle standard C++ exceptions - QMessageBox::critical(this, "Exception", "Exception at line 1165 MainWindow::sendLiveCQData " + QString::fromStdString(e.what())); - } - catch (...) { - // Handle any other type of exception - QMessageBox::critical(this, "Exception", "Unknown Exception at line 1170 MainWindow::sendLiveCQData"); - } + QString utcdatetimeUTCString = thePostLine.at(11); + + QUrlQuery query; + query.addQueryItem("skedfreq", thePostLine.at(0)); + query.addQueryItem("rxfreq", thePostLine.at(1)); + query.addQueryItem("rpol", thePostLine.at(2)); + query.addQueryItem("dt", thePostLine.at(4)); + query.addQueryItem("dB", thePostLine.at(5)); + query.addQueryItem("msgtype", thePostLine.at(7)); + query.addQueryItem("callsign", thePostLine.at(8)); + query.addQueryItem("grid", thePostLine.at(9)); + query.addQueryItem("mode", thePostLine.at(6)); + query.addQueryItem("utcdatetime", utcdatetimeUTCString); + query.addQueryItem("spotter", thePostLine.at(12)); + query.addQueryItem("spottergrid", thePostLine.at(10)); + query.addQueryItem("txpol", thePostLine.at(13)); + query.addQueryItem("apptype", "QMAP"); + + m_livecq->postSpot(query); } } -void MainWindow::handleReply() -{ - try { - QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); - if (reply->error() == QNetworkReply::NoError) { - qDebug() << reply->readAll(); - } else { - qDebug() << reply->errorString(); - } - } - catch (const std::exception& e) { - // Handle standard C++ exceptions - QMessageBox::critical(this, "Exception", "Exception at line 1188 MainWindow::handleReply " + QString::fromStdString(e.what())); - } - catch (...) { - // Handle any other type of exception - QMessageBox::critical(this, "Exception", "Unknown Exception at line 1193 MainWindow::handleReply"); - } -} - //------------------------------------------------------------- //guiUpdate() void MainWindow::guiUpdate() diff --git a/qmap/mainwindow.h b/qmap/mainwindow.h index 8c71c4d5..7ad76d5c 100644 --- a/qmap/mainwindow.h +++ b/qmap/mainwindow.h @@ -7,6 +7,7 @@ #include <QLabel> #include <QDateTime> #include <QHash> +#include <memory> #include "getfile.h" #include "soundin.h" #include "signalmeter.h" @@ -26,6 +27,7 @@ class QTimer; class Astro; class WideGraph; class VertWaterfall; +class LiveCQUpload; enum class DecodeClickGesture; class MainWindow : public QMainWindow @@ -98,7 +100,6 @@ private slots: void on_fAddComboBox_activated(); void on_pbSet_clicked(); void on_pbAdd_clicked(); - void handleReply(); //liveCQ private: Ui::MainWindow *ui; @@ -200,6 +201,7 @@ private: SoundInThread soundInThread; //Instantiate the audio threads bool doLiveCQ = true; //liveCQ QFile *cqlfi; //liveCQ + std::unique_ptr<LiveCQUpload> m_livecq; //---------------------------------------------------- private functions void readSettings(); diff --git a/qmap/map65_config.h.in b/qmap/map65_config.h.in deleted file mode 100644 index ffb97175..00000000 --- a/qmap/map65_config.h.in +++ /dev/null @@ -1,4 +0,0 @@ -#include "svnversion.h" - -#define MAP65_VERSION_MAJOR @MAP65_VERSION_MAJOR@ -#define MAP65_VERSION_MINOR @MAP65_VERSION_MINOR@ |
