Skip to content

Commit

Permalink
Fixed incorrect DMRTA header packet length from RF side
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnchain committed Dec 9, 2018
1 parent 334307c commit 4ee8dc9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion 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(0, data, 6U);
m_rfTalkerAlias.add(0, data, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
Expand Down
39 changes: 14 additions & 25 deletions DMRTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,14 @@ CDMRTA::~CDMRTA()
bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int len)
{
assert(data != NULL);

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 (blockId > 3) {
// invalid block id
reset();
return false;
}

unsigned int offset = blockId * 7;

if (offset + len >= sizeof(m_buf)) {
// buffer overflow
reset();
Expand All @@ -60,8 +47,7 @@ bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int l

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

decodeTA();
return true;
return decodeTA();
}

const unsigned char* CDMRTA::get()
Expand All @@ -75,7 +61,7 @@ void CDMRTA::reset()
::memset(m_buf, 0, sizeof(m_buf));
}

void CDMRTA::decodeTA()
bool CDMRTA::decodeTA()
{
unsigned char *b;
unsigned char c;
Expand Down Expand Up @@ -126,12 +112,15 @@ void CDMRTA::decodeTA()
break;
}

LogMessage("DMR Talker Alias (Data Format %u, Received %u/%u char): '%s'", TAformat, ::strlen(m_TA), TAsize, m_TA);
size_t TAlen = ::strlen(m_TA);
LogMessage("DMR Talker Alias (Data Format %u, Received %u/%u char): '%s'", TAformat, TAlen, TAsize, m_TA);

if (::strlen(m_TA) > TAsize) {
if (strlen(m_TA) < 29U)
if (TAlen > TAsize) {
if (TAlen < 29U)
strcat(m_TA," ?");
else
strcpy(m_TA + 28U," ?");
}

return TAlen >= TAsize;
}
2 changes: 1 addition & 1 deletion DMRTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CDMRTA {
void reset();

protected:
void decodeTA();
bool decodeTA();

private:
char m_TA[32];
Expand Down

0 comments on commit 4ee8dc9

Please sign in to comment.