Skip to content

Commit

Permalink
Upgrade the Embedded Data regeneration.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Jan 10, 2017
1 parent 42a24de commit dfa3595
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 110 deletions.
135 changes: 71 additions & 64 deletions DMREmbeddedData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "DMREmbeddedLC.h"
#include "DMREmbeddedData.h"

#include "Hamming.h"
#include "Utils.h"
Expand All @@ -26,8 +26,7 @@
#include <cassert>
#include <cstring>

CDMREmbeddedLC::CDMREmbeddedLC(unsigned int slotNo) :
m_slotNo(slotNo),
CDMREmbeddedData::CDMREmbeddedData() :
m_raw(NULL),
m_state(LCS_NONE),
m_data(NULL),
Expand All @@ -38,14 +37,14 @@ m_valid(false)
m_data = new bool[72U];
}

CDMREmbeddedLC::~CDMREmbeddedLC()
CDMREmbeddedData::~CDMREmbeddedData()
{
delete[] m_raw;
delete[] m_data;
}

// Add LC data (which may consist of 4 blocks) to the data store
bool CDMREmbeddedLC::addData(const unsigned char* data, unsigned char lcss)
bool CDMREmbeddedData::addData(const unsigned char* data, unsigned char lcss)
{
assert(data != NULL);

Expand All @@ -64,6 +63,7 @@ bool CDMREmbeddedLC::addData(const unsigned char* data, unsigned char lcss)
// Show we are ready for the next LC block
m_state = LCS_FIRST;
m_valid = false;

return false;
}

Expand All @@ -74,6 +74,7 @@ bool CDMREmbeddedLC::addData(const unsigned char* data, unsigned char lcss)

// Show we are ready for the next LC block
m_state = LCS_SECOND;

return false;
}

Expand All @@ -84,6 +85,7 @@ bool CDMREmbeddedLC::addData(const unsigned char* data, unsigned char lcss)

// Show we are ready for the final LC block
m_state = LCS_THIRD;

return false;
}

Expand All @@ -92,24 +94,34 @@ bool CDMREmbeddedLC::addData(const unsigned char* data, unsigned char lcss)
for (unsigned int a = 0U; a < 32U; a++)
m_raw[a + 96U] = rawData[a + 4U];

// Show that we're not ready for any more data
m_state = LCS_NONE;

// Process the complete data block
return processEmbeddedData();
}
decodeEmbeddedData();
if (m_valid)
encodeEmbeddedData();

// Is this a single block embedded LC
if (lcss == 0U)
return false;
return m_valid;
}

return false;
}

void CDMREmbeddedLC::setData(const CDMRLC& lc)
void CDMREmbeddedData::setLC(const CDMRLC& lc)
{
lc.getData(m_data);

m_FLCO = lc.getFLCO();
m_valid = true;

encodeEmbeddedData();
}

void CDMREmbeddedData::encodeEmbeddedData()
{
bool lcData[72U];
lc.getData(lcData);

unsigned int crc;
CCRC::encodeFiveBit(lcData, crc);
CCRC::encodeFiveBit(m_data, crc);

bool data[128U];
::memset(data, 0x00U, 128U * sizeof(bool));
Expand All @@ -122,19 +134,19 @@ void CDMREmbeddedLC::setData(const CDMRLC& lc)

unsigned int b = 0U;
for (unsigned int a = 0U; a < 11U; a++, b++)
data[a] = lcData[b];
data[a] = m_data[b];
for (unsigned int a = 16U; a < 27U; a++, b++)
data[a] = lcData[b];
data[a] = m_data[b];
for (unsigned int a = 32U; a < 42U; a++, b++)
data[a] = lcData[b];
data[a] = m_data[b];
for (unsigned int a = 48U; a < 58U; a++, b++)
data[a] = lcData[b];
data[a] = m_data[b];
for (unsigned int a = 64U; a < 74U; a++, b++)
data[a] = lcData[b];
data[a] = m_data[b];
for (unsigned int a = 80U; a < 90U; a++, b++)
data[a] = lcData[b];
data[a] = m_data[b];
for (unsigned int a = 96U; a < 106U; a++, b++)
data[a] = lcData[b];
data[a] = m_data[b];

// Hamming (16,11,4) check each row except the last one
for (unsigned int a = 0U; a < 112U; a += 16U)
Expand All @@ -154,7 +166,7 @@ void CDMREmbeddedLC::setData(const CDMRLC& lc)
}
}

unsigned char CDMREmbeddedLC::getData(unsigned char* data, unsigned char n) const
unsigned char CDMREmbeddedData::getData(unsigned char* data, unsigned char n) const
{
assert(data != NULL);

Expand Down Expand Up @@ -198,7 +210,7 @@ unsigned char CDMREmbeddedLC::getData(unsigned char* data, unsigned char n) cons
}

// Unpack and error check an embedded LC
bool CDMREmbeddedLC::processEmbeddedData()
void CDMREmbeddedData::decodeEmbeddedData()
{
// The data is unpacked downwards in columns
bool data[128U];
Expand All @@ -215,14 +227,14 @@ bool CDMREmbeddedLC::processEmbeddedData()
// Hamming (16,11,4) check each row except the last one
for (unsigned int a = 0U; a < 112U; a += 16U) {
if (!CHamming::decode16114(data + a))
return false;
return;
}

// Check the parity bits
for (unsigned int a = 0U; a < 16U; a++) {
bool parity = data[a + 0U] ^ data[a + 16U] ^ data[a + 32U] ^ data[a + 48U] ^ data[a + 64U] ^ data[a + 80U] ^ data[a + 96U] ^ data[a + 112U];
if (parity)
return false;
return;
}

// We have passed the Hamming check so extract the actual payload
Expand Down Expand Up @@ -252,52 +264,17 @@ bool CDMREmbeddedLC::processEmbeddedData()

// Now CRC check this
if (!CCRC::checkFiveBit(m_data, crc))
return false;
return;

m_valid = true;

// Extract the FLCO
unsigned char flco;
CUtils::bitsToByteBE(m_data + 0U, flco);
m_FLCO = FLCO(flco & 0x3FU);

char text[80U];

// Only generate the LC when it's the correct FLCO
switch (m_FLCO) {
case FLCO_GROUP:
case FLCO_USER_USER:
// ::sprintf(text, "DMR Slot %u, Embedded LC Data", m_slotNo);
// CUtils::dump(1U, text, m_data, 72U);
return true;
case FLCO_GPS_INFO:
::sprintf(text, "DMR Slot %u, Embedded GPS Info", m_slotNo);
CUtils::dump(1U, text, m_data, 72U);
return true;
case FLCO_TALKER_ALIAS_HEADER:
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Header", m_slotNo);
CUtils::dump(1U, text, m_data, 72U);
return true;
case FLCO_TALKER_ALIAS_BLOCK1:
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 1", m_slotNo);
CUtils::dump(1U, text, m_data, 72U);
return true;
case FLCO_TALKER_ALIAS_BLOCK2:
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 2", m_slotNo);
CUtils::dump(1U, text, m_data, 72U);
return true;
case FLCO_TALKER_ALIAS_BLOCK3:
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 3", m_slotNo);
CUtils::dump(1U, text, m_data, 72U);
return true;
default:
::sprintf(text, "DMR Slot %u, Unknown Embedded Data", m_slotNo);
CUtils::dump(1U, text, m_data, 72U);
return false;
}
}

CDMRLC* CDMREmbeddedLC::getLC() const
CDMRLC* CDMREmbeddedData::getLC() const
{
if (!m_valid)
return NULL;
Expand All @@ -308,8 +285,38 @@ CDMRLC* CDMREmbeddedLC::getLC() const
return new CDMRLC(m_data);
}

void CDMREmbeddedLC::reset()
bool CDMREmbeddedData::isValid() const
{
return m_valid;
}

FLCO CDMREmbeddedData::getFLCO() const
{
return m_FLCO;
}

void CDMREmbeddedData::reset()
{
m_state = LCS_NONE;
m_valid = false;
}

bool CDMREmbeddedData::getRawData(unsigned char* data) const
{
assert(data != NULL);

if (!m_valid)
return false;

CUtils::bitsToByteBE(m_data + 0U, data[0U]);
CUtils::bitsToByteBE(m_data + 8U, data[1U]);
CUtils::bitsToByteBE(m_data + 16U, data[2U]);
CUtils::bitsToByteBE(m_data + 24U, data[3U]);
CUtils::bitsToByteBE(m_data + 32U, data[4U]);
CUtils::bitsToByteBE(m_data + 40U, data[5U]);
CUtils::bitsToByteBE(m_data + 48U, data[6U]);
CUtils::bitsToByteBE(m_data + 56U, data[7U]);
CUtils::bitsToByteBE(m_data + 65U, data[8U]);

return true;
}
23 changes: 14 additions & 9 deletions DMREmbeddedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef DMREmbeddedLC_H
#define DMREmbeddedLC_H
#ifndef DMREmbeddedData_H
#define DMREmbeddedData_H

#include "DMRDefines.h"
#include "DMRLC.h"
Expand All @@ -29,30 +29,35 @@ enum LC_STATE {
LCS_THIRD
};

class CDMREmbeddedLC
class CDMREmbeddedData
{
public:
CDMREmbeddedLC(unsigned int slotNo);
~CDMREmbeddedLC();
CDMREmbeddedData();
~CDMREmbeddedData();

bool addData(const unsigned char* data, unsigned char lcss);
CDMRLC* getLC() const;

void setData(const CDMRLC& lc);
CDMRLC* getLC() const;
void setLC(const CDMRLC& lc);

unsigned char getData(unsigned char* data, unsigned char n) const;

bool getRawData(unsigned char* data) const;

bool isValid() const;
FLCO getFLCO() const;

void reset();

private:
unsigned int m_slotNo;
bool* m_raw;
LC_STATE m_state;
bool* m_data;
FLCO m_FLCO;
bool m_valid;

bool processEmbeddedData();
void decodeEmbeddedData();
void encodeEmbeddedData();
};

#endif
Loading

0 comments on commit dfa3595

Please sign in to comment.