diff --git a/udphandler.cpp b/udphandler.cpp index f19e6fd..3280530 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1135,7 +1135,7 @@ void udpAudio::dataReceived() void udpBase::init(quint16 lport) { - timeStarted.start(); + //timeStarted.start(); udp = new QUdpSocket(this); udp->bind(lport); // Bind to random port. localPort = udp->localPort(); @@ -1517,7 +1517,8 @@ void udpBase::sendPing() p.sentid = myId; p.rcvdid = remoteId; p.seq = pingSendSeq; - p.time = timeStarted.msecsSinceStartOfDay(); + QTime now=QTime::currentTime(); + p.time = (quint32)now.msecsSinceStartOfDay(); lastPingSentTime = QDateTime::currentDateTime(); udpMutex.lock(); udp->writeDatagram(QByteArray::fromRawData((const char*)p.packet, sizeof(p)), radioIP, port); diff --git a/udphandler.h b/udphandler.h index 3538337..3e51ed9 100644 --- a/udphandler.h +++ b/udphandler.h @@ -80,7 +80,7 @@ public: void printHex(const QByteArray& pdata, bool printVert, bool printHoriz); - QTime timeStarted; + //QTime timeStarted; QUdpSocket* udp=Q_NULLPTR; uint32_t myId = 0; diff --git a/udpserver.cpp b/udpserver.cpp index 3b30467..76b6be3 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -39,7 +39,7 @@ void udpServer::init() ; } srand(time(NULL)); // Generate random - timeStarted.start(); + //timeStarted.start(); // Convoluted way to find the external IP address, there must be a better way???? QString localhostname = QHostInfo::localHostName(); QList hostList = QHostInfo::fromName(localhostname).addresses(); @@ -357,7 +357,7 @@ void udpServer::controlReceived() audioSetup setup; setup.resampleQuality = config->resampleQuality; for (RIGCONFIG* radio : config->rigs) { - if ((!memcmp(radio->guid, current->guid, GUIDLEN) || config->rigs.size()==1) && radio->txaudio == Q_NULLPTR ) + if ((!memcmp(radio->guid, current->guid, GUIDLEN) || config->rigs.size()==1) && radio->txaudio == Q_NULLPTR && !config->lan) { radio->txAudioSetup.codec = current->txCodec; radio->txAudioSetup.format.setSampleRate(current->txSampleRate); @@ -392,7 +392,7 @@ void udpServer::controlReceived() connect(this, SIGNAL(haveAudioData(audioPacket)), radio->txaudio, SLOT(incomingAudio(audioPacket))); } - if ((!memcmp(radio->guid, current->guid, GUIDLEN) || config->rigs.size() == 1) && radio->rxaudio == Q_NULLPTR) + if ((!memcmp(radio->guid, current->guid, GUIDLEN) || config->rigs.size() == 1) && radio->rxaudio == Q_NULLPTR && !config->lan) { #if !defined(PORTAUDIO) && !defined(RTAUDIO) qInfo(logUdpServer()) << "Radio" << radio->rigName << "audio input(RX) :" << radio->rxAudioSetup.port.deviceName(); @@ -1072,7 +1072,8 @@ void udpServer::sendPing(QList* l, CLIENT* c, quint16 seq, bool reply) pingTime = c->rxPingTime; } else { - pingTime = (quint32)timeStarted.msecsSinceStartOfDay(); + QTime now=QTime::currentTime(); + pingTime = (quint32)now.msecsSinceStartOfDay(); seq = c->pingSeq; // Don't increment pingseq until we receive a reply. } diff --git a/udpserver.h b/udpserver.h index b7ca33d..9fd4f4a 100644 --- a/udpserver.h +++ b/udpserver.h @@ -217,7 +217,7 @@ private: QList civClients = QList(); QList audioClients = QList(); - QTime timeStarted; + //QTime timeStarted; audioSetup outAudio; @@ -235,4 +235,4 @@ private: }; -#endif // UDPSERVER_H \ No newline at end of file +#endif // UDPSERVER_H diff --git a/wfmain.cpp b/wfmain.cpp index 32b9e31..d2f4468 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -79,12 +79,7 @@ wfmain::wfmain(const QString serialPortCL, const QString hostCL, const QString s qDebug(logSystem()) << "Running rigConnections()"; rigConnections(); -/* if (serverConfig.enabled && udp != Q_NULLPTR) { - // Server - connect(rig, SIGNAL(haveAudioData(audioPacket)), udp, SLOT(receiveAudioData(audioPacket))); - connect(rig, SIGNAL(haveDataForServer(QByteArray)), udp, SLOT(dataForServer(QByteArray))); - connect(udp, SIGNAL(haveDataFromServer(QByteArray)), rig, SLOT(dataFromServer(QByteArray))); - } */ + setServerToPrefs(); @@ -997,8 +992,7 @@ void wfmain::setServerToPrefs() if (serverConfig.enabled) { serverConfig.lan = prefs.enableLAN; - qInfo(logAudio()) << "Audio Input device " << serverConfig.rigs.first()->rxAudioSetup.name; - qInfo(logAudio()) << "Audio Output device " << serverConfig.rigs.first()->txAudioSetup.name; + udp = new udpServer(&serverConfig); serverThread = new QThread(this); @@ -1011,12 +1005,17 @@ void wfmain::setServerToPrefs() if (rig != Q_NULLPTR) { connect(rig, SIGNAL(haveAudioData(audioPacket)), udp, SLOT(receiveAudioData(audioPacket))); + // Need to add a signal/slot for audio from the client to rig. + //connect(udp, SIGNAL(haveAudioData(audioPacket)), rig, SLOT(receiveAudioData(audioPacket))); connect(rig, SIGNAL(haveDataForServer(QByteArray)), udp, SLOT(dataForServer(QByteArray))); connect(udp, SIGNAL(haveDataFromServer(QByteArray)), rig, SLOT(dataFromServer(QByteArray))); } - if (!prefs.enableLAN) { + if (serverConfig.lan) { connect(udp, SIGNAL(haveNetworkStatus(networkStatus)), this, SLOT(receiveStatusUpdate(networkStatus))); + } else { + qInfo(logAudio()) << "Audio Input device " << serverConfig.rigs.first()->rxAudioSetup.name; + qInfo(logAudio()) << "Audio Output device " << serverConfig.rigs.first()->txAudioSetup.name; } serverThread->start(); @@ -1435,15 +1434,13 @@ void wfmain::loadSettings() settings->beginGroup("LAN"); prefs.enableLAN = settings->value("EnableLAN", defPrefs.enableLAN).toBool(); - if (prefs.enableLAN) - { - ui->baudRateCombo->setEnabled(false); - ui->serialDeviceListCombo->setEnabled(false); - } - else { - ui->baudRateCombo->setEnabled(true); - ui->serialDeviceListCombo->setEnabled(true); - } + + // If LAN is enabled, server gets its audio straight from the LAN + ui->serverRXAudioInputCombo->setEnabled(!prefs.enableLAN); + ui->serverTXAudioOutputCombo->setEnabled(!prefs.enableLAN); + + ui->baudRateCombo->setEnabled(!prefs.enableLAN); + ui->serialDeviceListCombo->setEnabled(!prefs.enableLAN); ui->lanEnableBtn->setChecked(prefs.enableLAN); ui->connectBtn->setEnabled(true); @@ -4572,6 +4569,8 @@ void wfmain::on_serialEnableBtn_clicked(bool checked) ui->audioInputCombo->setEnabled(!checked); ui->baudRateCombo->setEnabled(checked); ui->serialDeviceListCombo->setEnabled(checked); + ui->serverRXAudioInputCombo->setEnabled(checked); + ui->serverTXAudioOutputCombo->setEnabled(checked); } void wfmain::on_lanEnableBtn_clicked(bool checked) @@ -4593,6 +4592,8 @@ void wfmain::on_lanEnableBtn_clicked(bool checked) ui->audioInputCombo->setEnabled(checked); ui->baudRateCombo->setEnabled(!checked); ui->serialDeviceListCombo->setEnabled(!checked); + ui->serverRXAudioInputCombo->setEnabled(!checked); + ui->serverTXAudioOutputCombo->setEnabled(!checked); if(checked) { showStatusBarText("After filling in values, press Save Settings.");