diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:49 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:49 +0200 |
| commit | 76956486fa7ef52a51d4e56df1e13a9f19a6c93c (patch) | |
| tree | fe0c394439fdc167d1970372e8998874090854dd /map65/mainwindow.cpp | |
| parent | 0685fcada9f95fe90f70b387cd7d757da8209624 (diff) | |
| parent | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (diff) | |
Update upstream source from tag 'upstream/3.3.0_beta1+dfsg'
Update to upstream version '3.3.0~beta1+dfsg'
with Debian dir 85037bbb9376721108594b59b54ead82ac6924a3
Diffstat (limited to 'map65/mainwindow.cpp')
| -rw-r--r-- | map65/mainwindow.cpp | 287 |
1 files changed, 128 insertions, 159 deletions
diff --git a/map65/mainwindow.cpp b/map65/mainwindow.cpp index 3cb1e760..e9a0e6d6 100644 --- a/map65/mainwindow.cpp +++ b/map65/mainwindow.cpp @@ -30,11 +30,11 @@ #include <QApplication> #include <QDebug> #include <QDateTime> -#include <QTime> #include <QFile> #include <QTextStream> #include <QString> #include <QByteArray> +#include <QElapsedTimer> //#include <io.h> #include <stdio.h> @@ -50,20 +50,7 @@ #include "fortran_mutex.hpp" #include "pskreporter_settings.h" #include "runtime_paths.h" - -#if !defined(Q_OS_WIN) -extern "C" { - void ptt_set_override(const char *path); -} -#endif - -extern "C" { - int ptt_(int* nport, int* itx, int* iptt); -} - -#ifdef __unix__ -extern "C" void ptt_close(void); -#endif +#include "libm65/ptt.h" #ifdef MessageBox #undef MessageBox @@ -90,8 +77,6 @@ TxTune* g_pTxTune = NULL; std::atomic<bool> stop_m65{false}; -QString guiDate; //liveCQ -QStringList allDecodes; //liveCQ QStringList allDecodes2; //liveCQ QString m_otherUrl; bool m_w3szUrl; @@ -117,34 +102,6 @@ MainWindow::DecoderContext::~DecoderContext() delete stdoutChan; } -// TEMP diagnostic 2026-09-10 for the "decode reaches map65_rx.log but not the -// Messages window, only on the first decode cycle after MAP65 starts" report. -// Writes to its own separate log file rather than the shared w3sz_debug.log -// Fortran's dbg() uses -- the two processes/threads have no lock between -// them, and sharing a file produces torn, interleaved lines. Timestamps use -// the same sec_midn()-style local h*3600+m*60+s+ms/1000 format as the -// Fortran log, so the two can still be correlated by eye. Strip both files' -// worth of logging before merge. -// -// Mirrors run_m65.f90's dbg_enabled flag -- flip to true to re-enable this -// log without touching any of the cppDbg(...) call sites scattered through -// this file. -static bool const cppDbgEnabled = false; - -static void cppDbg(const QString &msg) -{ - if (!cppDbgEnabled) return; - double const t = [] { - QTime const now = QTime::currentTime(); - return now.hour() * 3600.0 + now.minute() * 60.0 + now.second() + now.msec() / 1000.0; - }(); - QFile f("w3sz_debug_cpp.log"); - if (f.open(QIODevice::Append | QIODevice::Text)) { - QTextStream out(&f); - out << "mainwindow: " << msg << " at t=" << QString::number(t, 'f', 3) << "\n"; - } -} - //-------------------------------------------------- MainWindow constructor MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -512,21 +469,7 @@ MainWindow::MainWindow(QWidget *parent) : m_wide_graph_window->m_TxOffset=m_TxOffset; if(m_initIQplus) m_wide_graph_window->initIQplus(); -// Create "m_worked", a dictionary of all calls in wsjt.log - QFile f("wsjt.log"); - qDebug() << "MainWindow Constructor File open result:" << f.open(QFileDevice::ReadOnly); - if(f.isOpen()) { - QTextStream in(&f); - QString line,t,callsign; - for(int i=0; i<99999; i++) { - line=in.readLine(); - if(line.length()<=0) break; - t=line.mid(18,12); - callsign=t.mid(0,t.indexOf(",")); - m_worked[callsign]=true; - } - f.close(); - } + loadWorkedLog(); if(ui->actionLinrad->isChecked()) on_actionLinrad_triggered(); if(ui->actionCuteSDR->isChecked()) on_actionCuteSDR_triggered(); @@ -643,24 +586,26 @@ void MainWindow::startSharedMemoryStdoutReader(DecoderContext* ctx) // Linux: eventHandle is a void* pointing to posix_event_t void* ev = ctx->stdoutChan->eventHandle; - // NEW: start reading from the current writeIndex StdoutSharedHeader h0 = region->header; std::uint32_t readIndex = h0.writeIndex; if (readIndex >= bufSize) readIndex = 0; region->header.readIndex = readIndex; - // TEMP diagnostic 2026-09-10: h0.writeIndex should always be 0 here -- - // StdoutSharedMemory's constructor unconditionally zeroes writeIndex/ - // readIndex right after mapping (see stdout_shared_memory.cpp), and - // that happens synchronously on the main thread before this reader - // thread is even spawned. If this ever logs a nonzero value, that - // assumption is wrong and this "start from current writeIndex" line - // is silently skipping over real data written before this point. - cppDbg(QString("stdout reader INIT readIndex=%1 (h0.writeIndex=%2) bufSize=%3") - .arg(readIndex).arg(h0.writeIndex).arg(bufSize)); - std::string lineBuffer; + QStringList displayLines; + auto flushDisplayLines = [this, &displayLines]() { + if (displayLines.isEmpty()) return; + QStringList lines; + lines.swap(displayLines); + QMetaObject::invokeMethod( + this, + [this, lines]() { + for (const QString& line : lines) processStdOut(line); + }, + Qt::QueuedConnection + ); + }; while (!stdoutReaderStop.load()) { @@ -685,6 +630,11 @@ void MainWindow::startSharedMemoryStdoutReader(DecoderContext* ctx) lineBuffer.clear(); QString text = QString::fromStdString(line); + if (text.startsWith('@') || text.startsWith('&')) { + displayLines.append(text); + continue; + } + flushDisplayLines(); QMetaObject::invokeMethod( this, [this, text]() { processStdOut(text); }, @@ -699,6 +649,8 @@ void MainWindow::startSharedMemoryStdoutReader(DecoderContext* ctx) region->header.readIndex = readIndex; } + flushDisplayLines(); + }); } @@ -707,17 +659,15 @@ void MainWindow::processStdOut(QString t) // qDebug().noquote() << QDateTime::currentMSecsSinceEpoch() << "PROCESS STDOUT:" << t; - // TEMP diagnostic 2026-09-10: confirms whether a decode line that made it - // into map65_rx.log (written Fortran-side, independent of this whole - // path) ever actually arrived here on the GUI thread. If a "!"-prefixed - // line is missing from this log around the time of a report-vs-rx.log - // mismatch, the loss is upstream (shared-memory ring buffer / reader - // thread); if it IS here but never appended to the Messages window, the - // loss is in handleControlLine/shouldDisplay below. - cppDbg(QString("processStdOut RECV \"%1\"").arg(t.trimmed())); - if (m_decodeDisplayFilter.handleControlLine(t)) return; + if (t.startsWith("<Map65DisplayBegin>")) { + m_messagesText.clear(); + m_bandmapText.clear(); + m_widebandDecode = true; + return; + } + if (t.startsWith("<DecodeSkipped>")) { bool validRequestId = false; auto requestId = t.trimmed().section(' ', -1).toLongLong(&validRequestId); @@ -783,9 +733,6 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) { return; } - // --- same position as legacy --- - read_log(); - // --- "!" decoded text lines --- if (t.startsWith("!")) { int n = t.length(); @@ -804,11 +751,6 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) { if (n >= 30 || t.indexOf("Best-fit") >= 0) { bool const display = m_decodeDisplayFilter.shouldDisplay(decode_line); - // TEMP diagnostic 2026-09-10 -- see the matching note at the top - // of processStdOut(). If display=false here for a line that has - // no legitimate earlier-pass duplicate, the display filter itself - // (map65_decode_display_filter.cpp) is the culprit. - cppDbg(QString("shouldDisplay=%1 for \"%2\"").arg(display ? "true" : "false").arg(decode_line)); if (display) ui->decodedTextBrowser->append(decode_line); } @@ -873,16 +815,13 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) { } } static const QRegularExpression call_re( - "^[A-Z0-9]{1,3}[0-9][A-Z0-9]{0,3}[A-Z](/[A-Z0-9]+)?$"); + "^([A-Z0-9]{1,4}/)?[A-Z0-9]{1,3}[0-9][A-Z0-9]{0,3}[A-Z](/[A-Z0-9]+)?$"); if (freq_khz > 0 && !sender.isEmpty() && call_re.match(sender.toUpper()).hasMatch()) { m_wide_graph_window->addDecodeLabel(freq_khz, sender, is_jt65); } } - // clear snapshots for this decode run, just like legacy - m_messagesText.clear(); - m_bandmapText.clear(); } // --- "@" message lines --- @@ -894,7 +833,9 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) { // --- "&" bandmap lines --- // N6NU 2026-05-24: format widened to include the 5-char ndf from // line3(k)(9:13). New layout: - // "&" + I3 kHz + I5 ndf + " " + A6 call + A2 age + // "&" + I3 kHz + I5 ndf + " " + A12 call + A2 age + A1 mode + A4 UTC + // where mode is '#' (JT65) or ':' (Q65) and UTC (hhmm) is the call's + // latest decode; older builds omit both. // Old layout (pre-260524, used by stock map65): // "&" + I3 kHz + " " + A6 call + A2 age // We auto-detect by checking column 4: if it's a digit/space-of-int, @@ -911,7 +852,7 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) { QString callsign = q.mid(call_start); callsign = callsign.mid(0, callsign.indexOf(" ")); if (callsign.length() > 2) { - if (m_worked[callsign]) { + if (m_worked.contains(callsign)) { q = q.mid(1,4) + " " + q.mid(call_start); } else { q = q.mid(1,4) + " *" + q.mid(call_start); @@ -919,24 +860,30 @@ if (t.indexOf("<QuickDecodeDone>") >= 0) { m_bandmapText += q; // Fallback overlay tap (N6NU 2026-05-13, DG2YCB feedback r4). - // We can't know the mode from this line, so pass is_jt65=false - // and mode_reliable=false. With the new format we now also - // have ndf precision, so freq_reliable=true. Old format - // callers still pass freq_reliable=false (integer kHz only). + // The mode character, when present, sets the label color; + // without it, pass is_jt65=false and mode_reliable=false. With + // the new format we now also have ndf precision, so + // freq_reliable=true. Old format callers still pass + // freq_reliable=false (integer kHz only). if (m_wide_graph_window) { + const QString mode = ndf_ok ? t.mid(call_start + 14, 1) : QString(); + const bool mode_known = (mode == "#" || mode == ":"); + bool utc_ok = false; + const int utc = mode_known ? t.mid(call_start + 15, 4).toInt(&utc_ok) : -1; bool ok_khz = false; const int nkHz = t.mid(1, 3).trimmed().toInt(&ok_khz); const double freq_khz = ndf_ok ? (nkHz + ndf_hz / 1000.0) : double(nkHz); static const QRegularExpression call_re( - "^[A-Z0-9]{1,3}[0-9][A-Z0-9]{0,3}[A-Z](/[A-Z0-9]+)?$"); + "^([A-Z0-9]{1,4}/)?[A-Z0-9]{1,3}[0-9][A-Z0-9]{0,3}[A-Z](/[A-Z0-9]+)?$"); if (ok_khz && freq_khz > 0 && call_re.match(callsign.toUpper()).hasMatch()) { m_wide_graph_window->addDecodeLabel( - freq_khz, callsign, /*is_jt65=*/false, - /*mode_reliable=*/false, - /*freq_reliable=*/ndf_ok); + freq_khz, callsign, /*is_jt65=*/mode == "#", + /*mode_reliable=*/mode_known, + /*freq_reliable=*/ndf_ok, + /*decode_utc=*/utc_ok ? utc : -1); } } } @@ -1070,10 +1017,12 @@ void MainWindow::readSettings() m_myCall=settings.value("MyCall","").toString(); m_myGrid=settings.value("MyGrid","").toString(); m_idInt=settings.value("IDint",0).toInt(); - m_pttPath=settings.value("PTTpath",0).toString(); + m_pttPath=settings.value("PTTpath","NONE").toString(); + if (m_pttPath.isEmpty() || m_pttPath == "0") m_pttPath = "NONE"; m_pttPortNumber = settings.value("PTTPortNumber",0).toInt(); + if (m_pttPath == "NONE") m_pttPortNumber = 0; #if !defined(Q_OS_WIN) - ptt_set_override(m_pttPath.toUtf8().constData()); + ptt_set_override(m_pttPath == "NONE" ? nullptr : m_pttPath.toUtf8().constData()); #endif m_astroFont=settings.value("AstroFont",20).toInt(); m_xpol=settings.value("Xpol",false).toBool(); @@ -1096,7 +1045,7 @@ void MainWindow::readSettings() } m_editorCommand=settings.value("Editor","notepad").toString(); m_dxccPfx=settings.value("DXCCpfx","").toString(); - m_timeout=settings.value("Timeout",20).toInt(); + m_timeout=qBound(10,settings.value("Timeout",20).toInt(),40); m_applyIQcal=settings.value("ApplyIQcal",0).toInt(); ui->actionApply_IQ_Calibration->setChecked(m_applyIQcal!=0); m_dPhi=settings.value("dPhi",0).toInt(); @@ -1864,9 +1813,7 @@ void MainWindow::closeEvent(QCloseEvent *e) } if (m_wide_graph_window) m_wide_graph_window->close(); -#ifdef __unix__ - ptt_close(); // close persistent Linux serial port -#endif + ptt_close(); if (g_pTxTune) { g_pTxTune->close(); @@ -2098,11 +2045,7 @@ void MainWindow::on_actionErase_Band_Map_and_Messages_triggered() { m_band_map_window->setText(""); m_messages_window->setText("",""); - // m_messagesText/m_bandmapText accumulate across decode cycles and are - // only reset when a "!" line arrives (processStdOut). Without clearing - // them here too, the next <EarlyFinished>/<DecodeFinished> redisplay - // (or a cycle with no fresh decodes) repaints the stale pre-erase text - // right back into the windows. + m_messages_window->clearLiveCQHistory(); m_messagesText.clear(); m_bandmapText.clear(); m_widebandDecode = false; @@ -2416,6 +2359,10 @@ void MainWindow::guiUpdate() static bool bMonitoring0=false; static int nc0=1; static int nc1=1; + static bool pttReleasePending=false; + static QElapsedTimer pttReleaseRetry; + static QString pttPath; + static int pttPortNumber=0; static char msgsent[23]; static int nsendingsh=0; int khsym=0; @@ -2444,25 +2391,46 @@ void MainWindow::guiUpdate() if(bTune and !bTune0) bMonitoring0=m_monitoring; bTune0=bTune; - if(m_auto or bTune) { - if ((bTxTime or bTune) && iptt == 0 && !m_txMute) { + auto stopForPttError = [this] (int error) { + bool deviceLost = error == PTT_DEVICE_LOST; + pttReleasePending = !deviceLost; + pttReleaseRetry.start(); + nc0 = nc1 = 1; + iptt0 = iptt; + btxok0 = false; + on_stopTxButton_clicked(); + if (bTune && g_pTxTune) g_pTxTune->accept(); + bTune = false; + soundOutThread.quitExecution = true; + m_transmitting = false; + if (deviceLost) { + m_wide_graph_window->enableSetRxHardware(true); + m_pttErrorShown = false; + msgBox(tr("Lost connection to PTT port: %1. PTT release could not be confirmed. " + "Check that the radio is no longer transmitting before starting another transmission.") + .arg(pttPath)); + } else if (!m_pttErrorShown) { + m_pttErrorShown = true; + msgBox(tr("Cannot open or control PTT port: %1").arg(pttPath)); + } + }; + + if (pttReleasePending) { + on_stopTxButton_clicked(); + if (bTune && g_pTxTune) g_pTxTune->accept(); + bTune = false; + } - if (m_pttPath != "NONE") { + if((m_auto or bTune) && !pttReleasePending) { + if ((bTxTime or bTune) && iptt == 0 && !m_txMute) { + pttPath = m_pttPath; + pttPortNumber = m_pttPortNumber; int itx = 1; - int nport = m_pttPortNumber; // the real COM port number - int ierr = ptt_(&nport, &itx, &iptt); - - if (ierr != 0) { - if (!m_pttErrorShown) { - char s[256]; - snprintf(s, sizeof(s), "Cannot open Port: %s", - m_pttPath.toUtf8().constData()); - msgBox(s); - m_pttErrorShown = true; - } - on_stopTxButton_clicked(); + int ierr = ptt_(&pttPortNumber, &itx, &iptt); + if (ierr != PTT_OK) { + stopForPttError(ierr); + return; } - } if (m_bIQxt) m_wide_graph_window->tx570(); @@ -2556,15 +2524,19 @@ void MainWindow::guiUpdate() if(!btxok && btxok0 && iptt==1) nc0=-11; //RxDelay = 1.0 s btxok0=btxok; if(nc0 <= 0) nc0++; - if(nc0 == 0) { + if(nc0 == 0 || (pttReleasePending && pttReleaseRetry.hasExpired(1000))) { if(m_bIQxt) m_wide_graph_window->rx570(); // Set Si570 back to Rx Freq - int itx = 0; - int nport = m_pttPortNumber; // the real COM port number - ptt_(&nport, &itx, &iptt); // Lower PTT - m_pttErrorShown = false; + int itx = 0; + int ierr = ptt_(&pttPortNumber, &itx, &iptt); + if (ierr != PTT_OK) { + stopForPttError(ierr); + return; + } + pttReleasePending = false; + m_pttErrorShown = false; if(!m_txMute) { - soundOutThread.quitExecution=true;\ + soundOutThread.quitExecution=true; } m_transmitting=false; m_wide_graph_window->enableSetRxHardware(true); @@ -2651,7 +2623,6 @@ void MainWindow::guiUpdate() m_setftx=0; QString utc = t.date().toString(" yyyy MMM dd \n") + t.time().toString(); ui->labUTC->setText(utc); - guiDate = ui->labUTC->text().trimmed().mid(0,12); //liveCQ if((!m_monitoring and !m_diskData) or (khsym==m_hsym0)) { xSignalMeter->setValue(0); ySignalMeter->setValue(0); @@ -2747,7 +2718,7 @@ void MainWindow::selectCall2(bool ctrl) //selectCall2 //doubleClickOnCall void MainWindow::doubleClickOnCall(QString hiscall, bool ctrl) { - if(m_worked[hiscall]) { + if(m_worked.contains(hiscall)) { msgBox("Possible dupe: " + hiscall + " already in log."); } ui->dxCallEntry->setText(hiscall); @@ -2789,7 +2760,7 @@ void MainWindow::doubleClickOnCall(QString hiscall, bool ctrl) void MainWindow::doubleClickOnMessages(QString hiscall, QString t2, bool ctrl) { if(hiscall.length()<3) return; - if(m_worked[hiscall]) { + if(m_worked.contains(hiscall)) { msgBox("Possible dupe: " + hiscall + " already in log."); } ui->dxCallEntry->setText(hiscall); @@ -3117,8 +3088,13 @@ void MainWindow::on_logQSOButton_clicked() //Log QSO button } QTextStream out(&f); out << logEntry; + out.flush(); + if (out.status() != QTextStream::Ok || !f.flush()) { + msgBox("Cannot write file \"wsjt.log\"."); + return; + } f.close(); - m_worked[m_hisCall]=true; + m_worked.insert(m_hisCall); } void MainWindow::on_actionErase_map65_rx_log_triggered() //Erase Rx log @@ -3271,7 +3247,7 @@ void MainWindow::on_actionFUNcube_Dongle_triggered() void MainWindow::on_actionEdit_wsjt_log_triggered() { - proc_editor.start (QDir::toNativeSeparators (m_editorCommand), {QDir::toNativeSeparators (m_appDir + "/wsjt.log"), }); + proc_editor.start (QDir::toNativeSeparators (m_editorCommand), {QDir::toNativeSeparators (m_dataDir + "/wsjt.log"), }); } void MainWindow::on_actionTx_Tune_triggered() @@ -3311,25 +3287,18 @@ bool MainWindow::isGrid4(QString g) return true; } -void MainWindow::read_log() -{ - // Update "m_worked" by reading wsjtx.log - m_worked.clear(); //Start from scratch - QFile f("wsjtx.log"); - qDebug() << "MainWindow::read_log File open result:" << f.open(QFileDevice::ReadOnly); - if(f.isOpen()) { - QTextStream in(&f); - QString line,callsign; - for(int i=0; i<99999; i++) { - line=in.readLine(); - if(line.length()<=0) break; - callsign=line.mid(40,6); - int n=callsign.indexOf(","); - if(n>0) callsign=callsign.left(n); - m_worked[callsign]=true; - } - f.close(); - } +void MainWindow::loadWorkedLog() +{ + QFile f("wsjt.log"); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) return; + QSet<QString> worked; + QTextStream in(&f); + while (!in.atEnd()) { + const QString callsign = in.readLine().section(',', 2, 2).trimmed(); + if (!callsign.isEmpty()) worked.insert(callsign); + } + if (in.status() != QTextStream::Ok) return; + m_worked.swap(worked); } void pa_deinit() |
