Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions configs/bridge-config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,9 @@ system:
trace: false
# Flag indicating whether or not debug logging is enabled.
debug: false

# RTS PTT Configuration
# Flag indicating whether RTS PTT control is enabled.
rtsPttEnable: false
# Serial port device for RTS PTT control (e.g., /dev/ttyUSB0).
rtsPttPort: "/dev/ttyUSB0"
84 changes: 84 additions & 0 deletions src/bridge/HostBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ void audioCallback(ma_device* device, void* output, const void* input, ma_uint32
pcm[pcmIdx + 1] = (uint8_t)((samples[smpIdx] >> 8) & 0xFF);
pcmIdx += 2;
}

// Assert RTS PTT when audio is being sent to output
bridge->assertRtsPtt();
}
else {
// Deassert RTS PTT when no audio is being sent to output
bridge->deassertRtsPtt();
}
}

Expand Down Expand Up @@ -243,6 +250,10 @@ HostBridge::HostBridge(const std::string& confFile) :
m_running(false),
m_trace(false),
m_debug(false),
m_rtsPttEnable(false),
m_rtsPttPort(),
m_rtsPttController(nullptr),
m_rtsPttActive(false),
m_rtpSeqNo(0U),
m_rtpTimestamp(INVALID_TS),
m_usrpSeqNo(0U)
Expand Down Expand Up @@ -283,6 +294,12 @@ HostBridge::HostBridge(const std::string& confFile) :

HostBridge::~HostBridge()
{
if (m_rtsPttController != nullptr) {
m_rtsPttController->close();
delete m_rtsPttController;
m_rtsPttController = nullptr;
}

delete[] m_ambeBuffer;
delete[] m_netLDU1;
delete[] m_netLDU2;
Expand Down Expand Up @@ -390,6 +407,11 @@ int HostBridge::run()
if (!ret)
return EXIT_FAILURE;

// initialize RTS PTT control
ret = initializeRtsPtt();
if (!ret)
return EXIT_FAILURE;

ma_result result;
if (m_localAudio) {
// initialize audio devices
Expand Down Expand Up @@ -927,6 +949,10 @@ bool HostBridge::readParams()
m_trace = systemConf["trace"].as<bool>(false);
m_debug = systemConf["debug"].as<bool>(false);

// RTS PTT Configuration
m_rtsPttEnable = systemConf["rtsPttEnable"].as<bool>(false);
m_rtsPttPort = systemConf["rtsPttPort"].as<std::string>("/dev/ttyUSB0");

std::string txModeStr = "DMR";
if (m_txMode == TX_MODE_P25)
txModeStr = "P25";
Expand All @@ -952,6 +978,10 @@ bool HostBridge::readParams()
LogInfo(" Grant Demands: %s", m_grantDemand ? "yes" : "no");
LogInfo(" Local Audio: %s", m_localAudio ? "yes" : "no");
LogInfo(" UDP Audio: %s", m_udpAudio ? "yes" : "no");
LogInfo(" RTS PTT Enable: %s", m_rtsPttEnable ? "yes" : "no");
if (m_rtsPttEnable) {
LogInfo(" RTS PTT Port: %s", m_rtsPttPort.c_str());
}

if (m_debug) {
LogInfo(" Debug: yes");
Expand Down Expand Up @@ -1568,6 +1598,8 @@ void HostBridge::decodeDMRAudioFrame(uint8_t* ambe, uint32_t srcId, uint32_t dst

if (m_localAudio) {
m_outputAudio.addData(samples, AUDIO_SAMPLES_LENGTH);
// Assert RTS PTT when audio is being sent to output
assertRtsPtt();
}

if (m_udpAudio) {
Expand Down Expand Up @@ -2223,6 +2255,8 @@ void HostBridge::decodeP25AudioFrame(uint8_t* ldu, uint32_t srcId, uint32_t dstI

if (m_localAudio) {
m_outputAudio.addData(samples, AUDIO_SAMPLES_LENGTH);
// Assert RTS PTT when audio is being sent to output
assertRtsPtt();
}

if (m_udpAudio) {
Expand Down Expand Up @@ -3690,3 +3724,53 @@ void* HostBridge::threadCallWatchdog(void* arg)

return nullptr;
}

/* Helper to initialize RTS PTT control. */

bool HostBridge::initializeRtsPtt()
{
if (!m_rtsPttEnable)
return true;

if (m_rtsPttPort.empty()) {
::LogError(LOG_HOST, "RTS PTT port is not specified");
return false;
}

m_rtsPttController = new RtsPttController(m_rtsPttPort);
if (!m_rtsPttController->open()) {
::LogError(LOG_HOST, "Failed to open RTS PTT port %s", m_rtsPttPort.c_str());
delete m_rtsPttController;
m_rtsPttController = nullptr;
return false;
}

::LogInfo(LOG_HOST, "RTS PTT Controller initialized on %s", m_rtsPttPort.c_str());
return true;
}

/* Helper to assert RTS PTT (start transmission). */

void HostBridge::assertRtsPtt()
{
if (!m_rtsPttEnable || m_rtsPttController == nullptr || m_rtsPttActive)
return;

if (m_rtsPttController->setPTT()) {
m_rtsPttActive = true;
::LogDebug(LOG_HOST, "RTS PTT asserted");
}
}

/* Helper to deassert RTS PTT (stop transmission). */

void HostBridge::deassertRtsPtt()
{
if (!m_rtsPttEnable || m_rtsPttController == nullptr || !m_rtsPttActive)
return;

if (m_rtsPttController->clearPTT()) {
m_rtsPttActive = false;
::LogDebug(LOG_HOST, "RTS PTT deasserted");
}
}
21 changes: 21 additions & 0 deletions src/bridge/HostBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "audio/miniaudio.h"
#include "mdc/mdc_decode.h"
#include "network/PeerNetwork.h"
#include "RtsPttController.h"

#include <string>
#include <mutex>
Expand Down Expand Up @@ -258,6 +259,12 @@ class HOST_SW_API HostBridge {
bool m_trace;
bool m_debug;

// RTS PTT Control
bool m_rtsPttEnable;
std::string m_rtsPttPort;
RtsPttController* m_rtsPttController;
bool m_rtsPttActive;

uint16_t m_rtpSeqNo;
uint32_t m_rtpTimestamp;

Expand Down Expand Up @@ -511,6 +518,20 @@ class HOST_SW_API HostBridge {
*/
void processTEKResponse(p25::kmm::KeyItem* ki, uint8_t algId, uint8_t keyLength);

/**
* @brief Helper to initialize RTS PTT control.
* @returns bool True, if RTS PTT was initialized successfully, otherwise false.
*/
bool initializeRtsPtt();
/**
* @brief Helper to assert RTS PTT (start transmission).
*/
void assertRtsPtt();
/**
* @brief Helper to deassert RTS PTT (stop transmission).
*/
void deassertRtsPtt();

/**
* @brief Entry point to audio processing thread.
* @param arg Instance of the thread_t structure.
Expand Down
Loading