From d68bc247efe19bff1237ba6a0f33cebf7bacd16b Mon Sep 17 00:00:00 2001 From: Brecht Reynders Date: Tue, 9 Oct 2018 21:17:21 +0200 Subject: [PATCH 1/5] adding soapy sdr support --- drivers/soapysdr/soapyDriver.cpp | 391 +++++++++++++++++++++++++++++++ drivers/soapysdr/soapyDriver.h | 116 +++++++++ 2 files changed, 507 insertions(+) create mode 100644 drivers/soapysdr/soapyDriver.cpp create mode 100644 drivers/soapysdr/soapyDriver.h diff --git a/drivers/soapysdr/soapyDriver.cpp b/drivers/soapysdr/soapyDriver.cpp new file mode 100644 index 0000000..f91e926 --- /dev/null +++ b/drivers/soapysdr/soapyDriver.cpp @@ -0,0 +1,391 @@ +/* + * Copyright (C) 2018 by IMDEA Networks Institute + * + * This file is part of Electrosense. + * + * Electrosense is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Electrosense is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RTL-Spec. If not, see . + * + * Authors: + * Roberto Calvo-Palomino + * + */ + + +#include "soapyDriver.h" +#include +#include +#include +#include + +namespace electrosense { + + +soapyDriver::soapyDriver() { + + mQueueOut = new ReaderWriterQueue(100); + mConverterEnabled = false; +} + + +int soapyDriver::open(std::string device) { + // rtlsdr lib expects to have integer id for identifying the device + + int device_index = -1; + SoapySDR::KwargsList list = SoapySDR::Device::enumerate(device); + int n_rtlsdr = list.size(); + + if (n_rtlsdr==0) { + std::cerr << "* Error: no RTL-SDR USB devices found" << std::endl; + throw std::logic_error("Fatal Error"); + } + + // Choose which device to use + if ((n_rtlsdr==1)) { + device_index=0; + std::cout << "Device index " << device_index << ": [Device: " << list[device_index]["device"] << "] [Product: " << list[device_index]["driver"] << "] [URI: " << list[device_index]["uri"] << "]" << std::endl; + } + if ((device_index<0)||(device_index>=n_rtlsdr)) { + std::cerr << "Error: must specify which USB device to use with --device-index" << std::endl; + std::cerr << "Found the following USB devices:" << std::endl; + for (int t=0;tgetSamplingRate(); + + // Sampling frequency + mDevice->setSampleRate(SOAPY_SDR_RX,0,samplingRate); + mDevice->setBandwidth(SOAPY_SDR_RX,0,samplingRate); + //if (rtlsdr_set_sample_rate(mDevice,samplingRate)<0) { + // std::cerr << "ERROR: unable to set sampling rate to " << samplingRate << std::endl; + // throw std::logic_error("Fatal Error"); + //} + + int frequency = 24e6; // default value + mDevice->setFrequency(SOAPY_SDR_RX,0,frequency); +// if (rtlsdr_set_center_freq(mDevice,frequency)<0) +// { +// std::cerr << "ERROR: unable to set frequency to" << frequency << std::endl; +// throw std::logic_error("Fatal Error"); +// } + +// int* gains; +// int count = rtlsdr_get_tuner_gains(mDevice, NULL); +// if (count > 0 ) { +// gains = (int*) malloc(sizeof(int) * count); +// count = rtlsdr_get_tuner_gains(mDevice, gains); +// std::cout << "Gain available: "; +// for (int i=0; igetGain(); + mDevice->setGainMode(SOAPY_SDR_RX,0,false); + +// int r = rtlsdr_set_tuner_gain_mode(mDevice, 1); +// if(r < 0) { +// std::cerr << "ERROR: Failed to enable manual gain mode" << std::endl; +// throw std::logic_error("Fatal Error"); +// } +// r = rtlsdr_set_tuner_gain(mDevice, gain*10); + mDevice->setGain(SOAPY_SDR_RX,0,gain); +// if(r < 0) { +// std::cerr << "ERROR: Failed to set manual tuner gain" << std::endl; +// throw std::logic_error("Fatal Error"); +// } +// else { + gain = mDevice->getGain(SOAPY_SDR_RX,0); +// int g = rtlsdr_get_tuner_gain(mDevice); +// std::cout << "Gain set to " << g/10 << std::endl; +// } + +// // Reset the buffer +// if (rtlsdr_reset_buffer(mDevice)<0) { +// std::cerr << "Error: unable to reset RTLSDR buffer" << std::endl; +// } + + + std::cout << "[*] Initializing dongle with following configuration: " << std::endl; + std::cout << "\t Center Frequency: " << frequency << " Hz" << std::endl; + std::cout << "\t Sampling Rate: " << samplingRate << " samples/sec" << std::endl; + std::cout << "\t Gain: " << gain << " dB" << std::endl; + +// // Check if the converter is present + +// mConverterDriver.portPath = new char[CONVERTER_PATH.size() + 1]; +// std::copy(CONVERTER_PATH.begin(), CONVERTER_PATH.end(), mConverterDriver.portPath); +// mConverterDriver.portPath[CONVERTER_PATH.size()] = '\0'; + +// if(!converterInit(&mConverterDriver)){ +// std::cerr << "Warning: Failed to open the converter" << std::endl; +// //throw std::logic_error("Failed to open the converter"); +// } +// else { +// std::cout << "Converter has been detected properly" << std::endl; +// mConverterEnabled = true; +// } + +// delete[] mConverterDriver.portPath; + + + return 1; + +} + + +int soapyDriver::close () { + return 1; +} + + +void timespec_diff(struct timespec *start, struct timespec *stop, + struct timespec *result) +{ + if ((stop->tv_nsec - start->tv_nsec) < 0) { + result->tv_sec = stop->tv_sec - start->tv_sec - 1; + result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000; + } else { + result->tv_sec = stop->tv_sec - start->tv_sec; + result->tv_nsec = stop->tv_nsec - start->tv_nsec; + } + + return; +} + +typedef struct { + soapyDriver * dev; +} callback_package_t; + + +//static void capbuf_rtlsdr_callback( unsigned char * buf, uint32_t len, void * ctx) { +// +// struct sched_param param; +// param.sched_priority = 20; +// pthread_setschedparam (pthread_self ( ) ,SCHED_FIFO,¶m ) ; +// +// struct timespec current_time; +// clock_gettime(CLOCK_REALTIME, ¤t_time); +// +// +// // Getting parameters +// callback_package_t * cp_p=(callback_package_t *)ctx; +// callback_package_t & cp=*cp_p; +// std::vector> capbuf_raw_p = *cp.buf; +// uint64_t center_freq = cp.center_frequency; +// ReaderWriterQueue< SpectrumSegment*> *queue = cp.queue; +//// rtlsdr_dev_t * dev=cp.dev; +// +// // we set init time to current time only in the first execution +// if (cp.init_time.tv_sec == 0) +// cp.init_time = current_time; +// +// for (uint32_t t=0;t(buf[t] ,buf[t+1] )); +// } +// +// //std::cout << "[*] Sending segment " << current_time.tv_sec << "." << current_time.tv_nsec << std::endl; +// SpectrumSegment *segment = new SpectrumSegment(-1000, current_time, center_freq, +// ElectrosenseContext::getInstance()->getSamplingRate(), +// capbuf_raw_p); +// +// queue->enqueue(segment); +// capbuf_raw_p.clear(); +// +// *cp.samples_read = *cp.samples_read + len; +// +// struct timespec diff; +// timespec_diff(&cp.init_time, ¤t_time, &diff); +// +// if (cp.duration != 0 && (diff.tv_sec >= cp.duration)) +// { +//// rtlsdr_cancel_async(dev); +// pthread_exit(NULL); +// return; +// } +//} + +bool soapyDriver::isRunning () { + return mRunning; +} + +static void *aux_thread (void *arg) { + soapyDriver *sd_t = (soapyDriver *) arg; + sd_t->SyncSampling(); + pthread_exit(NULL); +} + + +void soapyDriver::run () { + mRunning = true; +// SyncSampling(); + pthread_t myth; + pthread_create ( &myth, NULL, aux_thread, (void *)this ); + pthread_join(myth,NULL); + mRunning = false; +} + +void soapyDriver::SyncSampling() { + + const int BULK_TRANSFER_MULTIPLE = 512; + struct timespec start_time; + clock_gettime(CLOCK_REALTIME, &start_time); + + std::cout << "soapyDriver::run" << std::endl; + + mSeqHopping = new SequentialHopping(); + uint64_t center_freq=0, previous_freq=0, fft_size=0, slen=0; + + std::complex *iq_buf = NULL; + + while (mRunning) + { + + // Introduce here the concept of segment per band (before jumping). + + center_freq = mSeqHopping->nextHop(); + + if (previous_freq != center_freq) + { + previous_freq = center_freq; + +// // Native RTL-SDR + +// int r = 0;//rtlsdr_set_center_freq(mDevice, center_freq); + mDevice->setFrequency(SOAPY_SDR_RX,0,center_freq); +// if (r != 0) { +// std::cerr << "Error: unable to set center frequency" << std::endl; +// mRunning = false; +// } + +// // Reset the buffer + if (mStream != 0) + { + mDevice->deactivateStream(mStream,0,0); + mDevice->closeStream(mStream); + } + mStream=mDevice->setupStream(SOAPY_SDR_RX,"CF32"); + mDevice->activateStream(mStream); +// if (false){//rtlsdr_reset_buffer(mDevice)<0) +// std::cerr << "Error: unable to reset RTLSDR buffer" << std::endl; +// mRunning = false; +// } + + + + } + + unsigned int current_fft_size = 1<getLog2FftSize(); + + if (fft_size != current_fft_size) + { + + fft_size = current_fft_size; + + slen = ((current_fft_size-ElectrosenseContext::getInstance()->getSoverlap()) * + ElectrosenseContext::getInstance()->getAvgFactor()+ElectrosenseContext::getInstance()->getSoverlap())*2; + + + if(slen % BULK_TRANSFER_MULTIPLE != 0) + slen = slen + (BULK_TRANSFER_MULTIPLE - (slen % BULK_TRANSFER_MULTIPLE)); + + iq_buf = (std::complex *) realloc(iq_buf,slen*sizeof(std::complex)); + + } + std::vector iqbufs(1); + iqbufs[0] = iq_buf; + + struct timespec current_time; + clock_gettime(CLOCK_REALTIME, ¤t_time); + + int flags; + long long timeNs; + int r = mDevice->readStream(mStream,iqbufs.data(),slen,flags,timeNs,100000); + if(r <= 0 ){ + fprintf(stderr, "WARNING: Synchronous read failed.\n"); + std::cout << r << " " << slen << std::endl; + mRunning = false; + } + + // for(int i = 0; i> iq_vector; + + for (unsigned int i=0; igetAvgFactor(); i++) { + + iq_vector.clear(); + + for (unsigned int j = 0; j < current_fft_size*2; j ++) { + + // Every segment overlaps getSoverlap() samples in time domain. + + iq_vector.push_back( + iq_buf[j+i*(current_fft_size-ElectrosenseContext::getInstance()->getSoverlap())*2]); + + } + + //TODO: Id should be the ethernet MAC + + SpectrumSegment *segment = new SpectrumSegment(-1000, current_time, center_freq, + ElectrosenseContext::getInstance()->getSamplingRate(), + iq_vector); + mQueueOut->enqueue(segment); + + } + struct timespec diff; + timespec_diff(&start_time, ¤t_time, &diff); + if (diff.tv_sec > ElectrosenseContext::getInstance()->getMonitorTime() && + ElectrosenseContext::getInstance()->getMonitorTime()!= 0) + { + std::cout << "sampling done" << std::endl; + mRunning = false; + } + } + + delete(mSeqHopping); + +} + + + + +int soapyDriver::stop() +{ + mRunning = false; + waitForThread(); + + // Workaround: RPi does not work properly the cancellation of the async task + if (ElectrosenseContext::getInstance()->getPipeline().compare("PSD") ==0 ) { +// rtlsdr_close(mDevice); + SoapySDR::Device::unmake(mDevice); + mDevice = NULL; + } + + return 1; +} +} diff --git a/drivers/soapysdr/soapyDriver.h b/drivers/soapysdr/soapyDriver.h new file mode 100644 index 0000000..90b91a1 --- /dev/null +++ b/drivers/soapysdr/soapyDriver.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2018 by IMDEA Networks Institute + * + * This file is part of Electrosense. + * + * Electrosense is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Electrosense is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RTL-Spec. If not, see . + * + * Authors: + * Roberto Calvo-Palomino + * + */ +#ifndef ES_SENSOR_RTLSDR_H +#define ES_SENSOR_RTLSDR_H + +#include +#include +#include +#include +#include + +#include "../Driver.h" +#include "../Component.h" +#include "../Communication.h" +#include "soapyDriver.h" +#include "../../context/ElectrosenseContext.h" +#include "../common/SequentialHopping.h" + +// Workaround issue #4 , complex.h breaks openssl's RSA library +// include RSA before any mention to complex.h +#include "../../types/SpectrumSegment.h" +#include + +extern "C" { +#include "converter/converter.h" +}; + +namespace electrosense { + + + + class soapyDriver: public Driver, public Component, public Communication { + + public: + + soapyDriver(); + + ~soapyDriver(); + + // Open the device + int open(std::string deviceId); + + // Close the device + int close(); + + // Stop + int stop(); + + // Running + bool isRunning (); + + void SyncSampling(); + + void AsyncSampling(); + + ReaderWriterQueue* getQueueIn() { return NULL; } + void setQueueIn (ReaderWriterQueue* QueueIn ) {}; + + ReaderWriterQueue* getQueueOut() { return mQueueOut; }; + void setQueueOut (ReaderWriterQueue* QueueOut) {}; + + std::string getNameId () { return std::string("soapyDriver"); }; + + + private: + + const std::string CONVERTER_PATH = "/dev/esenseconv"; + + // Run the driver in the thread + void run(); + + bool mRunning; + + int mDeviceId; + + SoapySDR::Device * mDevice; + SoapySDR::Stream * mStream; + + SequentialHopping* mSeqHopping; + + ReaderWriterQueue* mQueueOut; + + + converter mConverterDriver; + bool mConverterEnabled; + + + + + std::vector> m_capbuf_raw; + + }; + +} + +#endif //ES_SENSOR_RTLSDR_H From dff41240c79b47a1742ce9b4a872c7d249bf85fe Mon Sep 17 00:00:00 2001 From: Brecht Reynders Date: Tue, 9 Oct 2018 21:17:46 +0200 Subject: [PATCH 2/5] finding SoapySDR library --- CMakeLists.txt | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c250ca..1e76e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,14 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++11") # Add the local Find*.cmake scripts LIST (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) -FIND_PACKAGE( RTLSDR REQUIRED ) -INCLUDE_DIRECTORIES("${RTLSDR_INCLUDE_DIR}") - +FIND_PACKAGE(SoapySDR NO_MODULE) +if (SOAPYSDR_FOUND) + INCLUDE_DIRECTORIES("${LIBSOAPYSDR_INCLUDE_DIR}") +endif () +FIND_PACKAGE(avro NO_MODULE) +if (AVRO_FOUND) + INCLUDE_DIRECTORIES("${AVRO_INCLUDE_DIR}") +endif () # liquid, avro, ssl, crypto @@ -29,8 +34,7 @@ configure_file( version_config.h.in generated/version_config.h ) #ADD_SUBDIRECTORY(drivers/rtlsdr/converter/) -set(SOURCE_FILES main.cpp drivers/Driver.h drivers/rtlsdr/rtlsdrDriver.cpp drivers/rtlsdr/rtlsdrDriver.h - drivers/rtlsdr/converter/converter.c drivers/rtlsdr/converter/converter.h +set(SOURCE_FILES main.cpp drivers/Driver.h drivers/soapysdr/soapyDriver.cpp drivers/soapysdr/soapyDriver.h context/ElectrosenseContext.cpp context/ElectrosenseContext.h drivers/common/SequentialHopping.cpp drivers/common/SequentialHopping.h types/SpectrumSegment.cpp types/SpectrumSegment.h ProcessingBlocks/RemoveDC.cpp ProcessingBlocks/RemoveDC.h @@ -40,9 +44,12 @@ set(SOURCE_FILES main.cpp drivers/Driver.h drivers/rtlsdr/rtlsdrDriver.cpp drive misc/TLS.cpp misc/TLS.h misc/TCP.cpp misc/TCP.h MiscBlocks/IQSink.cpp MiscBlocks/IQSink.h) add_executable(es_sensor ${SOURCE_FILES}) +list(APPEND SoapySDR_LIBRARIES -pthread) +list(APPEND AVRO_LIBRARIES -pthread) + target_link_libraries(es_sensor - ${RTLSDR_LIBRARY} + SoapySDR pthread dl liquid @@ -52,7 +59,7 @@ target_link_libraries(es_sensor ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/es_sensor DESTINATION /usr/share/electrosense/bin/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/build/es_sensor DESTINATION /usr/share/electrosense/bin/) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/schemas/rtl-spec.avsc DESTINATION /usr/share/electrosense/schemas/) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/schemas/iq-spec.avsc DESTINATION /usr/share/electrosense/schemas/) From b1d942e1c2c23d0a5fa1859f1e927deaa6675c9c Mon Sep 17 00:00:00 2001 From: Brecht Reynders Date: Tue, 9 Oct 2018 21:18:32 +0200 Subject: [PATCH 3/5] making everything in build folder --- main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 9e001c6..6c83e74 100644 --- a/main.cpp +++ b/main.cpp @@ -35,10 +35,10 @@ #include "MiscBlocks/FileSink.h" #include "MiscBlocks/IQSink.h" -#include "generated/version_config.h" +#include "build/generated/version_config.h" #include "context/ElectrosenseContext.h" -#include "drivers/rtlsdr/rtlsdrDriver.h" +#include "drivers/soapysdr/soapyDriver.h" #include "drivers/Component.h" #include "ProcessingBlocks/RemoveDC.h" @@ -304,7 +304,7 @@ int main( int argc, char* argv[] ) { electrosense::Averaging *avgBlock; // RTL-SDR Driver - auto *rtlDriver = new electrosense::rtlsdrDriver(); + auto *rtlDriver = new electrosense::soapyDriver(); vComponents.push_back(rtlDriver); rtlDriver->open("0"); From 35d999daa7b6b9d721a3d6b8fecfb7bf196779dc Mon Sep 17 00:00:00 2001 From: Brecht Reynders Date: Tue, 9 Oct 2018 21:25:16 +0200 Subject: [PATCH 4/5] removing comments --- drivers/soapysdr/soapyDriver.cpp | 130 ------------------------------- drivers/soapysdr/soapyDriver.h | 2 - 2 files changed, 132 deletions(-) diff --git a/drivers/soapysdr/soapyDriver.cpp b/drivers/soapysdr/soapyDriver.cpp index f91e926..c9ead89 100644 --- a/drivers/soapysdr/soapyDriver.cpp +++ b/drivers/soapysdr/soapyDriver.cpp @@ -75,56 +75,15 @@ int soapyDriver::open(std::string device) { // Sampling frequency mDevice->setSampleRate(SOAPY_SDR_RX,0,samplingRate); mDevice->setBandwidth(SOAPY_SDR_RX,0,samplingRate); - //if (rtlsdr_set_sample_rate(mDevice,samplingRate)<0) { - // std::cerr << "ERROR: unable to set sampling rate to " << samplingRate << std::endl; - // throw std::logic_error("Fatal Error"); - //} int frequency = 24e6; // default value mDevice->setFrequency(SOAPY_SDR_RX,0,frequency); -// if (rtlsdr_set_center_freq(mDevice,frequency)<0) -// { -// std::cerr << "ERROR: unable to set frequency to" << frequency << std::endl; -// throw std::logic_error("Fatal Error"); -// } - -// int* gains; -// int count = rtlsdr_get_tuner_gains(mDevice, NULL); -// if (count > 0 ) { -// gains = (int*) malloc(sizeof(int) * count); -// count = rtlsdr_get_tuner_gains(mDevice, gains); -// std::cout << "Gain available: "; -// for (int i=0; igetGain(); mDevice->setGainMode(SOAPY_SDR_RX,0,false); -// int r = rtlsdr_set_tuner_gain_mode(mDevice, 1); -// if(r < 0) { -// std::cerr << "ERROR: Failed to enable manual gain mode" << std::endl; -// throw std::logic_error("Fatal Error"); -// } -// r = rtlsdr_set_tuner_gain(mDevice, gain*10); mDevice->setGain(SOAPY_SDR_RX,0,gain); -// if(r < 0) { -// std::cerr << "ERROR: Failed to set manual tuner gain" << std::endl; -// throw std::logic_error("Fatal Error"); -// } -// else { gain = mDevice->getGain(SOAPY_SDR_RX,0); -// int g = rtlsdr_get_tuner_gain(mDevice); -// std::cout << "Gain set to " << g/10 << std::endl; -// } - -// // Reset the buffer -// if (rtlsdr_reset_buffer(mDevice)<0) { -// std::cerr << "Error: unable to reset RTLSDR buffer" << std::endl; -// } std::cout << "[*] Initializing dongle with following configuration: " << std::endl; @@ -132,24 +91,6 @@ int soapyDriver::open(std::string device) { std::cout << "\t Sampling Rate: " << samplingRate << " samples/sec" << std::endl; std::cout << "\t Gain: " << gain << " dB" << std::endl; -// // Check if the converter is present - -// mConverterDriver.portPath = new char[CONVERTER_PATH.size() + 1]; -// std::copy(CONVERTER_PATH.begin(), CONVERTER_PATH.end(), mConverterDriver.portPath); -// mConverterDriver.portPath[CONVERTER_PATH.size()] = '\0'; - -// if(!converterInit(&mConverterDriver)){ -// std::cerr << "Warning: Failed to open the converter" << std::endl; -// //throw std::logic_error("Failed to open the converter"); -// } -// else { -// std::cout << "Converter has been detected properly" << std::endl; -// mConverterEnabled = true; -// } - -// delete[] mConverterDriver.portPath; - - return 1; } @@ -174,58 +115,6 @@ void timespec_diff(struct timespec *start, struct timespec *stop, return; } -typedef struct { - soapyDriver * dev; -} callback_package_t; - - -//static void capbuf_rtlsdr_callback( unsigned char * buf, uint32_t len, void * ctx) { -// -// struct sched_param param; -// param.sched_priority = 20; -// pthread_setschedparam (pthread_self ( ) ,SCHED_FIFO,¶m ) ; -// -// struct timespec current_time; -// clock_gettime(CLOCK_REALTIME, ¤t_time); -// -// -// // Getting parameters -// callback_package_t * cp_p=(callback_package_t *)ctx; -// callback_package_t & cp=*cp_p; -// std::vector> capbuf_raw_p = *cp.buf; -// uint64_t center_freq = cp.center_frequency; -// ReaderWriterQueue< SpectrumSegment*> *queue = cp.queue; -//// rtlsdr_dev_t * dev=cp.dev; -// -// // we set init time to current time only in the first execution -// if (cp.init_time.tv_sec == 0) -// cp.init_time = current_time; -// -// for (uint32_t t=0;t(buf[t] ,buf[t+1] )); -// } -// -// //std::cout << "[*] Sending segment " << current_time.tv_sec << "." << current_time.tv_nsec << std::endl; -// SpectrumSegment *segment = new SpectrumSegment(-1000, current_time, center_freq, -// ElectrosenseContext::getInstance()->getSamplingRate(), -// capbuf_raw_p); -// -// queue->enqueue(segment); -// capbuf_raw_p.clear(); -// -// *cp.samples_read = *cp.samples_read + len; -// -// struct timespec diff; -// timespec_diff(&cp.init_time, ¤t_time, &diff); -// -// if (cp.duration != 0 && (diff.tv_sec >= cp.duration)) -// { -//// rtlsdr_cancel_async(dev); -// pthread_exit(NULL); -// return; -// } -//} - bool soapyDriver::isRunning () { return mRunning; } @@ -239,7 +128,6 @@ static void *aux_thread (void *arg) { void soapyDriver::run () { mRunning = true; -// SyncSampling(); pthread_t myth; pthread_create ( &myth, NULL, aux_thread, (void *)this ); pthread_join(myth,NULL); @@ -270,14 +158,7 @@ void soapyDriver::SyncSampling() { { previous_freq = center_freq; -// // Native RTL-SDR - -// int r = 0;//rtlsdr_set_center_freq(mDevice, center_freq); mDevice->setFrequency(SOAPY_SDR_RX,0,center_freq); -// if (r != 0) { -// std::cerr << "Error: unable to set center frequency" << std::endl; -// mRunning = false; -// } // // Reset the buffer if (mStream != 0) @@ -287,10 +168,6 @@ void soapyDriver::SyncSampling() { } mStream=mDevice->setupStream(SOAPY_SDR_RX,"CF32"); mDevice->activateStream(mStream); -// if (false){//rtlsdr_reset_buffer(mDevice)<0) -// std::cerr << "Error: unable to reset RTLSDR buffer" << std::endl; -// mRunning = false; -// } @@ -328,12 +205,6 @@ void soapyDriver::SyncSampling() { mRunning = false; } - // for(int i = 0; i> iq_vector; for (unsigned int i=0; igetAvgFactor(); i++) { @@ -381,7 +252,6 @@ int soapyDriver::stop() // Workaround: RPi does not work properly the cancellation of the async task if (ElectrosenseContext::getInstance()->getPipeline().compare("PSD") ==0 ) { -// rtlsdr_close(mDevice); SoapySDR::Device::unmake(mDevice); mDevice = NULL; } diff --git a/drivers/soapysdr/soapyDriver.h b/drivers/soapysdr/soapyDriver.h index 90b91a1..05dae2b 100644 --- a/drivers/soapysdr/soapyDriver.h +++ b/drivers/soapysdr/soapyDriver.h @@ -71,8 +71,6 @@ namespace electrosense { void SyncSampling(); - void AsyncSampling(); - ReaderWriterQueue* getQueueIn() { return NULL; } void setQueueIn (ReaderWriterQueue* QueueIn ) {}; From c6be3b3deee80749a3960ee940fa60efcfa01f5b Mon Sep 17 00:00:00 2001 From: Brecht Reynders Date: Tue, 9 Oct 2018 21:36:36 +0200 Subject: [PATCH 5/5] removing converter things --- drivers/soapysdr/soapyDriver.cpp | 1 - drivers/soapysdr/soapyDriver.h | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/drivers/soapysdr/soapyDriver.cpp b/drivers/soapysdr/soapyDriver.cpp index c9ead89..9403369 100644 --- a/drivers/soapysdr/soapyDriver.cpp +++ b/drivers/soapysdr/soapyDriver.cpp @@ -34,7 +34,6 @@ namespace electrosense { soapyDriver::soapyDriver() { mQueueOut = new ReaderWriterQueue(100); - mConverterEnabled = false; } diff --git a/drivers/soapysdr/soapyDriver.h b/drivers/soapysdr/soapyDriver.h index 05dae2b..524cdde 100644 --- a/drivers/soapysdr/soapyDriver.h +++ b/drivers/soapysdr/soapyDriver.h @@ -41,10 +41,6 @@ #include "../../types/SpectrumSegment.h" #include -extern "C" { -#include "converter/converter.h" -}; - namespace electrosense { @@ -82,7 +78,6 @@ namespace electrosense { private: - const std::string CONVERTER_PATH = "/dev/esenseconv"; // Run the driver in the thread void run(); @@ -99,11 +94,6 @@ namespace electrosense { ReaderWriterQueue* mQueueOut; - converter mConverterDriver; - bool mConverterEnabled; - - - std::vector> m_capbuf_raw;