Skip to content

Commit

Permalink
Extract the DMR talker alias decode logic from Display.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnchain committed Dec 8, 2018
1 parent e4d9a42 commit 50c2500
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 77 deletions.
53 changes: 25 additions & 28 deletions DMRSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ m_rfEmbeddedData(NULL),
m_rfEmbeddedReadN(0U),
m_rfEmbeddedWriteN(1U),
m_rfTalkerId(TALKER_ID_NONE),
m_rfTalkerAlias(NULL),
m_rfTalkerAlias(),
m_netEmbeddedLC(),
m_netEmbeddedData(NULL),
m_netEmbeddedReadN(0U),
Expand Down Expand Up @@ -117,8 +117,6 @@ m_aveRSSI(0U),
m_rssiCount(0U),
m_fp(NULL)
{
m_rfTalkerAlias = new unsigned char[32U];

m_lastFrame = new unsigned char[DMR_FRAME_LENGTH_BYTES + 2U];

m_rfEmbeddedData = new CDMREmbeddedData[2U];
Expand All @@ -132,7 +130,6 @@ CDMRSlot::~CDMRSlot()
delete[] m_rfEmbeddedData;
delete[] m_netEmbeddedData;
delete[] m_lastFrame;
delete[] m_rfTalkerAlias;
}

bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
Expand Down Expand Up @@ -632,9 +629,9 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)

if (!(m_rfTalkerId & TALKER_ID_HEADER)) {
if (m_rfTalkerId == TALKER_ID_NONE)
::memset(m_rfTalkerAlias, '\0', 32U);
::memcpy(m_rfTalkerAlias, data, 6U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "R");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 6U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Header", m_slotNo);
Expand All @@ -651,9 +648,9 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)

if (!(m_rfTalkerId & TALKER_ID_BLOCK1)) {
if (m_rfTalkerId == TALKER_ID_NONE)
::memset(m_rfTalkerAlias, '\0', 32U);
::memcpy(m_rfTalkerAlias + 6U, data, 7U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "R");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 1", m_slotNo);
Expand All @@ -670,9 +667,9 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)

if (!(m_rfTalkerId & TALKER_ID_BLOCK2)) {
if (m_rfTalkerId == TALKER_ID_NONE)
::memset(m_rfTalkerAlias, 0, 32U);
::memcpy(m_rfTalkerAlias + 6U + 7U, data, 7U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "R");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 2", m_slotNo);
Expand All @@ -689,9 +686,9 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)

if (!(m_rfTalkerId & TALKER_ID_BLOCK3)) {
if (m_rfTalkerId == TALKER_ID_NONE)
::memset(m_rfTalkerAlias, '\0', 32U);
::memcpy(m_rfTalkerAlias + 6U + 7U + 7U, data, 7U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "R");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 3", m_slotNo);
Expand Down Expand Up @@ -1426,9 +1423,9 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
case FLCO_TALKER_ALIAS_HEADER:
if (!(m_netTalkerId & TALKER_ID_HEADER)) {
if (!m_netTalkerId)
::memset(m_rfTalkerAlias, '\0', 32U);
::memcpy(m_rfTalkerAlias, data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "N");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Header", m_slotNo);
Expand All @@ -1441,9 +1438,9 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
case FLCO_TALKER_ALIAS_BLOCK1:
if (!(m_netTalkerId & TALKER_ID_BLOCK1)) {
if (!m_netTalkerId)
::memset(m_rfTalkerAlias, '\0', 32U);
::memcpy(m_rfTalkerAlias + 7U, data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "N");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 1", m_slotNo);
Expand All @@ -1456,9 +1453,9 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
case FLCO_TALKER_ALIAS_BLOCK2:
if (!(m_netTalkerId & TALKER_ID_BLOCK2)) {
if (!m_netTalkerId)
::memset(m_rfTalkerAlias, '\0', 32U);
::memcpy(m_rfTalkerAlias + 7U + 7U, data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "N");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data + 2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 2", m_slotNo);
Expand All @@ -1471,9 +1468,9 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
case FLCO_TALKER_ALIAS_BLOCK3:
if (!(m_netTalkerId & TALKER_ID_BLOCK3)) {
if (!m_netTalkerId)
::memset(m_rfTalkerAlias, '\0', 32U);
::memcpy(m_rfTalkerAlias + 7U + 7U + 7U, data+2U, 7U);
m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias, "N");
m_rfTalkerAlias.reset();
m_rfTalkerAlias.add(data+2U, 7U);
m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N");

if (m_dumpTAData) {
::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 3", m_slotNo);
Expand Down
3 changes: 2 additions & 1 deletion DMRSlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "RSSIInterpolator.h"
#include "DMREmbeddedData.h"
#include "DMRNetwork.h"
#include "DMRTA.h"
#include "RingBuffer.h"
#include "StopWatch.h"
#include "DMRLookup.h"
Expand Down Expand Up @@ -69,7 +70,7 @@ class CDMRSlot {
unsigned int m_rfEmbeddedReadN;
unsigned int m_rfEmbeddedWriteN;
unsigned char m_rfTalkerId;
unsigned char* m_rfTalkerAlias;
CDMRTA m_rfTalkerAlias;
CDMREmbeddedData m_netEmbeddedLC;
CDMREmbeddedData* m_netEmbeddedData;
unsigned int m_netEmbeddedReadN;
Expand Down
111 changes: 111 additions & 0 deletions DMRTA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (C) 2015,2016,2017,2018 Jonathan Naylor, G4KLX
* Copyright (C) 2018 by Shawn Chain, BG5HHP
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#include "DMRTA.h"
#include "Log.h"

#include <cstring>

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

CDMRTA::~CDMRTA() {
}

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

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

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

decodeTA();
return true;
}

const unsigned char* CDMRTA::get() {
return (unsigned char*)m_TA;
}

void CDMRTA::reset() {
::memset(m_TA, 0, sizeof(m_TA));
::memset(m_buf, 0, sizeof(m_buf));
m_bufOffset = 0;
}

void CDMRTA::decodeTA() {
unsigned char *b;
unsigned char c;
int j;
unsigned int i,t1,t2, TAsize, TAformat;

unsigned char* talkerAlias = m_buf;

TAformat=(talkerAlias[0]>>6U) & 0x03U;
TAsize = (talkerAlias[0]>>1U) & 0x1FU;
::strncpy(m_TA, "(could not decode)", sizeof(m_TA));

switch (TAformat) {
case 0U: // 7 bit
::memset(m_TA, 0, sizeof(m_TA));
b=&talkerAlias[0];
t1=0; t2=0; c=0;
for (i=0; (i<32U)&&(t2<TAsize); i++) {
for (j=7U;j>=0;j--) {
c = (c<<1U) | (b[i] >> j);
if (++t1==7U) {
if (i>0) {
m_TA[t2++]=c & 0x7FU;
}
t1=0;
c=0;
}
}
}
m_TA[TAsize]=0;
break;
case 1U: // ISO 8 bit
case 2U: // UTF8
::strncpy(m_TA,(char*)talkerAlias+1U, sizeof(m_TA));
break;
case 3U: // UTF16 poor man's conversion
t2=0;
::memset (&m_TA,0,sizeof(m_TA));
for(i=0; (i<15)&&(t2<TAsize); i++) {
if (talkerAlias[2U*i+1U]==0)
m_TA[t2++] = talkerAlias[2U*i+2U];
else
m_TA[t2++] = '?';
}
m_TA[TAsize]=0;
break;
}

LogMessage("DMR Talker Alias (Data Format %u, Received %u/%u char): '%s'", TAformat, ::strlen(m_TA), TAsize, m_TA);
if (::strlen(m_TA)>TAsize) {
if (strlen(m_TA)<29U)
strcat(m_TA," ?");
else
strcpy(m_TA+28U," ?");
}
}
36 changes: 36 additions & 0 deletions DMRTA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2015,2016,2017,2018 Jonathan Naylor, G4KLX
* Copyright (C) 2018 by Shawn Chain, BG5HHP
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#ifndef DMRTA_H
#define DMRTA_H

class CDMRTA {
public:
CDMRTA();
~CDMRTA();

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

protected:
void decodeTA();

private:
char m_TA[32];
unsigned char m_buf[32];
unsigned int m_bufOffset;
};

#endif
43 changes: 2 additions & 41 deletions Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,47 +157,8 @@ void CDisplay::writeDMRRSSI(unsigned int slotNo, unsigned char rssi)

void CDisplay::writeDMRTA(unsigned int slotNo, unsigned char* talkerAlias, const char* type)
{
char TA[32U];
unsigned char *b;
unsigned char c;
int j;
unsigned int i,t1,t2, TAsize, TAformat;

if (strcmp(type," ")==0) { writeDMRTAInt(slotNo, (unsigned char*)TA, type); return; }

TAformat=(talkerAlias[0]>>6U) & 0x03U;
TAsize = (talkerAlias[0]>>1U) & 0x1FU;
::strcpy(TA,"(could not decode)");
switch (TAformat) {
case 0U: // 7 bit
::memset (&TA,0,32U);
b=&talkerAlias[0];
t1=0; t2=0; c=0;
for (i=0;(i<32U)&&(t2<TAsize);i++) {
for (j=7U;j>=0;j--) {
c = (c<<1U) | (b[i] >> j);
if (++t1==7U) { if (i>0) {TA[t2++]=c & 0x7FU; } t1=0; c=0; }
}
}
break;
case 1U: // ISO 8 bit
case 2U: // UTF8
::strcpy(TA,(char*)talkerAlias+1U);
break;
case 3U: // UTF16 poor man's conversion
t2=0;
::memset (&TA,0,32U);
for(i=0;(i<15)&&(t2<TAsize);i++) {
if (talkerAlias[2U*i+1U]==0)
TA[t2++]=talkerAlias[2U*i+2U]; else TA[t2++]='?';
}
TA[TAsize]=0;
break;
}
LogMessage("DMR Talker Alias (Data Format %u, Received %u/%u char): '%s'", TAformat, ::strlen(TA), TAsize, TA);
if (::strlen(TA)>TAsize) { if (strlen(TA)<29U) strcat(TA," ?"); else strcpy(TA+28U," ?"); }
if (strlen((char*)TA)>=4U) writeDMRTAInt(slotNo, (unsigned char*)TA, type);

if (strcmp(type," ")==0) { writeDMRTAInt(slotNo, (unsigned char*)"", type); return; }
if (strlen((char*)talkerAlias)>=4U) writeDMRTAInt(slotNo, (unsigned char*)talkerAlias, type);
}

void CDisplay::writeDMRBER(unsigned int slotNo, float ber)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LDFLAGS = -g

OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o \
NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LDFLAGS = -g -L/usr/local/lib

OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi.Adafruit
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LDFLAGS = -g -L/usr/local/lib

OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi.HD44780
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LDFLAGS = -g -L/usr/local/lib

OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi.OLED
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LDFLAGS = -g -L/usr/local/lib

OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o OLED.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
Expand Down
Loading

0 comments on commit 50c2500

Please sign in to comment.