From 0653f81a0d4fc8e504ceb13384ac1b29652345ea Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Fri, 6 Jul 2018 16:40:09 -0400 Subject: [PATCH] Smarter beaconing with band space --- mainwindow.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++----- mainwindow.h | 2 ++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 0313b07..2ac212f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -5296,6 +5296,44 @@ bool MainWindow::prepareNextMessageFrame() } +bool MainWindow::isFreqOffsetFree(int f){ + int bw = 50; + int pad = 5; + + foreach(int offset, m_bandActivity.keys()){ + if(qAbs(offset - f) < bw+pad){ + return false; + } + } + + return true; +} + +int MainWindow::findFreeFreqOffset(){ + int bw = 50; + int fmin = 100; + int fmax = 1000; + int nslots = (fmax-fmin)/bw; + + int f = fmin; + for(int i = 0; i < nslots; i++){ + f = bw*(qrand() % nslots); + if(isFreqOffsetFree(f)){ + return f; + } + } + + for(int i = 0; i < nslots; i++){ + f = (qrand() % (fmax-fmin)) + fmin; + if(isFreqOffsetFree(f)){ + return f; + } + } + + // return 0 if there's no free offset + return 0; +} + void MainWindow::scheduleBeacon(bool first){ auto timestamp = QDateTime::currentDateTimeUtc(); //.addSecs(first ? 15 : 300); auto orig = timestamp; @@ -5325,16 +5363,17 @@ void MainWindow::prepareBeacon(){ return; } - if(!m_txFrameQueue.isEmpty()){ + int f = findFreeFreqOffset(); + + // delay beacon if there's not a free frequency or there's something the tx queue... + if(f == 0 || !m_txFrameQueue.isEmpty()){ beaconTimer.start(15*1000); return; } - QString message = QString("DE %1 %2\nDE %1 %2").arg(m_config.my_callsign()).arg(m_config.my_grid().mid(0, 4)); - - // TODO: jsherer - there's probably a better way... - int f = (qrand() % 900) + 100; setFreq4(f, f); + + QString message = QString("DE %1 %2\nDE %1 %2").arg(m_config.my_callsign()).arg(m_config.my_grid().mid(0, 4)); ui->extFreeTextMsgEdit->setPlainText(message); ui->startTxButton->setChecked(true); diff --git a/mainwindow.h b/mainwindow.h index e387ae1..1985a6f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -249,6 +249,8 @@ private slots: QString parseFT8Message(QString input); int countFreeTextMsgs(QString input); bool prepareNextMessageFrame(); + bool isFreqOffsetFree(int f); + int findFreeFreqOffset(); void scheduleBeacon(bool first=false); void prepareBeacon(); void on_rptSpinBox_valueChanged(int n);