Skip to content

Commit

Permalink
Format cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Jan 25, 2024
1 parent 3bde944 commit 0571d90
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 84 deletions.
66 changes: 32 additions & 34 deletions P25Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,21 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
unsigned char duid = m_nid.getDUID();
if (!valid) {
switch (m_lastDUID) {
case P25_DUID_HEADER:
case P25_DUID_LDU2:
duid = P25_DUID_LDU1;
break;
case P25_DUID_LDU1:
duid = P25_DUID_LDU2;
break;
case P25_DUID_PDU:
duid = P25_DUID_PDU;
break;
case P25_DUID_TSDU:
duid = P25_DUID_TSDU;
break;
default:
break;
case P25_DUID_HEADER:
case P25_DUID_LDU2:
duid = P25_DUID_LDU1;
break;
case P25_DUID_LDU1:
duid = P25_DUID_LDU2;
break;
case P25_DUID_PDU:
duid = P25_DUID_PDU;
break;
case P25_DUID_TSDU:
duid = P25_DUID_TSDU;
break;
default:
break;
}
}

Expand Down Expand Up @@ -235,8 +235,7 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
m_lastDUID = duid;
return true;
}
}
else if (duid == P25_DUID_LDU1) {
} else if (duid == P25_DUID_LDU1) {
if (m_rfState == RS_RF_LISTENING) {
m_rfData.reset();
bool ret = m_rfData.decodeLDU1(data + 2U);
Expand Down Expand Up @@ -295,8 +294,7 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len)
LogWarning("P25, LDU1 undecodable LC, using last LDU1 LC");
m_rfData = m_rfLastLDU1;
m_rfUndecodableLC++;
}
else {
} else {
m_rfLastLDU1 = m_rfData;
}

Expand Down Expand Up @@ -827,23 +825,23 @@ void CP25Control::writeNetwork(const unsigned char *data, unsigned char type, bo

switch (type)
{
case P25_DUID_LDU1:
m_network->writeLDU1(data, m_rfData, m_rfLSD, end);
break;
case P25_DUID_LDU2:
m_network->writeLDU2(data, m_rfData, m_rfLSD, end);
break;
default:
break;
case P25_DUID_LDU1:
m_network->writeLDU1(data, m_rfData, m_rfLSD, end);
break;
case P25_DUID_LDU2:
m_network->writeLDU2(data, m_rfData, m_rfLSD, end);
break;
default:
break;
}
}

void CP25Control::setBusyBits(unsigned char* data, unsigned int ssOffset, bool b1, bool b2)
{
assert(data != NULL);
assert(data != NULL);

WRITE_BIT(data, ssOffset, b1);
WRITE_BIT(data, ssOffset + 1U, b2);
WRITE_BIT(data, ssOffset, b1);
WRITE_BIT(data, ssOffset + 1U, b2);
}

void CP25Control::addBusyBits(unsigned char* data, unsigned int length, bool b1, bool b2)
Expand All @@ -864,8 +862,8 @@ void CP25Control::checkNetLDU1()

// Check for an unflushed LDU1
if (m_netLDU1[0U] != 0x00U || m_netLDU1[25U] != 0x00U || m_netLDU1[50U] != 0x00U ||
m_netLDU1[75U] != 0x00U || m_netLDU1[100U] != 0x00U || m_netLDU1[125U] != 0x00U ||
m_netLDU1[150U] != 0x00U || m_netLDU1[175U] != 0x00U || m_netLDU1[200U] != 0x00U)
m_netLDU1[75U] != 0x00U || m_netLDU1[100U] != 0x00U || m_netLDU1[125U] != 0x00U ||
m_netLDU1[150U] != 0x00U || m_netLDU1[175U] != 0x00U || m_netLDU1[200U] != 0x00U)
createNetLDU1();
}

Expand All @@ -876,8 +874,8 @@ void CP25Control::checkNetLDU2()

// Check for an unflushed LDU1
if (m_netLDU2[0U] != 0x00U || m_netLDU2[25U] != 0x00U || m_netLDU2[50U] != 0x00U ||
m_netLDU2[75U] != 0x00U || m_netLDU2[100U] != 0x00U || m_netLDU2[125U] != 0x00U ||
m_netLDU2[150U] != 0x00U || m_netLDU2[175U] != 0x00U || m_netLDU2[200U] != 0x00U)
m_netLDU2[75U] != 0x00U || m_netLDU2[100U] != 0x00U || m_netLDU2[125U] != 0x00U ||
m_netLDU2[150U] != 0x00U || m_netLDU2[175U] != 0x00U || m_netLDU2[200U] != 0x00U)
createNetLDU2();
}

Expand Down
98 changes: 48 additions & 50 deletions P25Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,15 @@ bool CP25Data::decodeHeader(const unsigned char* data)
return false;
}

m_mfId = rs[9U]; // Mfg Id.
m_algId = rs[10U]; // Algorithm ID
m_mfId = rs[9U]; // Mfg Id.
m_algId = rs[10U]; // Algorithm ID

if (m_algId != P25_ALGO_UNENCRYPT) {
m_mi = new unsigned char[P25_MI_LENGTH_BYTES];
::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES);
::memcpy(m_mi, rs, P25_MI_LENGTH_BYTES); // Message Indicator
::memcpy(m_mi, rs, P25_MI_LENGTH_BYTES); // Message Indicator

m_kId = (rs[11U] << 8) + rs[12U]; // Key ID
}
else {
m_kId = (rs[11U] << 8) + rs[12U]; // Key ID
} else {
m_mi = new unsigned char[P25_MI_LENGTH_BYTES];
::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES);

Expand All @@ -124,9 +123,9 @@ void CP25Data::encodeHeader(unsigned char* data)
::memset(rs, 0x00U, 81U);

for (unsigned int i = 0; i < P25_MI_LENGTH_BYTES; i++)
rs[i] = m_mi[i]; // Message Indicator
rs[i] = m_mi[i]; // Message Indicator

rs[9U] = m_mfId; // Mfg Id.
rs[9U] = m_mfId; // Mfg Id.
rs[10U] = m_algId; // Algorithm ID
rs[11U] = (m_kId >> 8) & 0xFFU; // Key ID MSB
rs[12U] = (m_kId >> 0) & 0xFFU; // Key ID LSB
Expand Down Expand Up @@ -183,18 +182,18 @@ bool CP25Data::decodeLDU1(const unsigned char* data)
unsigned int srcId = (rs[6U] << 16) + (rs[7U] << 8) + rs[8U];

switch (rs[0U]) {
case P25_LCF_GROUP:
m_emergency = (rs[2U] & 0x80U) == 0x80U;
m_dstId = (rs[4U] << 8) + rs[5U];
m_srcId = srcId;
break;
case P25_LCF_PRIVATE:
m_emergency = false;
m_dstId = (rs[3U] << 16) + (rs[4U] << 8) + rs[5U];
m_srcId = srcId;
break;
default:
return false;
case P25_LCF_GROUP:
m_emergency = (rs[2U] & 0x80U) == 0x80U;
m_dstId = (rs[4U] << 8) + rs[5U];
m_srcId = srcId;
break;
case P25_LCF_PRIVATE:
m_emergency = false;
m_dstId = (rs[3U] << 16) + (rs[4U] << 8) + rs[5U];
m_srcId = srcId;
break;
default:
return false;
}

m_lcf = rs[0U];
Expand Down Expand Up @@ -296,7 +295,6 @@ bool CP25Data::decodeLDU2(const unsigned char* data)
m_algId = rs[9U]; // Algorithm ID
if (m_algId != P25_ALGO_UNENCRYPT) {
m_mi = new unsigned char[P25_MI_LENGTH_BYTES];
::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES);
::memcpy(m_mi, rs, P25_MI_LENGTH_BYTES); // Message Indicator

m_kId = (rs[10U] << 8) + rs[11U]; // Key ID
Expand Down Expand Up @@ -388,18 +386,18 @@ bool CP25Data::decodeTSDU(const unsigned char* data)
tsbkValue = (tsbkValue << 8) + tsbk[9U];

switch (m_lcf) {
case P25_LCF_TSBK_CALL_ALERT:
m_dstId = (unsigned int)((tsbkValue >> 24) & 0xFFFFFFU); // Target Radio Address
m_srcId = (unsigned int)(tsbkValue & 0xFFFFFFU); // Source Radio Address
break;
case P25_LCF_TSBK_ACK_RSP_FNE:
m_serviceType = (unsigned char)((tsbkValue >> 56) & 0xFFU); // Service Type
m_dstId = (unsigned int)((tsbkValue >> 24) & 0xFFFFFFU); // Target Radio Address
m_srcId = (unsigned int)(tsbkValue & 0xFFFFFFU); // Source Radio Address
break;
default:
LogMessage("P25, unknown LCF value in TSDU - $%02X", m_lcf);
break;
case P25_LCF_TSBK_CALL_ALERT:
m_dstId = (unsigned int)((tsbkValue >> 24) & 0xFFFFFFU); // Target Radio Address
m_srcId = (unsigned int)(tsbkValue & 0xFFFFFFU); // Source Radio Address
break;
case P25_LCF_TSBK_ACK_RSP_FNE:
m_serviceType = (unsigned char)((tsbkValue >> 56) & 0xFFU); // Service Type
m_dstId = (unsigned int)((tsbkValue >> 24) & 0xFFFFFFU); // Target Radio Address
m_srcId = (unsigned int)(tsbkValue & 0xFFFFFFU); // Source Radio Address
break;
default:
LogMessage("P25, unknown LCF value in TSDU - $%02X", m_lcf);
break;
}

return true;
Expand All @@ -419,22 +417,22 @@ void CP25Data::encodeTSDU(unsigned char* data)
tsbk[1U] = m_mfId;

switch (m_lcf) {
case P25_LCF_TSBK_CALL_ALERT:
tsbkValue = 0U;
tsbkValue = (tsbkValue << 16) + 0U;
tsbkValue = (tsbkValue << 24) + m_dstId; // Target Radio Address
tsbkValue = (tsbkValue << 24) + m_srcId; // Source Radio Address
break;
case P25_LCF_TSBK_ACK_RSP_FNE:
tsbkValue = 0U; // Additional Info. Flag
tsbkValue = (tsbkValue << 1) + 0U; // Extended Address Flag
tsbkValue = (tsbkValue << 16) + (m_serviceType & 0xFF); // Service Type
tsbkValue = (tsbkValue << 32) + m_dstId; // Target Radio Address
tsbkValue = (tsbkValue << 24) + m_srcId; // Source Radio Address
break;
default:
LogMessage("P25, unknown LCF value in TSDU - $%02X", m_lcf);
break;
case P25_LCF_TSBK_CALL_ALERT:
tsbkValue = 0U;
tsbkValue = (tsbkValue << 16) + 0U;
tsbkValue = (tsbkValue << 24) + m_dstId; // Target Radio Address
tsbkValue = (tsbkValue << 24) + m_srcId; // Source Radio Address
break;
case P25_LCF_TSBK_ACK_RSP_FNE:
tsbkValue = 0U; // Additional Info. Flag
tsbkValue = (tsbkValue << 1) + 0U; // Extended Address Flag
tsbkValue = (tsbkValue << 16) + (m_serviceType & 0xFF); // Service Type
tsbkValue = (tsbkValue << 32) + m_dstId; // Target Radio Address
tsbkValue = (tsbkValue << 24) + m_srcId; // Source Radio Address
break;
default:
LogMessage("P25, unknown LCF value in TSDU - $%02X", m_lcf);
break;
}

// split rs value into bytes
Expand Down

0 comments on commit 0571d90

Please sign in to comment.