Fix IQ file sink file creation

The IQ File sink, tried to create the IQ
file even if it was instructed by the user not to
store IQ data. Despite the fact that no data were
written, it could trigger however errors in case
the destination file could not be opened,
eg. due to permissions.

The problem was that the base class tried to
open the file at its contructor. This commit
deals with this issue and the file is created
only if the user specifies that wants the IQ
data to be stored.
This commit is contained in:
Manolis Surligas 2019-12-23 23:39:53 +02:00
parent cb981074b9
commit 8b8e322a5b
4 changed files with 21 additions and 7 deletions

View File

@ -33,7 +33,5 @@ inputs:
templates:
imports: import satnogs
make: satnogs.iq_sink(${scale}, ${filename}, ${append}, ${activate})
callbacks:
- open(${filename})
file_format: 1

View File

@ -23,7 +23,6 @@
#include <satnogs/api.h>
#include <gnuradio/sync_block.h>
#include <gnuradio/blocks/file_sink_base.h>
namespace gr {
namespace satnogs {
@ -36,8 +35,7 @@ namespace satnogs {
* \ingroup satnogs
*
*/
class SATNOGS_API iq_sink : virtual public gr::sync_block,
virtual public gr::blocks::file_sink_base {
class SATNOGS_API iq_sink : virtual public gr::sync_block {
public:
typedef boost::shared_ptr<iq_sink> sptr;

View File

@ -26,6 +26,7 @@
#include "iq_sink_impl.h"
#include <volk/volk.h>
#include <stdexcept>
#include <gnuradio/blocks/null_sink.h>
namespace gr {
namespace satnogs {
@ -46,11 +47,27 @@ iq_sink_impl::iq_sink_impl(const float scale, const char *filename,
gr::sync_block("iq_sink",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(0, 0, 0)),
file_sink_base(filename, true, append),
file_sink_base(),
d_scale(scale),
d_num_points(16384),
d_status((iq_sink_status_t) status)
{
d_fp = 0;
d_new_fp = 0;
d_updated = false;
d_is_binary = true;
d_append = append;
/*
* Because the constructor of the derived class explicitly calls the open()
* and we want to avoid trying to open and invalid file in case of the
* user option is for bypassing this block, we call it explicitly
*/
if (status == IQ_SINK_STATUS_ACTIVE) {
if (!open(filename)) {
throw std::invalid_argument("IQ File Sink: Could not open file");
}
}
set_max_noutput_items(d_num_points);
unsigned int alignment = volk_get_alignment();
d_out = (int16_t *) volk_malloc(sizeof(int16_t) * d_num_points * 2,

View File

@ -22,13 +22,14 @@
#define INCLUDED_SATNOGS_IQ_SINK_IMPL_H
#include <satnogs/iq_sink.h>
#include <gnuradio/blocks/file_sink_base.h>
#include <chrono>
#include <fstream>
namespace gr {
namespace satnogs {
class iq_sink_impl : public iq_sink {
class iq_sink_impl : public iq_sink, public gr::blocks::file_sink_base {
private:
/**
* The different values for iq sink status