From 059831534c7e884f0a607ed86b582fd00d821731 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Sat, 26 Sep 2026 23:24:03 +0200 Subject: New upstream version 3.2.0~rc1+dfsg --- AutoRespondPeriod.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 AutoRespondPeriod.cpp (limited to 'AutoRespondPeriod.cpp') 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 +#include + +#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; +} -- cgit v1.2.3