Skip to content

Commit

Permalink
Fixed bug #1 about recover from error in adquisition thread
Browse files Browse the repository at this point in the history
  • Loading branch information
rocapal committed Jun 26, 2018
1 parent f3a551f commit acd6cb7
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 32 deletions.
3 changes: 2 additions & 1 deletion MiscBlocks/AvroSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@


#include "../drivers/Component.h"
#include "../drivers/Communication.h"
#include "../types/SpectrumSegment.h"
#include "../context/ElectrosenseContext.h"

Expand All @@ -44,7 +45,7 @@ extern "C" {
namespace electrosense {


class AvroSerialization: public Component<SpectrumSegment*,SpectrumSegment*> {
class AvroSerialization: public Component, public Communication<SpectrumSegment*,SpectrumSegment*> {

public:

Expand Down
3 changes: 2 additions & 1 deletion MiscBlocks/FileSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
#include <iomanip>

#include "../drivers/Component.h"
#include "../drivers/Communication.h"
#include "../types/SpectrumSegment.h"
#include "../context/ElectrosenseContext.h"

namespace electrosense {

class FileSink: public Component<SpectrumSegment*,SpectrumSegment*> {
class FileSink: public Component, public Communication<SpectrumSegment*,SpectrumSegment*> {

public:

Expand Down
3 changes: 2 additions & 1 deletion MiscBlocks/Transmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@


#include "../drivers/Component.h"
#include "../drivers/Communication.h"
#include "../types/SpectrumSegment.h"
#include "../context/ElectrosenseContext.h"


namespace electrosense {

class Transmission: public Component<SpectrumSegment*,SpectrumSegment*> {
class Transmission: public Component, public Communication<SpectrumSegment*,SpectrumSegment*> {

public:

Expand Down
3 changes: 2 additions & 1 deletion ProcessingBlocks/Averaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
#include <liquid/liquid.h>

#include "../drivers/Component.h"
#include "../drivers/Communication.h"
#include "../types/SpectrumSegment.h"
#include "../context/ElectrosenseContext.h"

namespace electrosense {

class Averaging: public Component<SpectrumSegment*,SpectrumSegment*> {
class Averaging: public Component, public Communication<SpectrumSegment*,SpectrumSegment*> {

public:

Expand Down
3 changes: 2 additions & 1 deletion ProcessingBlocks/FFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
#include <liquid/liquid.h>

#include "../drivers/Component.h"
#include "../drivers/Communication.h"
#include "../types/SpectrumSegment.h"
#include "../context/ElectrosenseContext.h"

namespace electrosense {

class FFT: public Component<SpectrumSegment*,SpectrumSegment*> {
class FFT: public Component, public Communication<SpectrumSegment*,SpectrumSegment*> {

public:

Expand Down
3 changes: 2 additions & 1 deletion ProcessingBlocks/RemoveDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@


#include "../drivers/Component.h"
#include "../drivers/Communication.h"
#include "../types/SpectrumSegment.h"
#include "../context/ElectrosenseContext.h"

namespace electrosense {

class RemoveDC: public Component<SpectrumSegment*,SpectrumSegment*> {
class RemoveDC: public Component, public Communication<SpectrumSegment*,SpectrumSegment*> {


public:
Expand Down
3 changes: 2 additions & 1 deletion ProcessingBlocks/Windowing.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@


#include "../drivers/Component.h"
#include "../drivers/Communication.h"
#include "../types/SpectrumSegment.h"
#include "../context/ElectrosenseContext.h"

namespace electrosense {

class Windowing: public Component<SpectrumSegment*,SpectrumSegment*> {
class Windowing: public Component, public Communication<SpectrumSegment*,SpectrumSegment*> {

public:

Expand Down
51 changes: 51 additions & 0 deletions drivers/Communication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* Authors:
* Roberto Calvo-Palomino <[email protected]>
*
*/

#ifndef ES_SENSOR_COMMUNCATION_H
#define ES_SENSOR_COMMUNCATION_H

#include <thread>

#include "../misc/readerwriterqueue.h"

using namespace moodycamel;

template <typename Tin, typename Tout>
class Communication {

public:

typedef const Tin ParamIn;
typedef const Tout ParamOut;

// Getters for the queue
virtual ReaderWriterQueue<Tin>* getQueueIn() = 0;
virtual ReaderWriterQueue<Tout>* getQueueOut() = 0;

// Setters for the queue
virtual void setQueueIn (ReaderWriterQueue<Tin>* QueueIn) = 0;
virtual void setQueueOut (ReaderWriterQueue<Tout>* QueueOut) = 0;

};

#endif
13 changes: 0 additions & 13 deletions drivers/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,11 @@

#include "../misc/readerwriterqueue.h"

using namespace moodycamel;

template <typename Tin, typename Tout>
class Component {

public:

typedef const Tin ParamIn;
typedef const Tout ParamOut;

// Getters for the queue
virtual ReaderWriterQueue<Tin>* getQueueIn() = 0;
virtual ReaderWriterQueue<Tout>* getQueueOut() = 0;

// Setters for the queue
virtual void setQueueIn (ReaderWriterQueue<Tin>* QueueIn) = 0;
virtual void setQueueOut (ReaderWriterQueue<Tout>* QueueOut) = 0;

// Name identifier for the component
virtual std::string getNameId () = 0;

Expand Down
3 changes: 2 additions & 1 deletion drivers/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Driver {
virtual int close() = 0;



//
virtual bool isRunning() = 0;

private:

Expand Down
25 changes: 20 additions & 5 deletions drivers/rtlsdr/rtlsdrDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ int rtlsdrDriver::close () {
return 1;
}

bool rtlsdrDriver::isRunning () {
return mRunning;
};

void rtlsdrDriver::run () {

Expand Down Expand Up @@ -183,6 +186,7 @@ void rtlsdrDriver::run () {
if (mConverterEnabled) {

if(!converterTune(&mConverterDriver, center_freq/1e3, &proxy_freq, &mustInvert)){
mRunning = false;
throw std::logic_error("Failed to converterTune");
}

Expand All @@ -193,24 +197,32 @@ void rtlsdrDriver::run () {
previous_proxy_freq = proxy_freq;

int r = rtlsdr_set_center_freq(mDevice, proxy_freq * 1e3);
if (r != 0)
if (r != 0) {
std::cerr << "Error: unable to set center frequency" << std::endl;
mRunning = false;
}

// Reset the buffer
if (rtlsdr_reset_buffer(mDevice)<0)
if (rtlsdr_reset_buffer(mDevice)<0) {
std::cerr << "Error: unable to reset RTLSDR buffer" << std::endl;
mRunning = false;
}

}
// Native RTL-SDR
} else {

int r = rtlsdr_set_center_freq(mDevice, center_freq);
if (r != 0)
if (r != 0) {
std::cerr << "Error: unable to set center frequency" << std::endl;
mRunning = false;
}

// Reset the buffer
if (rtlsdr_reset_buffer(mDevice)<0)
if (rtlsdr_reset_buffer(mDevice)<0) {
std::cerr << "Error: unable to reset RTLSDR buffer" << std::endl;
mRunning = false;
}
}


Expand Down Expand Up @@ -241,7 +253,10 @@ void rtlsdrDriver::run () {
clock_gettime(CLOCK_REALTIME, &current_time);

int r = rtlsdr_read_sync(mDevice, iq_buf, slen, &n_read);
if(r != 0 || (unsigned int)n_read != slen) fprintf(stderr, "WARNING: Synchronous read failed.\n");
if(r != 0 || (unsigned int)n_read != slen) {
fprintf(stderr, "WARNING: Synchronous read failed.\n");
mRunning = false;
}

if(mustInvert){
for(int i = 0; i<n_read; i+= 2){
Expand Down
7 changes: 5 additions & 2 deletions drivers/rtlsdr/rtlsdrDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "../Driver.h"
#include "../Component.h"
#include "../Communication.h"
#include "rtlsdrDriver.h"
#include "../../context/ElectrosenseContext.h"
#include "../common/SequentialHopping.h"
Expand All @@ -45,7 +46,7 @@ namespace electrosense {



class rtlsdrDriver: public Driver, public Component<int, SpectrumSegment*> {
class rtlsdrDriver: public Driver, public Component, public Communication<int, SpectrumSegment*> {

public:

Expand All @@ -62,6 +63,9 @@ namespace electrosense {
// Stop
int stop();

// Running
bool isRunning ();

ReaderWriterQueue<int>* getQueueIn() { return NULL; }
void setQueueIn (ReaderWriterQueue<int>* QueueIn ) {};

Expand All @@ -73,7 +77,6 @@ namespace electrosense {

private:

const unsigned int MAX_FREQ_RTL_SDR = 1766000000;
const std::string CONVERTER_PATH = "/dev/esenseconv";

// Run the driver in the thread
Expand Down
Loading

0 comments on commit acd6cb7

Please sign in to comment.