From 2653ee01aa671318fb142a710ea6857abe03461d Mon Sep 17 00:00:00 2001 From: Morgan Diepart Date: Sun, 22 Oct 2023 21:13:27 -0700 Subject: [PATCH] M17: added callsign-based squelch for incoming transmissions --- openrtx/include/rtx/OpMode_M17.hpp | 13 +++++++++++++ openrtx/src/rtx/OpMode_M17.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/openrtx/include/rtx/OpMode_M17.hpp b/openrtx/include/rtx/OpMode_M17.hpp index 537637c0..28310354 100644 --- a/openrtx/include/rtx/OpMode_M17.hpp +++ b/openrtx/include/rtx/OpMode_M17.hpp @@ -121,6 +121,19 @@ private: */ void txState(rtxStatus_t *const status); + /** + * Compare two callsigns in plain text form. + * The comparison does not take into account the country prefixes (strips + * the '/' and whatever is in front from all callsigns). It does take into + * account the dash and whatever is after it. In case the incoming callsign + * is "ALL" the function returns true. + * + * \param localCs plain text callsign from the user + * \param incomingCs plain text destination callsign + * \return true if local an incoming callsigns match. + */ + bool compareCallsigns(const std::string& localCs, const std::string& incomingCs); + bool startRx; ///< Flag for RX management. bool startTx; ///< Flag for TX management. diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index 700896d1..1f8fdbcd 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -268,8 +268,13 @@ void OpMode_M17::rxState(rtxStatus_t *const status) bool canMatch = (streamType.fields.CAN == status->can) || (status->canRxEn == false); + // Check if the destination callsign of the incoming transmission + // matches with ours + bool callMatch = compareCallsigns(std::string(status->source_address), dst); + // Extract audio data - if((type == M17FrameType::STREAM) && (pthSts == PATH_OPEN) && (canMatch == true)) + if((type == M17FrameType::STREAM) && (pthSts == PATH_OPEN) && + (canMatch == true) && (callMatch == true)) { M17StreamFrame sf = decoder.getStreamFrame(); codec_pushFrame(sf.payload().data(), false); @@ -359,3 +364,26 @@ void OpMode_M17::txState(rtxStatus_t *const status) modulator.stop(); } } + +bool OpMode_M17::compareCallsigns(const std::string& localCs, + const std::string& incomingCs) +{ + if(incomingCs == "ALL") + return true; + + std::string truncatedLocal(localCs); + std::string truncatedIncoming(incomingCs); + + int slashPos = localCs.find_first_of('/'); + if(slashPos <= 2) + truncatedLocal = localCs.substr(slashPos + 1); + + slashPos = incomingCs.find_first_of('/'); + if(slashPos <= 2) + truncatedIncoming = incomingCs.substr(slashPos + 1); + + if(truncatedLocal == truncatedIncoming) + return true; + + return false; +}