correct various issues with CW timing and situations where CW may not occur; fix issue with roaming beacons on DMR cycling incorrectly; silence some superfluous warnings;

pull/1/head
Bryan Biedenkapp 4 years ago
parent d37122a253
commit 3fa0cbc150

@ -68,6 +68,8 @@ using namespace lookups;
#define IDLE_SLEEP_MS 5U #define IDLE_SLEEP_MS 5U
#define ACTIVE_SLEEP_MS 1U #define ACTIVE_SLEEP_MS 1U
#define CW_IDLE_SLEEP_MS 50U
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Public Class Members // Public Class Members
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -546,14 +548,26 @@ int Host::run()
bool killed = false; bool killed = false;
bool hasTxShutdown = false; bool hasTxShutdown = false;
#define INTERRUPT_P25_CONTROL \ // Macro to interrupt a running P25 control channel transmission
if (g_interruptP25Control) { \ #define INTERRUPT_P25_CONTROL \
p25CCDurationTimer.stop(); \ if (p25 != NULL) { \
if (p25CCDurationTimer.isRunning() && !p25CCDurationTimer.hasExpired()) { \ if (g_interruptP25Control) { \
LogDebug(LOG_HOST, "traffic interrupts P25 CC, g_interruptP25Control = %u", g_interruptP25Control); \ p25CCDurationTimer.stop(); \
m_modem->clearP25Data(); \ if (p25CCDurationTimer.isRunning() && !p25CCDurationTimer.hasExpired()) { \
p25->reset(); \ LogDebug(LOG_HOST, "traffic interrupts P25 CC, g_interruptP25Control = %u", g_interruptP25Control); \
} \ m_modem->clearP25Data(); \
p25->reset(); \
} \
} \
}
// Macro to start DMR duplex idle transmission (or beacon)
#define START_DMR_DUPLEX_IDLE(x) \
if (dmr != NULL) { \
if (m_duplex) { \
m_modem->writeDMRStart(x); \
m_dmrTXTimer.start(); \
} \
} }
// main execution loop // main execution loop
@ -575,17 +589,21 @@ int Host::run()
uint8_t data[220U]; uint8_t data[220U];
uint32_t len; uint32_t len;
bool ret; bool ret;
bool hasCw = false;
if (m_modeTimer.isRunning() && m_modeTimer.hasExpired()) { if (!m_fixedMode) {
if (!m_fixedMode) { if (m_modeTimer.isRunning() && m_modeTimer.hasExpired()) {
setState(STATE_IDLE); setState(STATE_IDLE);
} }
else { }
if (dmr != NULL) else {
setState(STATE_DMR); m_modeTimer.stop();
if (p25 != NULL) if (dmr != NULL && m_state != STATE_DMR && !m_modem->hasTX()) {
setState(STATE_P25); LogDebug(LOG_HOST, "fixed mode state abnormal, m_state = %u, state = %u", m_state, STATE_DMR);
setState(STATE_DMR);
}
if (p25 != NULL && m_state != STATE_P25 && !m_modem->hasTX()) {
LogDebug(LOG_HOST, "fixed mode state abnormal, m_state = %u, state = %u", m_state, STATE_P25);
setState(STATE_P25);
} }
} }
@ -605,13 +623,10 @@ int Host::run()
if (m_state == STATE_IDLE) { if (m_state == STATE_IDLE) {
m_modeTimer.setTimeout(m_netModeHang); m_modeTimer.setTimeout(m_netModeHang);
setState(STATE_DMR); setState(STATE_DMR);
START_DMR_DUPLEX_IDLE(true);
} }
if (m_state == STATE_DMR) { if (m_state == STATE_DMR) {
// if the modem is in duplex -- write DMR sync start START_DMR_DUPLEX_IDLE(true);
if (m_duplex) {
m_modem->writeDMRStart(true);
m_dmrTXTimer.start();
}
m_modem->writeDMRData1(data, len); m_modem->writeDMRData1(data, len);
@ -621,9 +636,11 @@ int Host::run()
} }
m_modeTimer.start(); m_modeTimer.start();
} }
/*
else if (m_state != HOST_STATE_LOCKOUT) { else if (m_state != HOST_STATE_LOCKOUT) {
LogWarning(LOG_HOST, "DMR data received, state = %u", m_state); LogWarning(LOG_HOST, "DMR data received, state = %u", m_state);
} }
*/
} }
} }
@ -637,13 +654,10 @@ int Host::run()
if (m_state == STATE_IDLE) { if (m_state == STATE_IDLE) {
m_modeTimer.setTimeout(m_netModeHang); m_modeTimer.setTimeout(m_netModeHang);
setState(STATE_DMR); setState(STATE_DMR);
START_DMR_DUPLEX_IDLE(true);
} }
if (m_state == STATE_DMR) { if (m_state == STATE_DMR) {
// if the modem is in duplex -- write DMR sync start START_DMR_DUPLEX_IDLE(true);
if (m_duplex) {
m_modem->writeDMRStart(true);
m_dmrTXTimer.start();
}
m_modem->writeDMRData2(data, len); m_modem->writeDMRData2(data, len);
@ -653,9 +667,11 @@ int Host::run()
} }
m_modeTimer.start(); m_modeTimer.start();
} }
/*
else if (m_state != HOST_STATE_LOCKOUT) { else if (m_state != HOST_STATE_LOCKOUT) {
LogWarning(LOG_HOST, "DMR data received, state = %u", m_state); LogWarning(LOG_HOST, "DMR data received, state = %u", m_state);
} }
*/
} }
} }
} }
@ -684,9 +700,11 @@ int Host::run()
m_modeTimer.start(); m_modeTimer.start();
} }
/*
else if (m_state != HOST_STATE_LOCKOUT) { else if (m_state != HOST_STATE_LOCKOUT) {
LogWarning(LOG_HOST, "P25 data received, state = %u", m_state); LogWarning(LOG_HOST, "P25 data received, state = %u", m_state);
} }
*/
} }
else { else {
if (m_state == STATE_IDLE || m_state == STATE_P25) { if (m_state == STATE_IDLE || m_state == STATE_P25) {
@ -711,7 +729,6 @@ int Host::run()
} }
} }
// if the modem is in duplex -- handle P25 CC burst control // if the modem is in duplex -- handle P25 CC burst control
if (m_duplex) { if (m_duplex) {
if (p25CCDurationTimer.isPaused() && !g_interruptP25Control) { if (p25CCDurationTimer.isPaused() && !g_interruptP25Control) {
@ -756,6 +773,7 @@ int Host::run()
if (ret) { if (ret) {
m_modeTimer.setTimeout(m_rfModeHang); m_modeTimer.setTimeout(m_rfModeHang);
setState(STATE_DMR); setState(STATE_DMR);
START_DMR_DUPLEX_IDLE(true);
dmrBeaconDurationTimer.stop(); dmrBeaconDurationTimer.stop();
INTERRUPT_P25_CONTROL; INTERRUPT_P25_CONTROL;
@ -765,6 +783,8 @@ int Host::run()
// in simplex directly process slot 1 frames // in simplex directly process slot 1 frames
m_modeTimer.setTimeout(m_rfModeHang); m_modeTimer.setTimeout(m_rfModeHang);
setState(STATE_DMR); setState(STATE_DMR);
START_DMR_DUPLEX_IDLE(true);
dmr->processFrame1(data, len); dmr->processFrame1(data, len);
dmrBeaconDurationTimer.stop(); dmrBeaconDurationTimer.stop();
@ -810,6 +830,7 @@ int Host::run()
if (ret) { if (ret) {
m_modeTimer.setTimeout(m_rfModeHang); m_modeTimer.setTimeout(m_rfModeHang);
setState(STATE_DMR); setState(STATE_DMR);
START_DMR_DUPLEX_IDLE(true);
dmrBeaconDurationTimer.stop(); dmrBeaconDurationTimer.stop();
INTERRUPT_P25_CONTROL; INTERRUPT_P25_CONTROL;
@ -819,6 +840,8 @@ int Host::run()
// in simplex -- directly process slot 2 frames // in simplex -- directly process slot 2 frames
m_modeTimer.setTimeout(m_rfModeHang); m_modeTimer.setTimeout(m_rfModeHang);
setState(STATE_DMR); setState(STATE_DMR);
START_DMR_DUPLEX_IDLE(true);
dmr->processFrame2(data, len); dmr->processFrame2(data, len);
dmrBeaconDurationTimer.stop(); dmrBeaconDurationTimer.stop();
@ -958,20 +981,45 @@ int Host::run()
// clock and check CW timer // clock and check CW timer
m_cwIdTimer.clock(ms); m_cwIdTimer.clock(ms);
if (m_cwIdTimer.isRunning() && m_cwIdTimer.hasExpired()) { if (m_cwIdTimer.isRunning() && m_cwIdTimer.hasExpired()) {
if (dmrBeaconDurationTimer.isRunning() || p25CCDurationTimer.isRunning()) { if (!m_modem->hasTX()) {
LogDebug(LOG_HOST, "CW, beacon or CC timer running, ceasing"); if (dmrBeaconDurationTimer.isRunning() || p25CCDurationTimer.isRunning()) {
LogDebug(LOG_HOST, "CW, beacon or CC timer running, ceasing");
setState(STATE_IDLE); dmrBeaconDurationTimer.stop();
p25CCDurationTimer.stop();
}
dmrBeaconDurationTimer.stop(); LogDebug(LOG_HOST, "CW, start transmitting");
p25CCDurationTimer.stop();
//g_interruptP25Control = true;
}
if (m_state == STATE_IDLE && !m_modem->hasTX()) { setState(STATE_IDLE);
hasCw = true;
m_modem->sendCWId(m_cwCallsign); m_modem->sendCWId(m_cwCallsign);
Thread::sleep(CW_IDLE_SLEEP_MS);
bool first = true;
do {
// ------------------------------------------------------
// -- Modem Clocking --
// ------------------------------------------------------
ms = stopWatch.elapsed();
stopWatch.start();
m_modem->clock(ms);
if (!first && !m_modem->hasTX()) {
LogDebug(LOG_HOST, "CW, finished transmitting");
break;
}
if (first) {
first = false;
Thread::sleep(200U + CW_IDLE_SLEEP_MS); // ~250ms; poll time of the modem
}
else
Thread::sleep(CW_IDLE_SLEEP_MS);
} while (true);
m_cwIdTimer.setTimeout(m_cwIdTime); m_cwIdTimer.setTimeout(m_cwIdTime);
m_cwIdTimer.start(); m_cwIdTimer.start();
} }
@ -982,24 +1030,21 @@ int Host::run()
// clock and check DMR roaming beacon interval timer // clock and check DMR roaming beacon interval timer
dmrBeaconIntervalTimer.clock(ms); dmrBeaconIntervalTimer.clock(ms);
if ((dmrBeaconIntervalTimer.isRunning() && dmrBeaconIntervalTimer.hasExpired()) || g_fireDMRBeacon) { if ((dmrBeaconIntervalTimer.isRunning() && dmrBeaconIntervalTimer.hasExpired()) || g_fireDMRBeacon) {
if (hasCw) { if ((m_state == STATE_IDLE || m_state == STATE_DMR) && !m_modem->hasTX()) {
g_fireDMRBeacon = false; if (m_modeTimer.isRunning()) {
dmrBeaconIntervalTimer.start(); m_modeTimer.stop();
} }
else {
if ((m_state == STATE_IDLE || m_state == STATE_DMR) && !m_modem->hasTX()) {
if (m_modeTimer.isRunning()) {
m_modeTimer.stop();
}
if (m_state != STATE_DMR) if (m_fixedMode)
setState(STATE_DMR); START_DMR_DUPLEX_IDLE(true);
g_fireDMRBeacon = false; if (m_state != STATE_DMR)
LogDebug(LOG_HOST, "DMR, roaming beacon burst"); setState(STATE_DMR);
dmrBeaconIntervalTimer.start();
dmrBeaconDurationTimer.start(); g_fireDMRBeacon = false;
} LogDebug(LOG_HOST, "DMR, roaming beacon burst");
dmrBeaconIntervalTimer.start();
dmrBeaconDurationTimer.start();
} }
} }
@ -1008,9 +1053,11 @@ int Host::run()
if (dmrBeaconDurationTimer.isRunning() && dmrBeaconDurationTimer.hasExpired()) { if (dmrBeaconDurationTimer.isRunning() && dmrBeaconDurationTimer.hasExpired()) {
dmrBeaconDurationTimer.stop(); dmrBeaconDurationTimer.stop();
if (m_state == STATE_DMR && !m_modeTimer.isRunning()) { if (!m_fixedMode) {
m_modeTimer.setTimeout(m_rfModeHang); if (m_state == STATE_DMR && !m_modeTimer.isRunning()) {
m_modeTimer.start(); m_modeTimer.setTimeout(m_rfModeHang);
m_modeTimer.start();
}
} }
} }
@ -1029,40 +1076,34 @@ int Host::run()
if (m_p25CtrlBroadcast) { if (m_p25CtrlBroadcast) {
if ((p25CCIntervalTimer.isRunning() && p25CCIntervalTimer.hasExpired()) || g_fireP25Control) { if ((p25CCIntervalTimer.isRunning() && p25CCIntervalTimer.hasExpired()) || g_fireP25Control) {
if (hasCw) { if ((m_state == STATE_IDLE || m_state == STATE_P25) && !m_modem->hasTX()) {
g_fireP25Control = false; if (m_modeTimer.isRunning()) {
p25CCIntervalTimer.start(); m_modeTimer.stop();
} }
else {
if ((m_state == STATE_IDLE || m_state == STATE_P25) && !m_modem->hasTX()) {
if (m_modeTimer.isRunning()) {
m_modeTimer.stop();
}
if (m_state != STATE_P25) if (m_state != STATE_P25)
setState(STATE_P25); setState(STATE_P25);
if (g_interruptP25Control) { if (g_interruptP25Control) {
g_interruptP25Control = false; g_interruptP25Control = false;
LogDebug(LOG_HOST, "traffic complete, restart P25 CC broadcast, g_interruptP25Control = %u", g_interruptP25Control); LogDebug(LOG_HOST, "traffic complete, restart P25 CC broadcast, g_interruptP25Control = %u", g_interruptP25Control);
} }
p25->writeAdjSSNetwork(); p25->writeAdjSSNetwork();
p25->setCCRunning(true); p25->setCCRunning(true);
// hide this message for continuous CC -- otherwise display every time we process // hide this message for continuous CC -- otherwise display every time we process
if (!m_p25CtrlChannel) { if (!m_p25CtrlChannel) {
LogMessage(LOG_HOST, "P25, start CC broadcast"); LogMessage(LOG_HOST, "P25, start CC broadcast");
} }
g_fireP25Control = false; g_fireP25Control = false;
p25CCIntervalTimer.start(); p25CCIntervalTimer.start();
p25CCDurationTimer.start(); p25CCDurationTimer.start();
// if the CC is continuous -- clock one cycle into the duration timer // if the CC is continuous -- clock one cycle into the duration timer
if (m_p25CtrlChannel) { if (m_p25CtrlChannel) {
p25CCDurationTimer.clock(ms); p25CCDurationTimer.clock(ms);
}
} }
} }
} }
@ -1727,13 +1768,6 @@ void Host::setState(uint8_t state)
switch (state) { switch (state) {
case STATE_DMR: case STATE_DMR:
m_modem->setState(STATE_DMR); m_modem->setState(STATE_DMR);
// if the modem is in duplex -- write DMR start sync
if (m_duplex) {
m_modem->writeDMRStart(true);
m_dmrTXTimer.start();
}
m_state = STATE_DMR; m_state = STATE_DMR;
m_modeTimer.start(); m_modeTimer.start();
//m_cwIdTimer.stop(); //m_cwIdTimer.stop();

Loading…
Cancel
Save

Powered by TurnKey Linux.