Fixed incorrect DMRTA header packet length from RF side

This commit is contained in:
Shawn Chain 2018-12-09 23:49:15 +08:00
parent 334307cd4a
commit 4ee8dc9dee
3 changed files with 16 additions and 27 deletions

View file

@ -630,7 +630,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
if (!(m_rfTalkerId & TALKER_ID_HEADER)) { if (!(m_rfTalkerId & TALKER_ID_HEADER)) {
if (m_rfTalkerId == TALKER_ID_NONE) if (m_rfTalkerId == TALKER_ID_NONE)
m_rfTalkerAlias.reset(); 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"); m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");
if (m_dumpTAData) { if (m_dumpTAData) {

View file

@ -31,27 +31,14 @@ CDMRTA::~CDMRTA()
bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int len) bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int len)
{ {
assert(data != NULL); assert(data != NULL);
if (blockId > 3) {
unsigned int offset; // invalid block id
switch(blockId) { reset();
case 0: return false;
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;
} }
unsigned int offset = blockId * 7;
if (offset + len >= sizeof(m_buf)) { if (offset + len >= sizeof(m_buf)) {
// buffer overflow // buffer overflow
reset(); reset();
@ -60,8 +47,7 @@ bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int l
::memcpy(m_buf + offset, data, len); ::memcpy(m_buf + offset, data, len);
decodeTA(); return decodeTA();
return true;
} }
const unsigned char* CDMRTA::get() const unsigned char* CDMRTA::get()
@ -75,7 +61,7 @@ void CDMRTA::reset()
::memset(m_buf, 0, sizeof(m_buf)); ::memset(m_buf, 0, sizeof(m_buf));
} }
void CDMRTA::decodeTA() bool CDMRTA::decodeTA()
{ {
unsigned char *b; unsigned char *b;
unsigned char c; unsigned char c;
@ -126,12 +112,15 @@ void CDMRTA::decodeTA()
break; 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 (TAlen > TAsize) {
if (strlen(m_TA) < 29U) if (TAlen < 29U)
strcat(m_TA," ?"); strcat(m_TA," ?");
else else
strcpy(m_TA + 28U," ?"); strcpy(m_TA + 28U," ?");
} }
return TAlen >= TAsize;
} }

View file

@ -25,7 +25,7 @@ public:
void reset(); void reset();
protected: protected:
void decodeTA(); bool decodeTA();
private: private:
char m_TA[32]; char m_TA[32];