Skip to content

Commit

Permalink
implement proper payload SLCO;
Browse files Browse the repository at this point in the history
  • Loading branch information
gatekeep committed Mar 24, 2023
1 parent db0800e commit a1dd519
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/dmr/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ void Control::setOptions(yaml::Node& conf, bool controlPermitTG, const std::vect
case 1U:
m_slot1->setTSCC(enableTSCC, dedicatedTSCC);
m_slot1->setControlPermitTG(m_controlPermitTG);
//m_slot2->setTSCCPayload(true); // this is not the correct way this should be done
break;
case 2U:
m_slot2->setTSCC(enableTSCC, dedicatedTSCC);
m_slot2->setControlPermitTG(m_controlPermitTG);
//m_slot1->setTSCCPayload(true); // this is not the correct way this should be done
break;
default:
LogError(LOG_DMR, "DMR, invalid slot, TSCC disabled, slotNo = %u", m_tsccSlotNo);
Expand Down
1 change: 1 addition & 0 deletions src/dmr/DMRDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ namespace dmr
const uint8_t SLCO_NULL = 0x00U;
const uint8_t SLCO_ACT = 0x01U;
const uint8_t SLCO_TSCC = 0x02U;
const uint8_t SLCO_PAYLOAD = 0x03U;

// Reason Code(s)
const uint8_t TS_ACK_RSN_MSG = 0x60U; // TS - Message Accepted
Expand Down
80 changes: 73 additions & 7 deletions src/dmr/Slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ void Slot::clock()
}
}

// increment the TSCC counter on every slot 1 clock
m_tsccCnt++;
if (m_tsccCnt == TSCC_MAX_CNT) {
m_tsccCnt = 0U;
}

// if we have control enabled; do clocking to generate a CC data stream
if (m_enableTSCC) {
// clock all the grant timers
Expand All @@ -438,12 +444,6 @@ void Slot::clock()

if (m_ccPacketInterval.isRunning() && m_ccPacketInterval.hasExpired()) {
if (m_ccRunning) {
// increment the TSCC counter on every slot 1 clock
m_tsccCnt++;
if (m_tsccCnt == TSCC_MAX_CNT) {
m_tsccCnt = 0U;
}

if (m_ccSeq == 3U) {
m_ccSeq = 0U;
}
Expand All @@ -464,6 +464,10 @@ void Slot::clock()
}
}

if (m_tsccPayloadSlot) {
setShortLC_Payload(m_siteData, m_tsccCnt);
}

m_rfTimeoutTimer.clock(ms);
if (m_rfTimeoutTimer.isRunning() && m_rfTimeoutTimer.hasExpired()) {
if (!m_rfTimeout) {
Expand Down Expand Up @@ -1072,7 +1076,6 @@ void Slot::setShortLC(uint32_t slotNo, uint32_t id, uint8_t flco, bool voice)
/// <summary>
///
/// </summary>
/// <param name="slotNo"></param>
/// <param name="siteData"></param>
/// <param name="counter"></param>
void Slot::setShortLC_TSCC(SiteData siteData, uint16_t counter)
Expand Down Expand Up @@ -1132,3 +1135,66 @@ void Slot::setShortLC_TSCC(SiteData siteData, uint16_t counter)

m_modem->writeDMRShortLC(sLC);
}

/// <summary>
///
/// </summary>
/// <param name="siteData"></param>
/// <param name="counter"></param>
void Slot::setShortLC_Payload(SiteData siteData, uint16_t counter)
{
assert(m_modem != nullptr);

uint8_t lc[5U];
uint32_t lcValue = 0U;
lcValue = SLCO_PAYLOAD;
lcValue = (lcValue << 2) + siteData.siteModel();

switch (siteData.siteModel())
{
case SITE_MODEL_TINY:
{
lcValue = (lcValue << 9) + siteData.netId();
lcValue = (lcValue << 3) + siteData.siteId();
}
break;
case SITE_MODEL_SMALL:
{
lcValue = (lcValue << 7) + siteData.netId();
lcValue = (lcValue << 5) + siteData.siteId();
}
break;
case SITE_MODEL_LARGE:
{
lcValue = (lcValue << 5) + siteData.netId();
lcValue = (lcValue << 7) + siteData.siteId();
}
break;
case SITE_MODEL_HUGE:
{
lcValue = (lcValue << 2) + siteData.netId();
lcValue = (lcValue << 10) + siteData.siteId();
}
break;
}

lcValue = (lcValue << 1) + 0U; // Payload channel is Normal
lcValue = (lcValue << 9) + (counter & 0x1FFU);

// split value into bytes
lc[0U] = (uint8_t)((lcValue >> 24) & 0xFFU);
lc[1U] = (uint8_t)((lcValue >> 16) & 0xFFU);
lc[2U] = (uint8_t)((lcValue >> 8) & 0xFFU);
lc[3U] = (uint8_t)((lcValue >> 0) & 0xFFU);
lc[4U] = edac::CRC::crc8(lc, 4U);

//LogDebug(LOG_DMR, "setShortLC_Payload, netId = %02X, siteId = %02X", siteData.netId(), siteData.siteId());
//Utils::dump(1U, "setShortLC_Payload", lc, 5U);

uint8_t sLC[9U];

lc::ShortLC shortLC;
shortLC.encode(lc, sLC);

m_modem->writeDMRShortLC(sLC);
}
5 changes: 5 additions & 0 deletions src/dmr/Slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +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 setTSCCPayload(bool payload) { m_tsccPayloadSlot = payload; }
/// <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 Expand Up @@ -189,6 +191,7 @@ namespace dmr

bool m_enableTSCC;
bool m_dedicatedTSCC;
bool m_tsccPayloadSlot;

bool m_controlPermitTG;

Expand Down Expand Up @@ -264,6 +267,8 @@ namespace dmr
static void setShortLC(uint32_t slotNo, uint32_t id, uint8_t flco = FLCO_GROUP, bool voice = true);
/// <summary>Helper to set the DMR short LC for TSCC.</summary>
static void setShortLC_TSCC(SiteData siteData, uint16_t counter);
/// <summary>Helper to set the DMR short LC for payload.</summary>
static void setShortLC_Payload(SiteData siteData, uint16_t counter);
};
} // namespace dmr

Expand Down

0 comments on commit a1dd519

Please sign in to comment.