Skip to content

Commit

Permalink
ensure TSCC SLCO's will not be sent at all if DMR CC mode is disabled…
Browse files Browse the repository at this point in the history
…; hide display of TSCC Slot number if DMR TSCC is not enabled; add payload channel CSBKs; prohibit processing of voice/data traffic on a TSCC slot; fix issue where writeRF_CSBK was only functioning for TSCC slots; fix issue handling slot number in some CSBKs; change order of operations for when TSCC payload channels are activated;
  • Loading branch information
gatekeep committed Mar 25, 2023
1 parent 7e2e002 commit 8674866
Show file tree
Hide file tree
Showing 17 changed files with 482 additions and 123 deletions.
26 changes: 20 additions & 6 deletions src/dmr/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Control::Control(bool authoritative, uint32_t colorCode, uint32_t callHang, uint
m_idenTable(idenTable),
m_ridLookup(ridLookup),
m_tidLookup(tidLookup),
m_enableTSCC(false),
m_tsccCnt(0U),
m_tsccCntInterval(1000U, 0U, DMR_SLOT_TIME / 2U),
m_tsccSlotNo(0U),
Expand Down Expand Up @@ -170,6 +171,8 @@ void Control::setOptions(yaml::Node& conf, bool controlPermitTG, const std::vect
}
}

m_enableTSCC = enableTSCC;

uint32_t silenceThreshold = dmrProtocol["silenceThreshold"].as<uint32_t>(dmr::DEFAULT_SILENCE_THRESHOLD);
if (silenceThreshold > MAX_DMR_VOICE_ERRORS) {
LogWarning(LOG_DMR, "Silence threshold > %u, defaulting to %u", dmr::MAX_DMR_VOICE_ERRORS, dmr::DEFAULT_SILENCE_THRESHOLD);
Expand All @@ -186,8 +189,8 @@ void Control::setOptions(yaml::Node& conf, bool controlPermitTG, const std::vect
m_slot2->setSilenceThreshold(silenceThreshold);

if (printOptions) {
LogInfo(" TSCC Slot: %u", m_tsccSlotNo);
if (enableTSCC) {
LogInfo(" TSCC Slot: %u", m_tsccSlotNo);
LogInfo(" TSCC Aloha Random Access Wait: %u", nRandWait);
LogInfo(" TSCC Aloha Backoff: %u", backOff);
}
Expand All @@ -204,6 +207,11 @@ void Control::setOptions(yaml::Node& conf, bool controlPermitTG, const std::vect
/// <param name="ccRunning"></param>
void Control::setCCRunning(bool ccRunning)
{
if (!m_enableTSCC) {
m_ccRunning = false;
return;
}

m_ccRunning = ccRunning;
switch (m_tsccSlotNo) {
case 1U:
Expand All @@ -224,6 +232,11 @@ void Control::setCCRunning(bool ccRunning)
/// <param name="ccHalted"></param>
void Control::setCCHalted(bool ccHalted)
{
if (!m_enableTSCC) {
m_ccHalted = true;
return;
}

m_ccHalted = ccHalted;
switch (m_tsccSlotNo) {
case 1U:
Expand Down Expand Up @@ -419,13 +432,14 @@ Slot* Control::getTSCCSlot() const
/// </summary>
/// <param name="slotNo">DMR slot number.</param>
/// <param name="dstId"></param>
/// <param name="srcId"></param>
/// <param name="group"></param>
/// <param name="voice"></param>
void Control::tsccActivateSlot(uint32_t slotNo, uint32_t dstId, bool group, bool voice)
void Control::tsccActivateSlot(uint32_t slotNo, uint32_t dstId, uint32_t srcId, bool group, bool voice)
{
if (m_verbose) {
LogMessage(LOG_DMR, "DMR Slot %u, payload activation, group = %u, dstId = %u",
slotNo, group, dstId);
LogMessage(LOG_DMR, "DMR Slot %u, payload activation, srcId = %u, group = %u, dstId = %u",
slotNo, srcId, group, dstId);
}

// never allow the TSCC to become payload activated
Expand All @@ -437,11 +451,11 @@ void Control::tsccActivateSlot(uint32_t slotNo, uint32_t dstId, bool group, bool
switch (slotNo) {
case 1U:
m_tsccPayloadActive = true;
m_slot1->setTSCCActivated(dstId, group, voice);
m_slot1->setTSCCActivated(dstId, srcId, group, voice);
break;
case 2U:
m_tsccPayloadActive = true;
m_slot2->setTSCCActivated(dstId, group, voice);
m_slot2->setTSCCActivated(dstId, srcId, group, voice);
break;
default:
LogError(LOG_DMR, "DMR, invalid slot, TSCC payload activation, slotNo = %u", slotNo);
Expand Down
4 changes: 3 additions & 1 deletion src/dmr/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace dmr
/// <summary>Helper to return the slot carrying the TSCC.</summary>
Slot* getTSCCSlot() const;
/// <summary>Helper to payload activate the slot carrying granted payload traffic.</summary>
void tsccActivateSlot(uint32_t slotNo, uint32_t dstId, bool group, bool voice);
void tsccActivateSlot(uint32_t slotNo, uint32_t dstId, uint32_t srcId, bool group, bool voice);
/// <summary>Helper to clear an activated payload slot.</summary>
void tsccClearActivatedSlot(uint32_t slotNo);

Expand Down Expand Up @@ -141,6 +141,8 @@ namespace dmr
::lookups::RadioIdLookup* m_ridLookup;
::lookups::TalkgroupIdLookup* m_tidLookup;

bool m_enableTSCC;

uint16_t m_tsccCnt;
Timer m_tsccCntInterval;

Expand Down
1 change: 1 addition & 0 deletions src/dmr/DMRDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ namespace dmr
const uint8_t CSBKO_EXT_FNCT = 0x24U; // (DMRA) EXT FNCT - Extended Function
const uint8_t CSBKO_NACK_RSP = 0x26U; // NACK RSP - Negative Acknowledgement Response
const uint8_t CSBKO_BROADCAST = 0x28U; // BCAST - Announcement PDUs
const uint8_t CSBKO_P_CLEAR = 0x2EU; // P_CLEAR - Payload Channel Clear
const uint8_t CSBKO_PV_GRANT = 0x30U; // PV_GRANT - Private Voice Channel Grant
const uint8_t CSBKO_TV_GRANT = 0x31U; // TV_GRANT - Talkgroup Voice Channel Grant
const uint8_t CSBKO_BTV_GRANT = 0x32U; // BTV_GRANT - Broadcast Talkgroup Voice Channel Grant
Expand Down
30 changes: 18 additions & 12 deletions src/dmr/Slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,15 @@ bool Slot::processFrame(uint8_t *data, uint32_t len)
if (dataSync) {
uint8_t dataType = data[1U] & 0x0FU;

// write and process TSCC CSBKs and short LC
if (m_enableTSCC && m_dedicatedTSCC && m_slotNo == m_dmr->m_tsccSlotNo) {
switch (dataType)
{
case DT_CSBK:
return m_control->process(data, len);
default:
break;
}
if (dataType == DT_CSBK) {
return m_control->process(data, len);
}

if (m_enableTSCC && m_dedicatedTSCC)
return false;
}

switch (dataType)
{
case DT_CSBK:
return m_control->process(data, len);
case DT_VOICE_LC_HEADER:
case DT_VOICE_PI_HEADER:
return m_voice->process(data, len);
Expand Down Expand Up @@ -600,6 +592,20 @@ void Slot::setTSCC(bool enable, bool dedicated)
}
}

/// <summary>
/// Helper to activate a TSCC payload slot.
/// </summary>
/// <param name="dstId"></param>
/// <param name="srcId"></param>
/// <param name="group"></param>
/// <param name="voice"></param>
void Slot::setTSCCActivated(uint32_t dstId, uint32_t srcId, bool group, bool voice)
{
m_tsccPayloadDstId = dstId;
m_tsccPayloadGroup = group;
m_tsccPayloadVoice = voice;
}

/// <summary>
/// Helper to set the voice error silence threshold.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/dmr/Slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ namespace dmr

/// <summary>Helper to enable and configure TSCC support for this slot.</summary>
void setTSCC(bool enable, bool dedicated);
/// <summary>Sets a flag indicating whether the slot is a TSCC payload slot.</summary>
void setTSCCActivated(uint32_t dstId, bool group, bool voice) { m_tsccPayloadDstId = dstId; m_tsccPayloadGroup = group; m_tsccPayloadVoice = voice; }
/// <summary>Helper to activate a TSCC payload slot.</summary>
void setTSCCActivated(uint32_t dstId, uint32_t srcId, bool group, bool voice);
/// <summary>Sets a flag indicating whether the DMR control channel can send permit-tg to voice channels.</summary>
void setControlPermitTG(bool controlPermitTG) { m_controlPermitTG = controlPermitTG; }
/// <summary>Helper to set the voice error silence threshold.</summary>
Expand Down
2 changes: 2 additions & 0 deletions src/dmr/lc/csbk/CSBKFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "dmr/lc/csbk/CSBK_DVM_GIT_HASH.h"
#include "dmr/lc/csbk/CSBK_EXT_FNCT.h"
#include "dmr/lc/csbk/CSBK_NACK_RSP.h"
#include "dmr/lc/csbk/CSBK_P_CLEAR.h"
#include "dmr/lc/csbk/CSBK_P_GRANT.h"
#include "dmr/lc/csbk/CSBK_PD_GRANT.h"
#include "dmr/lc/csbk/CSBK_PRECCSBK.h"
#include "dmr/lc/csbk/CSBK_PV_GRANT.h"
Expand Down
2 changes: 1 addition & 1 deletion src/dmr/lc/csbk/CSBK_PD_GRANT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void CSBK_PD_GRANT::encode(uint8_t* data)
ulong64_t csbkValue = 0U;

csbkValue = (csbkValue << 12) + (m_logicalCh1 & 0xFFFU); // Logical Physical Channel 1
csbkValue = (csbkValue << 1) + (m_slotNo & 0x3U); // Logical Slot Number
csbkValue = (csbkValue << 1) + ((m_slotNo == 2U) ? 1U : 0U); // Logical Slot Number
csbkValue = (csbkValue << 1) + 0U; // High Rate Flag - Always Single Slot Data
csbkValue = (csbkValue << 1) + ((m_emergency) ? 1U : 0U); // Emergency
csbkValue = (csbkValue << 1) + ((m_siteOffsetTiming) ? 1U : 0U); // Site Timing: Aligned or Offset
Expand Down
2 changes: 1 addition & 1 deletion src/dmr/lc/csbk/CSBK_PV_GRANT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void CSBK_PV_GRANT::encode(uint8_t* data)
ulong64_t csbkValue = 0U;

csbkValue = (csbkValue << 12) + (m_logicalCh1 & 0xFFFU); // Logical Physical Channel 1
csbkValue = (csbkValue << 1) + (m_slotNo & 0x3U); // Logical Slot Number
csbkValue = (csbkValue << 1) + ((m_slotNo == 2U) ? 1U : 0U); // Logical Slot Number
csbkValue = (csbkValue << 1) + 0U; // Reserved
csbkValue = (csbkValue << 1) + ((m_emergency) ? 1U : 0U); // Emergency
csbkValue = (csbkValue << 1) + ((m_siteOffsetTiming) ? 1U : 0U); // Site Timing: Aligned or Offset
Expand Down
83 changes: 83 additions & 0 deletions src/dmr/lc/csbk/CSBK_P_CLEAR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Digital Voice Modem - Host Software
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Host Software
*
*/
/*
* Copyright (C) 2023 by Bryan Biedenkapp N2PLL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Defines.h"
#include "dmr/lc/csbk/CSBK_P_CLEAR.h"
#include "Log.h"
#include "Utils.h"

using namespace dmr::lc::csbk;
using namespace dmr::lc;
using namespace dmr;

#include <cassert>
#include <cmath>

// ---------------------------------------------------------------------------
// Public Class Members
// ---------------------------------------------------------------------------

/// <summary>
/// Initializes a new instance of the CSBK_P_CLEAR class.
/// </summary>
CSBK_P_CLEAR::CSBK_P_CLEAR() : CSBK()
{
m_CSBKO = CSBKO_P_CLEAR;
}

/// <summary>
/// Decode a control signalling block.
/// </summary>
/// <param name="data"></param>
/// <returns>True, if CSBK was decoded, otherwise false.</returns>
bool CSBK_P_CLEAR::decode(const uint8_t* data)
{
assert(data != NULL);

/* stub */

return true;
}

/// <summary>
/// Encode a control signalling block.
/// </summary>
/// <param name="data"></param>
void CSBK_P_CLEAR::encode(uint8_t* data)
{
assert(data != NULL);

ulong64_t csbkValue = 0U;

csbkValue = (csbkValue << 12) + (m_logicalCh1 & 0xFFFU); // Logical Physical Channel 1
csbkValue = (csbkValue << 1) + 0U; // Reserved
csbkValue = (csbkValue << 3) + 0U; // Reserved
csbkValue = (csbkValue << 1) + ((m_GI) ? 1U : 0U); // Group/Individual Flag
csbkValue = (csbkValue << 24) + m_dstId; // Talkgroup ID
csbkValue = (csbkValue << 24) + m_srcId; // Source Radio Address

std::unique_ptr<uint8_t[]> csbk = CSBK::fromValue(csbkValue);
CSBK::encode(data, csbk.get());
}
57 changes: 57 additions & 0 deletions src/dmr/lc/csbk/CSBK_P_CLEAR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Digital Voice Modem - Host Software
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Host Software
*
*/
/*
* Copyright (C) 2023 by Bryan Biedenkapp N2PLL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(__DMR_LC_CSBK__CSBK_P_CLEAR_H__)
#define __DMR_LC_CSBK__CSBK_P_CLEAR_H__

#include "Defines.h"
#include "dmr/lc/CSBK.h"

namespace dmr
{
namespace lc
{
namespace csbk
{
// ---------------------------------------------------------------------------
// Class Declaration
// Implements P_CLEAR - Payload Channel Clear
// ---------------------------------------------------------------------------

class HOST_SW_API CSBK_P_CLEAR : public CSBK {
public:
/// <summary>Initializes a new instance of the CSBK_P_CLEAR class.</summary>
CSBK_P_CLEAR();

/// <summary>Decode a control signalling block.</summary>
virtual bool decode(const uint8_t* data);
/// <summary>Encode a control signalling block.</summary>
virtual void encode(uint8_t* data);
};
} // namespace csbk
} // namespace lc
} // namespace dmr

#endif // __DMR_LC_CSBK__CSBK_P_CLEAR_H__
Loading

0 comments on commit 8674866

Please sign in to comment.