Skip to content

Commit

Permalink
Finally fix the (re)generation of Full LC PDUs.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Feb 22, 2016
1 parent e2c7a28 commit fe362d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
7 changes: 2 additions & 5 deletions DMRFullLC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "DMRDefines.h"
#include "RS129.h"
#include "Utils.h"
#include "Log.h"

#include <cstdio>
Expand Down Expand Up @@ -60,12 +61,8 @@ CDMRLC* CDMRFullLC::decode(const unsigned char* data, unsigned char type)
return NULL;
}

if (!CRS129::check(lcData)) {
::LogDebug("Checksum failed for the LC");
CDMRLC lc(lcData);
LogDebug("Invalid LC, src = %u, dst = %s%u", lc.getSrcId(), lc.getFLCO() == FLCO_GROUP ? "TG " : "", lc.getDstId());
if (!CRS129::check(lcData))
return NULL;
}

return new CDMRLC(lcData);
}
Expand Down
22 changes: 21 additions & 1 deletion DMRLC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,63 @@

CDMRLC::CDMRLC(FLCO flco, unsigned int srcId, unsigned int dstId) :
m_PF(false),
m_R(false),
m_FLCO(flco),
m_FID(0U),
m_options(0U),
m_srcId(srcId),
m_dstId(dstId)
{
}

CDMRLC::CDMRLC(const unsigned char* bytes) :
m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
m_srcId(0U),
m_dstId(0U)
{
assert(bytes != NULL);

m_PF = (bytes[0U] & 0x80U) == 0x80U;
m_R = (bytes[0U] & 0x40U) == 0x40U;

m_FLCO = FLCO(bytes[0U] & 0x3FU);

m_FID = bytes[1U];

m_options = bytes[2U];

m_dstId = bytes[3U] << 16 | bytes[4U] << 8 | bytes[5U];
m_srcId = bytes[6U] << 16 | bytes[7U] << 8 | bytes[8U];
}

CDMRLC::CDMRLC(const bool* bits) :
m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
m_srcId(0U),
m_dstId(0U)
{
assert(bits != NULL);

m_PF = bits[0U];
m_R = bits[1U];

unsigned char temp1, temp2;
unsigned char temp1, temp2, temp3;
CUtils::bitsToByteBE(bits + 0U, temp1);
m_FLCO = FLCO(temp1 & 0x3FU);

CUtils::bitsToByteBE(bits + 8U, temp2);
m_FID = temp2;

CUtils::bitsToByteBE(bits + 16U, temp3);
m_options = temp3;

unsigned char d1, d2, d3;
CUtils::bitsToByteBE(bits + 24U, d1);
CUtils::bitsToByteBE(bits + 32U, d2);
Expand All @@ -85,8 +98,10 @@ m_dstId(0U)

CDMRLC::CDMRLC() :
m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
m_srcId(0U),
m_dstId(0U)
{
Expand All @@ -105,8 +120,13 @@ void CDMRLC::getData(unsigned char* bytes) const
if (m_PF)
bytes[0U] |= 0x80U;

if (m_R)
bytes[0U] |= 0x40U;

bytes[1U] = m_FID;

bytes[2U] = m_options;

bytes[3U] = m_dstId >> 16;
bytes[4U] = m_dstId >> 8;
bytes[5U] = m_dstId >> 0;
Expand Down
2 changes: 2 additions & 0 deletions DMRLC.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ class CDMRLC

private:
bool m_PF;
bool m_R;
FLCO m_FLCO;
unsigned char m_FID;
unsigned char m_options;
unsigned int m_srcId;
unsigned int m_dstId;
};
Expand Down

0 comments on commit fe362d6

Please sign in to comment.