More bug fixes and code cleanups

pull/4/head
Doug McLain 2 years ago
parent a24658ba30
commit a612323d23

@ -329,10 +329,12 @@ void DroidStar::process_connect()
emit update_log("Connecting to " + m_host + ":" + QString::number(m_port) + "..."); 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_mode = Mode::create_mode(m_protocol);
m_modethread = new QThread; m_modethread = new QThread;
m_mode->moveToThread(m_modethread); 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_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); 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'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "REF"){ if(line.at(0) == "REF"){
@ -743,7 +745,7 @@ void DroidStar::process_dcs_hosts()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "DCS"){ if(line.at(0) == "DCS"){
@ -784,7 +786,7 @@ void DroidStar::process_xrf_hosts()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "XRF"){ if(line.at(0) == "XRF"){
@ -825,7 +827,7 @@ void DroidStar::process_ysf_hosts()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "YSF"){ if(line.at(0) == "YSF"){
@ -869,7 +871,7 @@ void DroidStar::process_fcs_rooms()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "FCS"){ if(line.at(0) == "FCS"){
@ -915,7 +917,7 @@ void DroidStar::process_dmr_hosts()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "DMR"){ if(line.at(0) == "DMR"){
@ -956,7 +958,7 @@ void DroidStar::process_p25_hosts()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "P25"){ if(line.at(0) == "P25"){
@ -997,7 +999,7 @@ void DroidStar::process_nxdn_hosts()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "NXDN"){ if(line.at(0) == "NXDN"){
@ -1040,7 +1042,7 @@ void DroidStar::process_m17_hosts()
} }
m_customhosts = m_localhosts.split('\n'); m_customhosts = m_localhosts.split('\n');
for (const auto& i : m_customhosts){ for (const auto& i : qAsConst(m_customhosts)){
QStringList line = i.simplified().split(' '); QStringList line = i.simplified().split(' ');
if(line.at(0) == "M17"){ 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_urcall.isEmpty()) set_urcall("CQCQCQ");
if(m_rptr1.isEmpty()) set_rptr1(m_callsign + " " + m_module); 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)); 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); 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"){ else if (m_protocol == "YSF" || m_protocol == "FCS"){
m_data1 = info.gw; m_data1 = info.gw;
m_data2 =info.src; m_data2 = info.src;
m_data3 = info.dst; m_data3 = info.dst;
if(info.type == 0){ if(info.type == 0){

@ -19,7 +19,6 @@
#define DROIDSTAR_H #define DROIDSTAR_H
#include <QObject> #include <QObject>
#include <QTimer>
#include "mode.h" #include "mode.h"
class DroidStar : public QObject class DroidStar : public QObject

@ -91,7 +91,6 @@ M17::M17() :
m_txtimerint = 30; // Qt timers on windows seem to be slower than desired value m_txtimerint = 30; // Qt timers on windows seem to be slower than desired value
#else #else
m_txtimerint = 36;
m_txcan = 0; m_txcan = 0;
#endif #endif
m_attenuation = 1; m_attenuation = 1;
@ -725,6 +724,7 @@ void M17::toggle_tx(bool tx)
void M17::start_tx() void M17::start_tx()
{ {
m_txtimerint = 38;
set_mode(m_txrate); set_mode(m_txrate);
Mode::start_tx(); Mode::start_tx();
} }

@ -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_dmrid = dmrid;
m_nxdnid = nxdnid;
m_module = module; m_module = module;
m_refname = refname; m_refname = refname;
m_ipv6 = ipv6; m_ipv6 = ipv6;

@ -42,7 +42,7 @@ public:
Mode(); Mode();
~Mode(); ~Mode();
static Mode* create_mode(QString); 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) void set_modem_flags(bool rxInvert, bool txInvert, bool pttInvert, bool useCOSAsLockout, bool duplex)
{ {
m_rxInvert = rxInvert; m_rxInvert = rxInvert;
@ -161,6 +161,7 @@ protected:
QHostAddress m_address; QHostAddress m_address;
char m_module; char m_module;
uint32_t m_dmrid; uint32_t m_dmrid;
uint16_t m_nxdnid;
QString m_refname; QString m_refname;
bool m_tx; bool m_tx;
uint16_t m_txcnt; uint16_t m_txcnt;

@ -210,39 +210,22 @@ void NXDN::interleave(uint8_t *ambe)
void NXDN::hostname_lookup(QHostInfo i) void NXDN::hostname_lookup(QHostInfo i)
{ {
if (!i.addresses().isEmpty()) { 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_address = i.addresses().first();
m_udp = new QUdpSocket(this); m_udp = new QUdpSocket(this);
connect(m_udp, SIGNAL(readyRead()), this, SLOT(process_udp())); connect(m_udp, SIGNAL(readyRead()), this, SLOT(process_udp()));
m_udp->writeDatagram(out, m_address, m_modeinfo.port); m_modeinfo.gwid = m_refname.toUInt();
#ifdef DEBUG send_ping();
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
} }
} }
void NXDN::send_ping() void NXDN::send_ping(bool disconnect)
{ {
QByteArray out; QByteArray out;
out.append('N'); out.append('N');
out.append('X'); out.append('X');
out.append('D'); out.append('D');
out.append('N'); out.append('N');
out.append('P'); disconnect ? out.append('U') : out.append('P');
out.append(m_modeinfo.callsign.toUtf8()); out.append(m_modeinfo.callsign.toUtf8());
out.append(10 - m_modeinfo.callsign.size(), ' '); out.append(10 - m_modeinfo.callsign.size(), ' ');
out.append((m_modeinfo.gwid >> 8) & 0xff); out.append((m_modeinfo.gwid >> 8) & 0xff);
@ -258,29 +241,6 @@ void NXDN::send_ping()
#endif #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() void NXDN::transmit()
{ {
uint8_t ambe[7]; uint8_t ambe[7];

@ -34,13 +34,12 @@ private slots:
void process_udp(); void process_udp();
void process_rx_data(); void process_rx_data();
void get_ambe(); void get_ambe();
void send_ping(); void send_ping(bool disconnect = false);
void send_disconnect(); void send_disconnect() {send_ping(true);}
void transmit(); void transmit();
void hostname_lookup(QHostInfo i); void hostname_lookup(QHostInfo i);
void send_frame(); void send_frame();
private: private:
uint16_t m_nxdnid;
bool m_eot; bool m_eot;
uint8_t m_nxdnframe[55]; uint8_t m_nxdnframe[55];
uint8_t m_lich; uint8_t m_lich;

@ -31,7 +31,6 @@ private:
int m_p25cnt; int m_p25cnt;
uint8_t imbe[11U]; uint8_t imbe[11U];
int m_dstid; int m_dstid;
uint32_t m_dmrid;
uint32_t m_txdstid; uint32_t m_txdstid;
private slots: private slots:
void process_udp(); void process_udp();

@ -198,6 +198,11 @@ void YSF::process_udp()
if((buf.size() == 155) && (::memcmp(buf.data(), "YSFD", 4U) == 0)){ if((buf.size() == 155) && (::memcmp(buf.data(), "YSFD", 4U) == 0)){
memcpy(ysftag, buf.data() + 4, 10);ysftag[10] = '\0'; memcpy(ysftag, buf.data() + 4, 10);ysftag[10] = '\0';
m_modeinfo.gw = QString(ysftag); 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; p_data = (uint8_t *)buf.data() + 35;
if(m_modem){ if(m_modem){
m_rxmodemq.append(MMDVM_FRAME_START); m_rxmodemq.append(MMDVM_FRAME_START);
@ -245,6 +250,7 @@ void YSF::process_udp()
m_audio->start_playback(); m_audio->start_playback();
m_rxtimer->start(m_rxtimerint); m_rxtimer->start(m_rxtimerint);
} }
decode_header(p_data);
qDebug() << "New YSF stream from gw" << m_modeinfo.gw; qDebug() << "New YSF stream from gw" << m_modeinfo.gw;
} }
else if(m_fi == YSF_FI_TERMINATOR){ else if(m_fi == YSF_FI_TERMINATOR){
@ -380,6 +386,60 @@ void YSF::send_disconnect()
#endif #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) void YSF::decode_vw(uint8_t* data)
{ {
uint8_t vch[18U]; uint8_t vch[18U];

@ -72,6 +72,7 @@ private slots:
void rate_changed(int r) { m_txfullrate = r;} void rate_changed(int r) { m_txfullrate = r;}
void process_modem_data(QByteArray); void process_modem_data(QByteArray);
private: private:
void decode_header(uint8_t* data);
void decode_dn(uint8_t* data); void decode_dn(uint8_t* data);
void decode_vw(uint8_t* data); void decode_vw(uint8_t* data);
void encode_header(bool eot = 0); void encode_header(bool eot = 0);

Loading…
Cancel
Save