Finally fix the (re)generation of Full LC PDUs.

This commit is contained in:
Jonathan Naylor 2016-02-22 22:27:03 +00:00
parent e2c7a28fb9
commit fe362d6e2d
3 changed files with 25 additions and 6 deletions

View file

@ -21,6 +21,7 @@
#include "DMRDefines.h" #include "DMRDefines.h"
#include "RS129.h" #include "RS129.h"
#include "Utils.h"
#include "Log.h" #include "Log.h"
#include <cstdio> #include <cstdio>
@ -60,12 +61,8 @@ CDMRLC* CDMRFullLC::decode(const unsigned char* data, unsigned char type)
return NULL; return NULL;
} }
if (!CRS129::check(lcData)) { 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());
return NULL; return NULL;
}
return new CDMRLC(lcData); return new CDMRLC(lcData);
} }

View file

@ -25,8 +25,10 @@
CDMRLC::CDMRLC(FLCO flco, unsigned int srcId, unsigned int dstId) : CDMRLC::CDMRLC(FLCO flco, unsigned int srcId, unsigned int dstId) :
m_PF(false), m_PF(false),
m_R(false),
m_FLCO(flco), m_FLCO(flco),
m_FID(0U), m_FID(0U),
m_options(0U),
m_srcId(srcId), m_srcId(srcId),
m_dstId(dstId) m_dstId(dstId)
{ {
@ -34,41 +36,52 @@ m_dstId(dstId)
CDMRLC::CDMRLC(const unsigned char* bytes) : CDMRLC::CDMRLC(const unsigned char* bytes) :
m_PF(false), m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP), m_FLCO(FLCO_GROUP),
m_FID(0U), m_FID(0U),
m_options(0U),
m_srcId(0U), m_srcId(0U),
m_dstId(0U) m_dstId(0U)
{ {
assert(bytes != NULL); assert(bytes != NULL);
m_PF = (bytes[0U] & 0x80U) == 0x80U; m_PF = (bytes[0U] & 0x80U) == 0x80U;
m_R = (bytes[0U] & 0x40U) == 0x40U;
m_FLCO = FLCO(bytes[0U] & 0x3FU); m_FLCO = FLCO(bytes[0U] & 0x3FU);
m_FID = bytes[1U]; m_FID = bytes[1U];
m_options = bytes[2U];
m_dstId = bytes[3U] << 16 | bytes[4U] << 8 | bytes[5U]; m_dstId = bytes[3U] << 16 | bytes[4U] << 8 | bytes[5U];
m_srcId = bytes[6U] << 16 | bytes[7U] << 8 | bytes[8U]; m_srcId = bytes[6U] << 16 | bytes[7U] << 8 | bytes[8U];
} }
CDMRLC::CDMRLC(const bool* bits) : CDMRLC::CDMRLC(const bool* bits) :
m_PF(false), m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP), m_FLCO(FLCO_GROUP),
m_FID(0U), m_FID(0U),
m_options(0U),
m_srcId(0U), m_srcId(0U),
m_dstId(0U) m_dstId(0U)
{ {
assert(bits != NULL); assert(bits != NULL);
m_PF = bits[0U]; m_PF = bits[0U];
m_R = bits[1U];
unsigned char temp1, temp2; unsigned char temp1, temp2, temp3;
CUtils::bitsToByteBE(bits + 0U, temp1); CUtils::bitsToByteBE(bits + 0U, temp1);
m_FLCO = FLCO(temp1 & 0x3FU); m_FLCO = FLCO(temp1 & 0x3FU);
CUtils::bitsToByteBE(bits + 8U, temp2); CUtils::bitsToByteBE(bits + 8U, temp2);
m_FID = temp2; m_FID = temp2;
CUtils::bitsToByteBE(bits + 16U, temp3);
m_options = temp3;
unsigned char d1, d2, d3; unsigned char d1, d2, d3;
CUtils::bitsToByteBE(bits + 24U, d1); CUtils::bitsToByteBE(bits + 24U, d1);
CUtils::bitsToByteBE(bits + 32U, d2); CUtils::bitsToByteBE(bits + 32U, d2);
@ -85,8 +98,10 @@ m_dstId(0U)
CDMRLC::CDMRLC() : CDMRLC::CDMRLC() :
m_PF(false), m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP), m_FLCO(FLCO_GROUP),
m_FID(0U), m_FID(0U),
m_options(0U),
m_srcId(0U), m_srcId(0U),
m_dstId(0U) m_dstId(0U)
{ {
@ -105,8 +120,13 @@ void CDMRLC::getData(unsigned char* bytes) const
if (m_PF) if (m_PF)
bytes[0U] |= 0x80U; bytes[0U] |= 0x80U;
if (m_R)
bytes[0U] |= 0x40U;
bytes[1U] = m_FID; bytes[1U] = m_FID;
bytes[2U] = m_options;
bytes[3U] = m_dstId >> 16; bytes[3U] = m_dstId >> 16;
bytes[4U] = m_dstId >> 8; bytes[4U] = m_dstId >> 8;
bytes[5U] = m_dstId >> 0; bytes[5U] = m_dstId >> 0;

View file

@ -50,8 +50,10 @@ public:
private: private:
bool m_PF; bool m_PF;
bool m_R;
FLCO m_FLCO; FLCO m_FLCO;
unsigned char m_FID; unsigned char m_FID;
unsigned char m_options;
unsigned int m_srcId; unsigned int m_srcId;
unsigned int m_dstId; unsigned int m_dstId;
}; };