summaryrefslogtreecommitdiff
path: root/AutoRespondPeriod.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /AutoRespondPeriod.cpp
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'AutoRespondPeriod.cpp')
-rw-r--r--AutoRespondPeriod.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/AutoRespondPeriod.cpp b/AutoRespondPeriod.cpp
new file mode 100644
index 00000000..fa289a1a
--- /dev/null
+++ b/AutoRespondPeriod.cpp
@@ -0,0 +1,101 @@
+#include "AutoRespondPeriod.hpp"
+
+#include <QRegularExpression>
+#include <QStringList>
+
+#include "Decoder/decodedtext.h"
+#include "Radio.hpp"
+
+namespace
+{
+ QRegularExpression const continuingExchange {R"(^(?:R(?:[-+]\d+)?|RRR|RR73|73)$)"};
+}
+
+bool isDirectAutoRespondCandidate(DecodedText const& message, QString const& myCall)
+{
+ if (!message.isStandardMessage() || myCall.isEmpty()) return false;
+
+ auto const words = message.messageWords();
+ if (words.size() < 5) return false;
+
+ auto const recipient = words.at(2);
+ auto const sender = words.at(3);
+ auto const exchange = words.at(4);
+ auto const myBaseCall = Radio::base_callsign(myCall);
+ bool const addressedToUs = myCall == myBaseCall ? recipient == myBaseCall : recipient == myCall;
+
+ return addressedToUs
+ && Radio::is_callsign(sender)
+ && Radio::base_callsign(sender) != myBaseCall
+ && !exchange.isEmpty()
+ && !exchange.contains(continuingExchange);
+}
+
+bool AutoRespondPeriodState::setEnableTx(bool enabled)
+{
+ if (enabled == m_enableTx) return false;
+
+ m_enableTx = enabled;
+ if (!enabled) disarm();
+ return true;
+}
+
+bool AutoRespondPeriodState::observePeriod(QDateTime const& periodStart, bool receivePeriod,
+ bool pendingCq, AutoRespondPolicy policy)
+{
+ if (!periodStart.isValid() || periodStart == m_lastObservedPeriod) return false;
+
+ m_lastObservedPeriod = periodStart;
+ m_currentPeriodIsReceive = receivePeriod;
+ if (!receivePeriod) return false;
+
+ m_receivePeriod = periodStart;
+ m_firstClaimed = false;
+ m_policy = AutoRespondPolicy::None;
+ m_open = m_enableTx
+ && pendingCq
+ && AutoRespondPolicy::None != policy;
+ if (m_open) m_policy = policy;
+ return m_open;
+}
+
+bool AutoRespondPeriodState::armCurrentReceivePeriod(bool pendingCq,
+ AutoRespondPolicy policy)
+{
+ if (m_open || !m_enableTx || !m_currentPeriodIsReceive || !pendingCq
+ || AutoRespondPolicy::None == policy) return false;
+
+ m_open = true;
+ m_policy = policy;
+ m_firstClaimed = false;
+ return true;
+}
+
+void AutoRespondPeriodState::disarm()
+{
+ m_open = false;
+ m_policy = AutoRespondPolicy::None;
+ m_firstClaimed = false;
+}
+
+void AutoRespondPeriodState::close()
+{
+ disarm();
+}
+
+bool AutoRespondPeriodState::accepts(QDateTime const& decodePeriodStart) const
+{
+ return m_open && decodePeriodStart.isValid() && decodePeriodStart == m_receivePeriod;
+}
+
+bool AutoRespondPeriodState::claimFirst(QDateTime const& decodePeriodStart)
+{
+ if (!accepts(decodePeriodStart) || m_firstClaimed) return false;
+ m_firstClaimed = true;
+ return true;
+}
+
+AutoRespondPolicy AutoRespondPeriodState::policy() const
+{
+ return m_policy;
+}