Skip to content

Commit

Permalink
Bugfix of the DMRTA decoding for blocks comes in with random order
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnchain committed Dec 9, 2018
1 parent afdb36f commit 334307c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
16 changes: 8 additions & 8 deletions DMRSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
if (!(m_rfTalkerId & TALKER_ID_HEADER)) {
if (m_rfTalkerId == TALKER_ID_NONE)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 6U);
m_rfTalkerAlias.add(0, data, 6U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
Expand All @@ -649,7 +649,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
if (!(m_rfTalkerId & TALKER_ID_BLOCK1)) {
if (m_rfTalkerId == TALKER_ID_NONE)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 7U);
m_rfTalkerAlias.add(1, data, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
Expand All @@ -668,7 +668,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
if (!(m_rfTalkerId & TALKER_ID_BLOCK2)) {
if (m_rfTalkerId == TALKER_ID_NONE)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 7U);
m_rfTalkerAlias.add(2, data, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
Expand All @@ -687,7 +687,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
if (!(m_rfTalkerId & TALKER_ID_BLOCK3)) {
if (m_rfTalkerId == TALKER_ID_NONE)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 7U);
m_rfTalkerAlias.add(3, data, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
Expand Down Expand Up @@ -1424,7 +1424,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
if (!(m_netTalkerId & TALKER_ID_HEADER)) {
if (!m_netTalkerId)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data + 2U, 7U);
m_rfTalkerAlias.add(0, data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
Expand All @@ -1439,7 +1439,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
if (!(m_netTalkerId & TALKER_ID_BLOCK1)) {
if (!m_netTalkerId)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data + 2U, 7U);
m_rfTalkerAlias.add(1, data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
Expand All @@ -1454,7 +1454,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
if (!(m_netTalkerId & TALKER_ID_BLOCK2)) {
if (!m_netTalkerId)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data + 2U, 7U);
m_rfTalkerAlias.add(2, data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
Expand All @@ -1469,7 +1469,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
if (!(m_netTalkerId & TALKER_ID_BLOCK3)) {
if (!m_netTalkerId)
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data+2U, 7U);
m_rfTalkerAlias.add(3, data+2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
Expand Down
31 changes: 24 additions & 7 deletions DMRTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,45 @@

CDMRTA::CDMRTA() :
m_TA(),
m_buf(),
m_bufOffset(0)
m_buf()
{
}

CDMRTA::~CDMRTA()
{
}

bool CDMRTA::add(const unsigned char* data, unsigned int len)
bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int len)
{
assert(data != NULL);

if (m_bufOffset + len >= sizeof(m_buf)) {
unsigned int offset;
switch(blockId) {
case 0:
offset = 0;
break;
case 1:
offset = 6;
break;
case 2:
offset = 13;
break;
case 3:
offset = 20;
break;
default:
// invalid block id
reset();
return false;
}

if (offset + len >= sizeof(m_buf)) {
// buffer overflow
reset();
return false;
}

::memcpy(m_buf + m_bufOffset, data, len);
m_bufOffset += len;
::memcpy(m_buf + offset, data, len);

decodeTA();
return true;
Expand All @@ -55,7 +73,6 @@ void CDMRTA::reset()
{
::memset(m_TA, 0, sizeof(m_TA));
::memset(m_buf, 0, sizeof(m_buf));
m_bufOffset = 0;
}

void CDMRTA::decodeTA()
Expand Down
3 changes: 1 addition & 2 deletions DMRTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CDMRTA {
CDMRTA();
~CDMRTA();

bool add(const unsigned char* data, unsigned int len);
bool add(unsigned int blockId, const unsigned char* data, unsigned int len);
const unsigned char* get();
void reset();

Expand All @@ -30,7 +30,6 @@ class CDMRTA {
private:
char m_TA[32];
unsigned char m_buf[32];
unsigned int m_bufOffset;
};

#endif

0 comments on commit 334307c

Please sign in to comment.