aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2015-02-22 20:42:49 +0100
committerSylvain Munaut <tnt@246tNt.com>2016-09-14 10:14:32 -0600
commit2efc4ddc4e3e5a650d4f22f17ce4cd0d08fcde52 (patch)
treefa88943e92679440e42c05db758b79a3733b2a73
parent98fec6650d8e7e48bccb87a739c3d9c82167eb05 (diff)
gr-gmr1: Add special file sink to record RACH in text format
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r--gr-gmr1/grc/CMakeLists.txt1
-rw-r--r--gr-gmr1/grc/rach_file_sink.xml29
-rw-r--r--gr-gmr1/include/gnuradio/gmr1/CMakeLists.txt1
-rw-r--r--gr-gmr1/include/gnuradio/gmr1/rach_file_sink.h56
-rw-r--r--gr-gmr1/lib/CMakeLists.txt1
-rw-r--r--gr-gmr1/lib/rach_file_sink_impl.cc149
-rw-r--r--gr-gmr1/lib/rach_file_sink_impl.h66
-rw-r--r--gr-gmr1/swig/gmr1_swig.i4
8 files changed, 307 insertions, 0 deletions
diff --git a/gr-gmr1/grc/CMakeLists.txt b/gr-gmr1/grc/CMakeLists.txt
index 850d049..84ce36e 100644
--- a/gr-gmr1/grc/CMakeLists.txt
+++ b/gr-gmr1/grc/CMakeLists.txt
@@ -22,5 +22,6 @@ install(FILES
gsmtap_sink.xml
rach_demod.xml
rach_detect_fft.xml
+ rach_file_sink.xml
DESTINATION share/gnuradio/grc/blocks
)
diff --git a/gr-gmr1/grc/rach_file_sink.xml b/gr-gmr1/grc/rach_file_sink.xml
new file mode 100644
index 0000000..b72160f
--- /dev/null
+++ b/gr-gmr1/grc/rach_file_sink.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<block>
+ <name>RACH File Sink</name>
+ <key>rach_file_sink</key>
+ <category>GMR-1</category>
+ <import>from gnuradio import gmr1</import>
+ <make>gmr1.rach_file_sink($filename, $center_freq, $sample_rate)</make>
+ <param>
+ <name>Filename</name>
+ <key>filename</key>
+ <type>string</type>
+ </param>
+ <param>
+ <name>Center Frequency</name>
+ <key>center_freq</key>
+ <value>0</value>
+ <type>float</type>
+ </param>
+ <param>
+ <name>Sample Rate</name>
+ <key>sample_rate</key>
+ <value>0</value>
+ <type>float</type>
+ </param>
+ <sink>
+ <name>pdus</name>
+ <type>message</type>
+ </sink>
+</block>
diff --git a/gr-gmr1/include/gnuradio/gmr1/CMakeLists.txt b/gr-gmr1/include/gnuradio/gmr1/CMakeLists.txt
index a05f79e..399bbae 100644
--- a/gr-gmr1/include/gnuradio/gmr1/CMakeLists.txt
+++ b/gr-gmr1/include/gnuradio/gmr1/CMakeLists.txt
@@ -26,5 +26,6 @@ install(FILES
gsmtap_sink.h
rach_demod.h
rach_detect_fft.h
+ rach_file_sink.h
DESTINATION include/gnuradio/gmr1
)
diff --git a/gr-gmr1/include/gnuradio/gmr1/rach_file_sink.h b/gr-gmr1/include/gnuradio/gmr1/rach_file_sink.h
new file mode 100644
index 0000000..51d5aea
--- /dev/null
+++ b/gr-gmr1/include/gnuradio/gmr1/rach_file_sink.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2015 Sylvain Munaut <tnt@246tNt.com>
+ *
+ * This 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, or (at your option)
+ * any later version.
+ *
+ * This software 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 this software; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_GMR1_RACH_FILE_SINK_H
+#define INCLUDED_GR_GMR1_RACH_FILE_SINK_H
+
+#include <gnuradio/gmr1/api.h>
+
+#include <gnuradio/blocks/pdu.h>
+#include <gnuradio/block.h>
+
+namespace gr {
+ namespace gmr1 {
+
+ /*!
+ * \brief
+ * \ingroup
+ */
+ class GR_GMR1_API rach_file_sink : virtual public block
+ {
+ public:
+ typedef boost::shared_ptr<rach_file_sink> sptr;
+
+ static sptr make(const std::string &filename,
+ const double center_freq, const double sample_rate);
+
+ virtual std::string filename() const = 0;
+
+ virtual double center_freq() const = 0;
+ virtual double sample_rate() const = 0;
+
+ virtual void set_center_freq(const double center_freq) = 0;
+ virtual void set_sample_rate(const double sample_rate) = 0;
+ };
+
+ } // namespace gmr1
+} // namespace gr
+
+#endif /* INCLUDED_GR_GMR1_RACH_FILE_SINK_H */
diff --git a/gr-gmr1/lib/CMakeLists.txt b/gr-gmr1/lib/CMakeLists.txt
index 10b9475..992dd08 100644
--- a/gr-gmr1/lib/CMakeLists.txt
+++ b/gr-gmr1/lib/CMakeLists.txt
@@ -46,6 +46,7 @@ list(APPEND gmr1_sources
gsmtap_sink_impl.cc
rach_demod_impl.cc
rach_detect_fft_impl.cc
+ rach_file_sink_impl.cc
)
add_library(gnuradio-gmr1 SHARED ${gmr1_sources})
diff --git a/gr-gmr1/lib/rach_file_sink_impl.cc b/gr-gmr1/lib/rach_file_sink_impl.cc
new file mode 100644
index 0000000..43695e3
--- /dev/null
+++ b/gr-gmr1/lib/rach_file_sink_impl.cc
@@ -0,0 +1,149 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2015 Sylvain Munaut <tnt@246tNt.com>
+ *
+ * This 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, or (at your option)
+ * any later version.
+ *
+ * This software 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 this software; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <cstdio>
+
+#include <gnuradio/io_signature.h>
+
+#include "rach_file_sink_impl.h"
+
+
+namespace gr {
+ namespace gmr1 {
+
+rach_file_sink::sptr
+rach_file_sink::make(const std::string &filename,
+ const double center_freq, const double sample_rate)
+{
+ return gnuradio::get_initial_sptr(
+ new rach_file_sink_impl(filename, center_freq, sample_rate)
+ );
+}
+
+rach_file_sink_impl::rach_file_sink_impl(const std::string &filename,
+ const double center_freq,
+ const double sample_rate)
+ : gr::block("rach_file_sink",
+ io_signature::make(0, 0, 0),
+ io_signature::make(0, 0, 0)),
+ d_filename(filename),
+ d_center_freq(center_freq), d_sample_rate(sample_rate)
+{
+ message_port_register_in(PDU_PORT_ID);
+ set_msg_handler(PDU_PORT_ID, boost::bind(&rach_file_sink_impl::send_pdu, this, _1));
+
+ this->d_fh = fopen(filename.c_str(), "a");
+ if (!this->d_fh)
+ throw std::runtime_error("Unable to open output file");
+}
+
+rach_file_sink_impl::~rach_file_sink_impl()
+{
+ fclose(this->d_fh);
+}
+
+
+std::string
+rach_file_sink_impl::filename() const
+{
+ return this->d_filename;
+}
+
+double
+rach_file_sink_impl::center_freq() const
+{
+ return this->d_center_freq;
+}
+
+double
+rach_file_sink_impl::sample_rate() const
+{
+ return this->d_sample_rate;
+}
+
+void
+rach_file_sink_impl::set_center_freq(const double center_freq)
+{
+ this->d_center_freq = center_freq;
+}
+
+void
+rach_file_sink_impl::set_sample_rate(const double sample_rate)
+{
+ this->d_sample_rate = sample_rate;
+}
+
+
+bool
+rach_file_sink_impl::start()
+{
+ /* Nothing yet */
+}
+
+bool
+rach_file_sink_impl::stop()
+{
+ fflush(this->d_fh);
+}
+
+
+void
+rach_file_sink_impl::send_pdu(pmt::pmt_t pdu)
+{
+ static const pmt::pmt_t key_sb_mask = pmt::string_to_symbol("sb_mask");
+ static const pmt::pmt_t key_freq = pmt::string_to_symbol("freq");
+
+ pmt::pmt_t meta = pmt::car(pdu);
+ pmt::pmt_t vector = pmt::cdr(pdu);
+ size_t len = pmt::length(vector);
+ size_t offset(0);
+ const uint8_t* rach = (const uint8_t*) pmt::uniform_vector_elements(vector, offset);
+
+ /* Validate */
+ if (!is_dict(meta) ||
+ !dict_has_key(meta, key_sb_mask) ||
+ !dict_has_key(meta, key_freq))
+ throw std::runtime_error("Invalid RACH PDU");
+
+ /* Grab SB_Mask & freq */
+ uint8_t sb_mask = pmt::to_long(pmt::dict_ref(meta, key_sb_mask, pmt::PMT_NIL));
+ double freq = pmt::to_double(pmt::dict_ref(meta, key_freq, pmt::PMT_NIL));
+
+ fprintf(this->d_fh, "%02hhx %.17g %.17g ",
+ sb_mask,
+ freq,
+ this->d_center_freq + (this->d_sample_rate * freq / (2.0 * M_PI))
+ );
+
+ /* Raw bytes */
+ for (int i=0; i<len; i++)
+ fprintf(this->d_fh, "%02hhx", rach[i]);
+
+ /* EOL */
+ fprintf(this->d_fh, "\n");
+}
+
+ } // namespace gmr1
+} // namespace gr
diff --git a/gr-gmr1/lib/rach_file_sink_impl.h b/gr-gmr1/lib/rach_file_sink_impl.h
new file mode 100644
index 0000000..6738f01
--- /dev/null
+++ b/gr-gmr1/lib/rach_file_sink_impl.h
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2015 Sylvain Munaut <tnt@246tNt.com>
+ *
+ * This 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, or (at your option)
+ * any later version.
+ *
+ * This software 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 this software; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef INCLUDED_GR_GMR1_RACH_FILE_SINK_IMPL_H
+#define INCLUDED_GR_GMR1_RACH_FILE_SINK_IMPL_H
+
+#include <gnuradio/gmr1/rach_file_sink.h>
+
+#include <cstdio>
+
+namespace gr {
+ namespace gmr1 {
+
+ /*!
+ * \brief
+ * \ingroup gmr1
+ */
+ class rach_file_sink_impl : public rach_file_sink
+ {
+ private:
+ std::string d_filename;
+ double d_center_freq;
+ double d_sample_rate;
+
+ FILE *d_fh;
+
+ void send_pdu(pmt::pmt_t pdu);
+
+ public:
+ rach_file_sink_impl(const std::string &filename,
+ const double center_freq, const double sample_rate);
+ virtual ~rach_file_sink_impl();
+
+ std::string filename() const;
+ double center_freq() const;
+ double sample_rate() const;
+
+ void set_center_freq(const double center_freq);
+ void set_sample_rate(const double sample_rate);
+
+ bool start();
+ bool stop();
+ };
+
+ } // namespace gmr1
+} // namespace gr
+
+#endif /* INCLUDED_GR_GMR1_RACH_FILE_SINK_IMPL_H */
diff --git a/gr-gmr1/swig/gmr1_swig.i b/gr-gmr1/swig/gmr1_swig.i
index 0f427d5..4c58d32 100644
--- a/gr-gmr1/swig/gmr1_swig.i
+++ b/gr-gmr1/swig/gmr1_swig.i
@@ -13,6 +13,7 @@
#include "gnuradio/gmr1/gsmtap_sink.h"
#include "gnuradio/gmr1/rach_demod.h"
#include "gnuradio/gmr1/rach_detect_fft.h"
+#include "gnuradio/gmr1/rach_file_sink.h"
%}
%include "gnuradio/gmr1/burst_to_tagged_stream.h"
@@ -26,3 +27,6 @@ GR_SWIG_BLOCK_MAGIC2(gmr1, rach_demod);
%include "gnuradio/gmr1/rach_detect_fft.h"
GR_SWIG_BLOCK_MAGIC2(gmr1, rach_detect_fft);
+
+%include "gnuradio/gmr1/rach_file_sink.h"
+GR_SWIG_BLOCK_MAGIC2(gmr1, rach_file_sink);