diff --git a/cmake/Modules/FindLibNANOMSG.cmake b/cmake/Modules/FindLibNANOMSG.cmake new file mode 100644 index 000000000..63b8504e3 --- /dev/null +++ b/cmake/Modules/FindLibNANOMSG.cmake @@ -0,0 +1,28 @@ +if(NOT LIBNANOMSG_FOUND) + + pkg_check_modules (LIBNANOMSG_PKG libnanomsg) + find_path(LIBNANOMSG_INCLUDE_DIR NAMES nanomsg/nn.h + PATHS + ${LIBNANOMSG_PKG_INCLUDE_DIRS} + /usr/include + /usr/local/include + ) + + find_library(LIBNANOMSG_LIBRARIES NAMES nanomsg + PATHS + ${LIBNANOMSG_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + + if(LIBNANOMSG_INCLUDE_DIR AND LIBNANOMSG_LIBRARIES) + set(LIBNANOMSG_FOUND TRUE CACHE INTERNAL "libnanomsg found") + message(STATUS "Found libnanomsg: ${LIBNANOMSG_INCLUDE_DIR}, ${LIBNANOMSG_LIBRARIES}") + else(LIBNANOMSG_INCLUDE_DIR AND LIBNANOMSG_LIBRARIES) + set(LIBNANOMSG_FOUND FALSE CACHE INTERNAL "libnanomsg found") + message(STATUS "libnanomsg not found.") + endif(LIBNANOMSG_INCLUDE_DIR AND LIBNANOMSG_LIBRARIES) + + mark_as_advanced(LIBNANOMSG_INCLUDE_DIR LIBNANOMSG_LIBRARIES) + +endif(NOT LIBNANOMSG_FOUND) diff --git a/plugins/samplesource/CMakeLists.txt b/plugins/samplesource/CMakeLists.txt index 5e1ec48eb..d87169ab4 100644 --- a/plugins/samplesource/CMakeLists.txt +++ b/plugins/samplesource/CMakeLists.txt @@ -42,5 +42,11 @@ if(LIBUSB_FOUND AND LIBHACKRF_FOUND) add_subdirectory(hackrf) endif(LIBUSB_FOUND AND LIBHACKRF_FOUND) +#find_package(LibNANOMSG) +#if(LIBNANOMSG_FOUND) +# add_subdirectory(sdrdaemon) +#endif(LIBNANOMSG_FOUND) + add_subdirectory(filesource) add_subdirectory(sdrdaemon) + diff --git a/plugins/samplesource/sdrdaemon/CMakeLists.txt b/plugins/samplesource/sdrdaemon/CMakeLists.txt index f69e8bf90..a347ed988 100644 --- a/plugins/samplesource/sdrdaemon/CMakeLists.txt +++ b/plugins/samplesource/sdrdaemon/CMakeLists.txt @@ -1,6 +1,7 @@ project(sdrdaemon) find_package(LZ4) +find_package(LibNANOMSG) set(sdrdaemon_SOURCES sdrdaemonbuffer.cpp @@ -45,11 +46,13 @@ add_library(inputsdrdaemon SHARED target_include_directories(inputsdrdaemon PUBLIC ${LZ4_INCLUDE_DIRS} + ${LIBNANOMSG_INCLUDE_DIR} ) target_link_libraries(inputsdrdaemon ${QT_LIBRARIES} ${LZ4_LIBRARIES} + ${LIBNANOMSG_LIBRARIES} sdrbase ) diff --git a/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp b/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp index 391d77434..2adb62c18 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp +++ b/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp @@ -67,6 +67,12 @@ SDRdaemonGui::SDRdaemonGui(PluginAPI* pluginAPI, QWidget* parent) : m_iqCorrection(false), m_autoFollowRate(false) { + m_sender = nn_socket(AF_SP, NN_PAIR); + assert(m_sender != -1); + int millis = 500; + int rc = nn_setsockopt (m_sender, NN_SOL_SOCKET, NN_SNDTIMEO, &millis, sizeof (millis)); + assert (rc == 0); + m_startingTimeStamp.tv_sec = 0; m_startingTimeStamp.tv_usec = 0; ui->setupUi(this); @@ -383,6 +389,7 @@ void SDRdaemonGui::on_applyButton_clicked(bool checked) void SDRdaemonGui::on_sendButton_clicked(bool checked) { sendConfiguration(); + ui->specificParms->setCursorPosition(0); ui->sendButton->setEnabled(false); } @@ -394,6 +401,16 @@ void SDRdaemonGui::sendConfiguration() if (remoteAddress != m_remoteAddress) { m_remoteAddress = remoteAddress; + std::ostringstream os; + os << "tcp://" << m_remoteAddress.toStdString() << ":" << m_controlPort; + std::string addrstrng = os.str(); + int rc = nn_connect(m_sender, addrstrng.c_str()); + + if (rc < 0) { + QMessageBox::information(this, tr("Message"), tr("Cannot connect to remote control port")); + } else { + qDebug() << "SDRdaemonGui::sendConfiguration: connexion to " << addrstrng.c_str() << " successful"; + } } std::ostringstream os; @@ -422,9 +439,19 @@ void SDRdaemonGui::sendConfiguration() os << "," << ui->specificParms->text().toStdString(); } - qDebug() << "SDRdaemonGui::sendConfiguration:" - << " remoteAddress: " << remoteAddress - << " message: " << os.str().c_str(); + int config_size = os.str().size(); + int rc = nn_send(m_sender, (void *) os.str().c_str(), config_size, 0); + + if (rc != config_size) + { + QMessageBox::information(this, tr("Message"), tr("Cannot send message to remote control port")); + } + else + { + qDebug() << "SDRdaemonGui::sendConfiguration:" + << " remoteAddress: " << remoteAddress + << " message: " << os.str().c_str(); + } } void SDRdaemonGui::on_address_textEdited(const QString& arg1) @@ -546,16 +573,16 @@ void SDRdaemonGui::updateWithStreamData() QString s2 = QString::number(skewPerCent, 'f', 2); ui->skewRateText->setText(tr("%1").arg(s2)); updateWithStreamTime(); +} +void SDRdaemonGui::updateWithStreamTime() +{ if (m_initSendConfiguration) { sendConfiguration(); m_initSendConfiguration = false; } -} -void SDRdaemonGui::updateWithStreamTime() -{ quint64 startingTimeStampMsec = ((quint64) m_startingTimeStamp.tv_sec * 1000LL) + ((quint64) m_startingTimeStamp.tv_usec / 1000LL); QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec); QString s_date = dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); diff --git a/plugins/samplesource/sdrdaemon/sdrdaemongui.h b/plugins/samplesource/sdrdaemon/sdrdaemongui.h index b626e02aa..8a45e0ca6 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemongui.h +++ b/plugins/samplesource/sdrdaemon/sdrdaemongui.h @@ -78,6 +78,7 @@ private: bool m_addressEdited; bool m_dataPortEdited; bool m_initSendConfiguration; + int m_sender; bool m_dcBlock; bool m_iqCorrection;