From 8b8e322a5b5e8eb84123303be8167dc3bb187f5e Mon Sep 17 00:00:00 2001 From: Manolis Surligas Date: Mon, 23 Dec 2019 23:39:53 +0200 Subject: [PATCH] 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. --- grc/satnogs_iq_sink.block.yml | 2 -- include/satnogs/iq_sink.h | 4 +--- lib/iq_sink_impl.cc | 19 ++++++++++++++++++- lib/iq_sink_impl.h | 3 ++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/grc/satnogs_iq_sink.block.yml b/grc/satnogs_iq_sink.block.yml index b3cb30d..6678ca8 100644 --- a/grc/satnogs_iq_sink.block.yml +++ b/grc/satnogs_iq_sink.block.yml @@ -33,7 +33,5 @@ inputs: templates: imports: import satnogs make: satnogs.iq_sink(${scale}, ${filename}, ${append}, ${activate}) - callbacks: - - open(${filename}) file_format: 1 diff --git a/include/satnogs/iq_sink.h b/include/satnogs/iq_sink.h index 23e9ff2..651982d 100644 --- a/include/satnogs/iq_sink.h +++ b/include/satnogs/iq_sink.h @@ -23,7 +23,6 @@ #include #include -#include 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 sptr; diff --git a/lib/iq_sink_impl.cc b/lib/iq_sink_impl.cc index f600d8a..dade3fa 100644 --- a/lib/iq_sink_impl.cc +++ b/lib/iq_sink_impl.cc @@ -26,6 +26,7 @@ #include "iq_sink_impl.h" #include #include +#include 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, diff --git a/lib/iq_sink_impl.h b/lib/iq_sink_impl.h index ff78a8c..24db436 100644 --- a/lib/iq_sink_impl.h +++ b/lib/iq_sink_impl.h @@ -22,13 +22,14 @@ #define INCLUDED_SATNOGS_IQ_SINK_IMPL_H #include +#include #include #include 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