diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 825e80b3..f341e1e5 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2021 Jonathan Naylor, G4KLX + * Copyright (C) 2015-2021,2023 Jonathan Naylor, G4KLX * * 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 @@ -81,12 +81,13 @@ m_rfEmbeddedData(NULL), m_rfEmbeddedReadN(0U), m_rfEmbeddedWriteN(1U), m_rfTalkerId(TALKER_ID_NONE), -m_rfTalkerAlias(), +m_rfTalkerAlias(slotNo), m_netEmbeddedLC(), m_netEmbeddedData(NULL), m_netEmbeddedReadN(0U), m_netEmbeddedWriteN(1U), m_netTalkerId(TALKER_ID_NONE), +m_netTalkerAlias(slotNo), m_rfLC(NULL), m_netLC(NULL), m_rfSeqNo(0U), @@ -661,7 +662,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len) case FLCO_GPS_INFO: if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded GPS Info", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); logGPSPosition(data); } if (m_network != NULL) @@ -675,12 +676,12 @@ 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 + 2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R"); + m_rfTalkerAlias.add(0U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias.get(), "R"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Header", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_rfTalkerId |= TALKER_ID_HEADER; @@ -694,12 +695,12 @@ 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(1, data + 2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R"); + m_rfTalkerAlias.add(1U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias.get(), "R"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 1", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_rfTalkerId |= TALKER_ID_BLOCK1; @@ -713,12 +714,12 @@ 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(2, data + 2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R"); + m_rfTalkerAlias.add(2U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias.get(), "R"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 2", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_rfTalkerId |= TALKER_ID_BLOCK2; @@ -732,12 +733,12 @@ 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(3, data + 2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "R"); + m_rfTalkerAlias.add(3U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_rfTalkerAlias.get(), "R"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 3", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_rfTalkerId |= TALKER_ID_BLOCK3; @@ -1494,20 +1495,20 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) case FLCO_GPS_INFO: if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded GPS Info", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); logGPSPosition(data); } break; case FLCO_TALKER_ALIAS_HEADER: if (!(m_netTalkerId & TALKER_ID_HEADER)) { if (!m_netTalkerId) - m_rfTalkerAlias.reset(); - m_rfTalkerAlias.add(0, data + 2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N"); + m_netTalkerAlias.reset(); + m_netTalkerAlias.add(0U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_netTalkerAlias.get(), "N"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Header", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_netTalkerId |= TALKER_ID_HEADER; @@ -1516,13 +1517,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) case FLCO_TALKER_ALIAS_BLOCK1: if (!(m_netTalkerId & TALKER_ID_BLOCK1)) { if (!m_netTalkerId) - m_rfTalkerAlias.reset(); - m_rfTalkerAlias.add(1, data + 2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N"); + m_netTalkerAlias.reset(); + m_netTalkerAlias.add(1U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_netTalkerAlias.get(), "N"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 1", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_netTalkerId |= TALKER_ID_BLOCK1; @@ -1531,13 +1532,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) case FLCO_TALKER_ALIAS_BLOCK2: if (!(m_netTalkerId & TALKER_ID_BLOCK2)) { if (!m_netTalkerId) - m_rfTalkerAlias.reset(); - m_rfTalkerAlias.add(2, data + 2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N"); + m_netTalkerAlias.reset(); + m_netTalkerAlias.add(2U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_netTalkerAlias.get(), "N"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 2", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_netTalkerId |= TALKER_ID_BLOCK2; @@ -1546,13 +1547,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) case FLCO_TALKER_ALIAS_BLOCK3: if (!(m_netTalkerId & TALKER_ID_BLOCK3)) { if (!m_netTalkerId) - m_rfTalkerAlias.reset(); - m_rfTalkerAlias.add(3, data+2U, 7U); - m_display->writeDMRTA(m_slotNo, (unsigned char*)m_rfTalkerAlias.get(), "N"); + m_netTalkerAlias.reset(); + m_netTalkerAlias.add(3U, data + 2U, 7U); + m_display->writeDMRTA(m_slotNo, m_netTalkerAlias.get(), "N"); if (m_dumpTAData) { ::sprintf(text, "DMR Slot %u, Embedded Talker Alias Block 3", m_slotNo); - CUtils::dump(2U, text, data, 9U); + CUtils::dump(1U, text, data, 9U); } m_netTalkerId |= TALKER_ID_BLOCK3; diff --git a/DMRSlot.h b/DMRSlot.h index 62bcc914..d3d58a26 100644 --- a/DMRSlot.h +++ b/DMRSlot.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2021 by Jonathan Naylor G4KLX + * Copyright (C) 2015-2021,2023 by Jonathan Naylor G4KLX * * 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 @@ -80,6 +80,7 @@ class CDMRSlot { unsigned int m_netEmbeddedReadN; unsigned int m_netEmbeddedWriteN; unsigned char m_netTalkerId; + CDMRTA m_netTalkerAlias; CDMRLC* m_rfLC; CDMRLC* m_netLC; unsigned char m_rfSeqNo; @@ -132,7 +133,7 @@ class CDMRSlot { static unsigned char* m_idle; - static FLCO m_flco1; + static FLCO m_flco1; static unsigned char m_id1; static ACTIVITY_TYPE m_activity1; static FLCO m_flco2; diff --git a/DMRTA.cpp b/DMRTA.cpp index 9e60673f..055116ea 100644 --- a/DMRTA.cpp +++ b/DMRTA.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2015,2016,2017,2018 Jonathan Naylor, G4KLX +* Copyright (C) 2015,2016,2017,2018,2023 Jonathan Naylor, G4KLX * Copyright (C) 2018 by Shawn Chain, BG5HHP * * This program is free software; you can redistribute it and/or modify @@ -18,8 +18,9 @@ #include #include -CDMRTA::CDMRTA() : -m_TA(), +CDMRTA::CDMRTA(unsigned int slotNo) : +m_slotNo(slotNo), +m_ta(), m_buf() { } @@ -31,13 +32,14 @@ CDMRTA::~CDMRTA() bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int len) { assert(data != NULL); - if (blockId > 3) { + + if (blockId > 3U) { // invalid block id reset(); return false; } - unsigned int offset = blockId * 7; + unsigned int offset = blockId * 7U; if (offset + len >= sizeof(m_buf)) { // buffer overflow @@ -52,75 +54,83 @@ bool CDMRTA::add(unsigned int blockId, const unsigned char* data, unsigned int l const unsigned char* CDMRTA::get() { - return (unsigned char*)m_TA; + return (unsigned char*)m_ta; } void CDMRTA::reset() { - ::memset(m_TA, 0, sizeof(m_TA)); - ::memset(m_buf, 0, sizeof(m_buf)); + ::memset(m_ta, 0x00U, sizeof(m_ta)); + ::memset(m_buf, 0x00U, 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; - ::strcpy(m_TA, "(could not decode)"); - - 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 - ::memcpy(m_TA, 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; + unsigned int taFormat = (m_buf[0] >> 6U) & 0x03U; + unsigned int taSize = (m_buf[0] >> 1U) & 0x1FU; + ::strcpy(m_ta, "(could not decode)"); + + switch (taFormat) { + case 0U: { // 7 bit + ::memset(m_ta, 0x00U, sizeof(m_ta)); + + unsigned char* b = m_buf; + unsigned int t1 = 0U; + unsigned int t2 = 0U; + unsigned char c = 0U; + + for (unsigned int i = 0U; (i < 32U) && (t2 < taSize); i++) { + for (int 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 + ::memcpy(m_ta, m_buf + 1U, sizeof(m_ta)); + break; + + case 3U: { // UTF16 poor man's conversion + unsigned int t2 = 0U; + ::memset(&m_ta, 0x00U, sizeof(m_ta)); + + for (unsigned int i = 0U; (i < 15U) && (t2 < taSize); i++) { + if (m_buf[2U * i + 1U] == 0) + m_ta[t2++] = m_buf[2U * i + 2U]; + else + m_ta[t2++] = '?'; + } + + m_ta[taSize] = 0; + } + break; + } + + size_t taLen = ::strlen(m_ta); + + if (taLen == taSize) + LogMessage("DMR Slot %u, Talker Alias \"%s\"", m_slotNo, m_ta); + + LogDebug("DMR Slot %u, Talker Alias (Data Format %u, Received %u/%u char): '%s'", m_slotNo, taFormat, taLen, taSize, m_ta); + + if (taLen > taSize) { + if (taLen < 29U) + ::strcat(m_ta, " ?"); + else + ::strcpy(m_ta + 28U, " ?"); + } + + return taLen >= taSize; } + diff --git a/DMRTA.h b/DMRTA.h index d53f93f5..ccf48d9c 100644 --- a/DMRTA.h +++ b/DMRTA.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2015,2016,2017,2018 Jonathan Naylor, G4KLX +* Copyright (C) 2015,2016,2017,2018,2023 Jonathan Naylor, G4KLX * Copyright (C) 2018 by Shawn Chain, BG5HHP * * This program is free software; you can redistribute it and/or modify @@ -17,19 +17,22 @@ class CDMRTA { public: - CDMRTA(); - ~CDMRTA(); + CDMRTA(unsigned int slotNo); + ~CDMRTA(); - bool add(unsigned int blockId, const unsigned char* data, unsigned int len); - const unsigned char* get(); - void reset(); + bool add(unsigned int blockId, const unsigned char* data, unsigned int len); + + const unsigned char* get(); + + void reset(); protected: - bool decodeTA(); + bool decodeTA(); private: - char m_TA[32]; - unsigned char m_buf[32]; + unsigned int m_slotNo; + char m_ta[32]; + unsigned char m_buf[32]; }; #endif diff --git a/Display.cpp b/Display.cpp index ebb18644..718ed84f 100644 --- a/Display.cpp +++ b/Display.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2021,2023 by Jonathan Naylor G4KLX * * 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 @@ -189,10 +189,15 @@ void CDisplay::writeDMRRSSI(unsigned int slotNo, unsigned char rssi) writeDMRRSSIInt(slotNo, rssi); } -void CDisplay::writeDMRTA(unsigned int slotNo, unsigned char* talkerAlias, const char* type) +void CDisplay::writeDMRTA(unsigned int slotNo, const unsigned char* talkerAlias, const char* type) { - if (strcmp(type," ")==0) { writeDMRTAInt(slotNo, (unsigned char*)"", type); return; } - if (strlen((char*)talkerAlias)>=4U) writeDMRTAInt(slotNo, (unsigned char*)talkerAlias, 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) @@ -487,7 +492,7 @@ void CDisplay::writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi) { } -void CDisplay::writeDMRTAInt(unsigned int slotNo, unsigned char* talkerAlias, const char* type) +void CDisplay::writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type) { } diff --git a/Display.h b/Display.h index fae929b2..109b0ca2 100644 --- a/Display.h +++ b/Display.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2021,2023 by Jonathan Naylor G4KLX * * 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 @@ -53,7 +53,7 @@ class CDisplay void writeDMR(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type); void writeDMRRSSI(unsigned int slotNo, unsigned char rssi); void writeDMRBER(unsigned int slotNo, float ber); - void writeDMRTA(unsigned int slotNo, unsigned char* talkerAlias, const char* type); + void writeDMRTA(unsigned int slotNo, const unsigned char* talkerAlias, const char* type); void clearDMR(unsigned int slotNo); void writeFusion(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); @@ -103,7 +103,7 @@ class CDisplay virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type) = 0; virtual int writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type); virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi); - virtual void writeDMRTAInt(unsigned int slotNo, unsigned char* talkerAlias, const char* type); + virtual void writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type); virtual void writeDMRBERInt(unsigned int slotNo, float ber); virtual void clearDMRInt(unsigned int slotNo) = 0; diff --git a/Nextion.cpp b/Nextion.cpp index 4875fe5d..6df9a6d3 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2023 by Jonathan Naylor G4KLX * * 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 @@ -477,7 +477,7 @@ void CNextion::writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi) } } -void CNextion::writeDMRTAInt(unsigned int slotNo, unsigned char* talkerAlias, const char* type) +void CNextion::writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type) { if (!(m_screenLayout & LAYOUT_TA_ENABLE)) return; diff --git a/Nextion.h b/Nextion.h index 713fc905..d4405263 100644 --- a/Nextion.h +++ b/Nextion.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2023 by Jonathan Naylor G4KLX * * 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 @@ -50,8 +50,7 @@ class CNextion : public CDisplay virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi); - virtual void writeDMRTAInt(unsigned int slotNo, unsigned char* talkerAlias, const char* type); - + virtual void writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type); virtual void writeDMRBERInt(unsigned int slotNo, float ber); virtual void clearDMRInt(unsigned int slotNo);