From a612323d234239f13e1c3c99254cd66885fce6b0 Mon Sep 17 00:00:00 2001 From: Doug McLain Date: Tue, 10 Jan 2023 16:07:29 -0500 Subject: [PATCH] More bug fixes and code cleanups --- droidstar.cpp | 31 ++++++++++++++++---------- droidstar.h | 1 - m17.cpp | 2 +- mode.cpp | 3 ++- mode.h | 3 ++- nxdn.cpp | 48 ++++------------------------------------- nxdn.h | 5 ++--- p25.h | 1 - ysf.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ ysf.h | 1 + 10 files changed, 92 insertions(+), 63 deletions(-) diff --git a/droidstar.cpp b/droidstar.cpp index d750c71..d621668 100644 --- a/droidstar.cpp +++ b/droidstar.cpp @@ -329,10 +329,12 @@ void DroidStar::process_connect() emit update_log("Connecting to " + m_host + ":" + QString::number(m_port) + "..."); + uint16_t nxdnid = m_nxdnids.key(m_callsign); + m_mode = Mode::create_mode(m_protocol); m_modethread = new QThread; m_mode->moveToThread(m_modethread); - m_mode->init(m_callsign, m_dmrid, m_module, m_refname, m_host, m_port, m_ipv6, vocoder, modem, m_capture, m_playback); + m_mode->init(m_callsign, m_dmrid, nxdnid, m_module, m_refname, m_host, m_port, m_ipv6, vocoder, modem, m_capture, m_playback); m_mode->set_modem_flags(rxInvert, txInvert, pttInvert, useCOSAsLockout, duplex); m_mode->set_modem_params(m_modemBaud.toUInt(), rxfreq, txfreq, m_modemTxDelay.toInt(), m_modemRxLevel.toFloat(), m_modemRFLevel.toFloat(), ysfTXHang, m_modemCWIdTxLevel.toFloat(), m_modemDstarTxLevel.toFloat(), m_modemDMRTxLevel.toFloat(), m_modemYSFTxLevel.toFloat(), m_modemP25TxLevel.toFloat(), m_modemNXDNTxLevel.toFloat(), pocsagTXLevel, m17TXLevel); @@ -702,7 +704,7 @@ void DroidStar::process_ref_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "REF"){ @@ -743,7 +745,7 @@ void DroidStar::process_dcs_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "DCS"){ @@ -784,7 +786,7 @@ void DroidStar::process_xrf_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "XRF"){ @@ -825,7 +827,7 @@ void DroidStar::process_ysf_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "YSF"){ @@ -869,7 +871,7 @@ void DroidStar::process_fcs_rooms() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "FCS"){ @@ -915,7 +917,7 @@ void DroidStar::process_dmr_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "DMR"){ @@ -956,7 +958,7 @@ void DroidStar::process_p25_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "P25"){ @@ -997,7 +999,7 @@ void DroidStar::process_nxdn_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "NXDN"){ @@ -1040,7 +1042,7 @@ void DroidStar::process_m17_hosts() } m_customhosts = m_localhosts.split('\n'); - for (const auto& i : m_customhosts){ + for (const auto& i : qAsConst(m_customhosts)){ QStringList line = i.simplified().split(' '); if(line.at(0) == "M17"){ @@ -1259,6 +1261,13 @@ void DroidStar::update_data(Mode::MODEINFO info) if(m_urcall.isEmpty()) set_urcall("CQCQCQ"); if(m_rptr1.isEmpty()) set_rptr1(m_callsign + " " + m_module); emit update_log("Connected to " + m_protocol + " " + m_refname + " " + m_host + ":" + QString::number(m_port)); + + if(info.sw_vocoder_loaded){ + emit update_log("Vocoder plugin loaded"); + } + else{ + emit update_log("Vocoder plugin not loaded"); + } } m_netstatustxt = "Connected ping cnt: " + QString::number(info.count); @@ -1297,7 +1306,7 @@ void DroidStar::update_data(Mode::MODEINFO info) } else if (m_protocol == "YSF" || m_protocol == "FCS"){ m_data1 = info.gw; - m_data2 =info.src; + m_data2 = info.src; m_data3 = info.dst; if(info.type == 0){ diff --git a/droidstar.h b/droidstar.h index 3e408b5..acb294b 100644 --- a/droidstar.h +++ b/droidstar.h @@ -19,7 +19,6 @@ #define DROIDSTAR_H #include -#include #include "mode.h" class DroidStar : public QObject diff --git a/m17.cpp b/m17.cpp index ed50f2e..cb0a0fd 100755 --- a/m17.cpp +++ b/m17.cpp @@ -91,7 +91,6 @@ M17::M17() : m_txtimerint = 30; // Qt timers on windows seem to be slower than desired value #else - m_txtimerint = 36; m_txcan = 0; #endif m_attenuation = 1; @@ -725,6 +724,7 @@ void M17::toggle_tx(bool tx) void M17::start_tx() { + m_txtimerint = 38; set_mode(m_txrate); Mode::start_tx(); } diff --git a/mode.cpp b/mode.cpp index 05a30c7..a54cf77 100644 --- a/mode.cpp +++ b/mode.cpp @@ -82,9 +82,10 @@ Mode::~Mode() { } -void Mode::init(QString callsign, uint32_t dmrid, char module, QString refname, QString host, int port, bool ipv6, QString vocoder, QString modem, QString audioin, QString audioout) +void Mode::init(QString callsign, uint32_t dmrid, uint16_t nxdnid, char module, QString refname, QString host, int port, bool ipv6, QString vocoder, QString modem, QString audioin, QString audioout) { m_dmrid = dmrid; + m_nxdnid = nxdnid; m_module = module; m_refname = refname; m_ipv6 = ipv6; diff --git a/mode.h b/mode.h index 04e472f..177a033 100644 --- a/mode.h +++ b/mode.h @@ -42,7 +42,7 @@ public: Mode(); ~Mode(); static Mode* create_mode(QString); - void init(QString callsign, uint32_t dmrid, char module, QString refname, QString host, int port, bool ipv6, QString vocoder, QString modem, QString audioin, QString audioout); + void init(QString callsign, uint32_t dmrid, uint16_t nxdnid, char module, QString refname, QString host, int port, bool ipv6, QString vocoder, QString modem, QString audioin, QString audioout); void set_modem_flags(bool rxInvert, bool txInvert, bool pttInvert, bool useCOSAsLockout, bool duplex) { m_rxInvert = rxInvert; @@ -161,6 +161,7 @@ protected: QHostAddress m_address; char m_module; uint32_t m_dmrid; + uint16_t m_nxdnid; QString m_refname; bool m_tx; uint16_t m_txcnt; diff --git a/nxdn.cpp b/nxdn.cpp index 41f96d2..20e2188 100755 --- a/nxdn.cpp +++ b/nxdn.cpp @@ -210,39 +210,22 @@ void NXDN::interleave(uint8_t *ambe) void NXDN::hostname_lookup(QHostInfo i) { if (!i.addresses().isEmpty()) { - QByteArray out; - out.append('N'); - out.append('X'); - out.append('D'); - out.append('N'); - out.append('P'); - out.append(m_modeinfo.callsign.toUtf8()); - out.append(10 - m_modeinfo.callsign.size(), ' '); - out.append((m_modeinfo.gwid >> 8) & 0xff); - out.append((m_modeinfo.gwid >> 0) & 0xff); m_address = i.addresses().first(); m_udp = new QUdpSocket(this); connect(m_udp, SIGNAL(readyRead()), this, SLOT(process_udp())); - m_udp->writeDatagram(out, m_address, m_modeinfo.port); -#ifdef DEBUG - fprintf(stderr, "CONN: "); - for(int i = 0; i < out.size(); ++i){ - fprintf(stderr, "%02x ", (uint8_t)out.data()[i]); - } - fprintf(stderr, "\n"); - fflush(stderr); -#endif + m_modeinfo.gwid = m_refname.toUInt(); + send_ping(); } } -void NXDN::send_ping() +void NXDN::send_ping(bool disconnect) { QByteArray out; out.append('N'); out.append('X'); out.append('D'); out.append('N'); - out.append('P'); + disconnect ? out.append('U') : out.append('P'); out.append(m_modeinfo.callsign.toUtf8()); out.append(10 - m_modeinfo.callsign.size(), ' '); out.append((m_modeinfo.gwid >> 8) & 0xff); @@ -258,29 +241,6 @@ void NXDN::send_ping() #endif } -void NXDN::send_disconnect() -{ - QByteArray out; - out.append('N'); - out.append('X'); - out.append('D'); - out.append('N'); - out.append('U'); - out.append(m_modeinfo.callsign.toUtf8()); - out.append(10 - m_modeinfo.callsign.size(), ' '); - out.append((m_modeinfo.gwid >> 8) & 0xff); - out.append((m_modeinfo.gwid >> 0) & 0xff); - m_udp->writeDatagram(out, m_address, m_modeinfo.port); -#ifdef DEBUG - fprintf(stderr, "SEND: "); - for(int i = 0; i < out.size(); ++i){ - fprintf(stderr, "%02x ", (uint8_t)out.data()[i]); - } - fprintf(stderr, "\n"); - fflush(stderr); -#endif -} - void NXDN::transmit() { uint8_t ambe[7]; diff --git a/nxdn.h b/nxdn.h index a146a2b..59a1416 100644 --- a/nxdn.h +++ b/nxdn.h @@ -34,13 +34,12 @@ private slots: void process_udp(); void process_rx_data(); void get_ambe(); - void send_ping(); - void send_disconnect(); + void send_ping(bool disconnect = false); + void send_disconnect() {send_ping(true);} void transmit(); void hostname_lookup(QHostInfo i); void send_frame(); private: - uint16_t m_nxdnid; bool m_eot; uint8_t m_nxdnframe[55]; uint8_t m_lich; diff --git a/p25.h b/p25.h index 02b72ee..18d1522 100644 --- a/p25.h +++ b/p25.h @@ -31,7 +31,6 @@ private: int m_p25cnt; uint8_t imbe[11U]; int m_dstid; - uint32_t m_dmrid; uint32_t m_txdstid; private slots: void process_udp(); diff --git a/ysf.cpp b/ysf.cpp index 5690db6..67be252 100755 --- a/ysf.cpp +++ b/ysf.cpp @@ -198,6 +198,11 @@ void YSF::process_udp() if((buf.size() == 155) && (::memcmp(buf.data(), "YSFD", 4U) == 0)){ memcpy(ysftag, buf.data() + 4, 10);ysftag[10] = '\0'; m_modeinfo.gw = QString(ysftag); + //memcpy(ysftag, buf.data() + 14, 10);ysftag[10] = '\0'; + //m_modeinfo.src = QString(ysftag); + //memcpy(ysftag, buf.data() + 24, 10);ysftag[10] = '\0'; + //m_modeinfo.dst = QString(ysftag); + p_data = (uint8_t *)buf.data() + 35; if(m_modem){ m_rxmodemq.append(MMDVM_FRAME_START); @@ -245,6 +250,7 @@ void YSF::process_udp() m_audio->start_playback(); m_rxtimer->start(m_rxtimerint); } + decode_header(p_data); qDebug() << "New YSF stream from gw" << m_modeinfo.gw; } else if(m_fi == YSF_FI_TERMINATOR){ @@ -380,6 +386,60 @@ void YSF::send_disconnect() #endif } +void YSF::decode_header(uint8_t* data) +{ + assert(data != NULL); + + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; + + uint8_t* source = NULL; + uint8_t* dest = NULL; + uint8_t dch[45U]; + + uint8_t* p1 = data; + uint8_t* p2 = dch; + for (uint32_t i = 0U; i < 5U; i++) { + ::memcpy(p2, p1, 9U); + p1 += 18U; p2 += 9U; + } + + CYSFConvolution conv; + conv.start(); + + for (uint32_t i = 0U; i < 180U; i++) { + uint32_t n = INTERLEAVE_TABLE_9_20[i]; + uint8_t s0 = READ_BIT(dch, n) ? 1U : 0U; + + n++; + uint8_t s1 = READ_BIT(dch, n) ? 1U : 0U; + + conv.decode(s0, s1); + } + + uint8_t output[23U]; + conv.chainback(output, 176U); + + bool valid = CCRC::checkCCITT162(output, 22U); + if (valid) { + for (uint32_t i = 0U; i < 20U; i++) + output[i] ^= WHITENING_DATA[i]; + + if (dest == NULL) { + dest = new uint8_t[YSF_CALLSIGN_LENGTH]; + ::memcpy(dest, output + 0U, YSF_CALLSIGN_LENGTH); + } + + if (source == NULL) { + source = new uint8_t[YSF_CALLSIGN_LENGTH]; + ::memcpy(source, output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH); + } + + m_modeinfo.src = QString::fromUtf8((const char *)source); + m_modeinfo.dst = QString::fromUtf8((const char *)dest); + m_modeinfo.gw2 = QString::fromUtf8((const char *)dest); + } +} + void YSF::decode_vw(uint8_t* data) { uint8_t vch[18U]; diff --git a/ysf.h b/ysf.h index ea71e50..01a7886 100644 --- a/ysf.h +++ b/ysf.h @@ -72,6 +72,7 @@ private slots: void rate_changed(int r) { m_txfullrate = r;} void process_modem_data(QByteArray); private: + void decode_header(uint8_t* data); void decode_dn(uint8_t* data); void decode_vw(uint8_t* data); void encode_header(bool eot = 0);