Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/g4klx/MMDVMHost
Browse files Browse the repository at this point in the history
  • Loading branch information
juribeparada committed Dec 10, 2018
2 parents e1f3567 + 2d0570f commit 5de3bee
Show file tree
Hide file tree
Showing 20 changed files with 444 additions and 156 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(0, data, 7U);
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(1, 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(2, 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(3, 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(0, 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(1, 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(2, 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(3, 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
126 changes: 126 additions & 0 deletions DMRTA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* 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>
#include <cassert>

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

CDMRTA::~CDMRTA()
{
}

bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int len)
{
assert(data != NULL);
if (blockId > 3) {
// invalid block id
reset();
return false;
}

unsigned int offset = blockId * 7;

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

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

return decodeTA();
}

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));
}

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

unsigned char* talkerAlias = m_buf;

unsigned int TAformat = (talkerAlias[0] >> 6U) & 0x03U;
unsigned int 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 = 0U; t2 = 0U; c = 0U;
for (i = 0U; (i < 32U) && (t2 < TAsize); i++) {
for (j = 7; j >= 0; j--) {
c = (c << 1U) | (b[i] >> j);
if (++t1 == 7U) {
if (i > 0U)
m_TA[t2++] = c & 0x7FU;

t1 = 0U;
c = 0U;
}
}
}
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 = 0U; (i < 15U) && (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;
}

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

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

return TAlen >= TAsize;
}
35 changes: 35 additions & 0 deletions DMRTA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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(unsigned int blockId, const unsigned char* data, unsigned int len);
const unsigned char* get();
void reset();

protected:
bool decodeTA();

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

#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 MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ bool CMMDVMHost::createModem()
LogInfo(" RX Frequency: %uHz (%uHz)", rxFrequency, rxFrequency + rxOffset);
LogInfo(" TX Frequency: %uHz (%uHz)", txFrequency, txFrequency + txOffset);

m_modem = new CModem(port, m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, trace, debug);
m_modem = CModem::createModem(port, m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, trace, debug);
m_modem->setSerialParams(protocol,address);
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled, m_nxdnEnabled, m_pocsagEnabled);
m_modem->setLevels(rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, pocsagTXLevel);
Expand Down
Loading

0 comments on commit 5de3bee

Please sign in to comment.