Implemented a burst sink and a burst source. See issue #42
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 028660f..6dc30a3 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -46,6 +46,8 @@
misc_utils/controlled_const_source_f_impl.cc
misc_utils/message_printer_impl.cc
misc_utils/tmsi_dumper_impl.cc
+ misc_utils/burst_sink_impl.cc
+ misc_utils/burst_source_impl.cc
decryption/decryption_impl.cc
)
diff --git a/lib/misc_utils/burst_sink_impl.cc b/lib/misc_utils/burst_sink_impl.cc
new file mode 100644
index 0000000..fdb7d98
--- /dev/null
+++ b/lib/misc_utils/burst_sink_impl.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/* @file
+ * @author Roman Khassraf <rkhassraf@gmail.com>
+ * @section LICENSE
+ *
+ * Gr-gsm 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.
+ *
+ * Gr-gsm 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 gr-gsm; 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 <gnuradio/io_signature.h>
+#include "burst_sink_impl.h"
+#include "stdio.h"
+
+namespace gr {
+ namespace gsm {
+
+ burst_sink::sptr
+ burst_sink::make(const std::string &filename)
+ {
+ return gnuradio::get_initial_sptr
+ (new burst_sink_impl(filename));
+ }
+
+ /*
+ * The private constructor
+ */
+ burst_sink_impl::burst_sink_impl(const std::string &filename)
+ : gr::block("burst_sink",
+ gr::io_signature::make(0, 0, 0),
+ gr::io_signature::make(0, 0, 0)),
+ d_output_file(filename.c_str(), std::ofstream::binary)
+ {
+ message_port_register_in(pmt::mp("in"));
+ set_msg_handler(pmt::mp("in"), boost::bind(&burst_sink_impl::process_burst, this, _1));
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ burst_sink_impl::~burst_sink_impl()
+ {
+ if (d_output_file.is_open())
+ {
+ d_output_file.close();
+ }
+ }
+
+ void burst_sink_impl::process_burst(pmt::pmt_t msg)
+ {
+ std::string s = pmt::serialize_str(msg);
+ const char *serialized = s.data();
+ d_output_file.write(serialized, s.length());
+ }
+ } /* namespace gsm */
+} /* namespace gr */
+
diff --git a/lib/misc_utils/burst_sink_impl.h b/lib/misc_utils/burst_sink_impl.h
new file mode 100644
index 0000000..f981826
--- /dev/null
+++ b/lib/misc_utils/burst_sink_impl.h
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/* @file
+ * @author Roman Khassraf <rkhassraf@gmail.com>
+ * @section LICENSE
+ *
+ * Gr-gsm 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.
+ *
+ * Gr-gsm 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 gr-gsm; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef INCLUDED_GSM_BURST_SINK_IMPL_H
+#define INCLUDED_GSM_BURST_SINK_IMPL_H
+
+#include <grgsm/misc_utils/burst_sink.h>
+#include <fstream>
+
+namespace gr {
+ namespace gsm {
+
+ class burst_sink_impl : public burst_sink
+ {
+ private:
+ std::ofstream d_output_file;
+ public:
+ burst_sink_impl(const std::string &filename);
+ ~burst_sink_impl();
+ void process_burst(pmt::pmt_t msg);
+ };
+
+ } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_BURST_SINK_IMPL_H */
+
diff --git a/lib/misc_utils/burst_source_impl.cc b/lib/misc_utils/burst_source_impl.cc
new file mode 100644
index 0000000..bd22885
--- /dev/null
+++ b/lib/misc_utils/burst_source_impl.cc
@@ -0,0 +1,108 @@
+/* -*- c++ -*- */
+/* @file
+ * @author Roman Khassraf <rkhassraf@gmail.com>
+ * @section LICENSE
+ *
+ * Gr-gsm 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.
+ *
+ * Gr-gsm 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 gr-gsm; 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 <gnuradio/io_signature.h>
+#include "burst_source_impl.h"
+#include "stdio.h"
+
+#define PMT_SIZE 174
+
+namespace gr {
+ namespace gsm {
+
+ burst_source::sptr
+ burst_source::make(const std::string &filename)
+ {
+ return gnuradio::get_initial_sptr
+ (new burst_source_impl(filename));
+ }
+
+ /*
+ * The private constructor
+ */
+ burst_source_impl::burst_source_impl(const std::string &filename)
+ : gr::block("burst_source",
+ gr::io_signature::make(0, 0, 0),
+ gr::io_signature::make(0, 0, 0)),
+ d_input_file(filename.c_str(), std::ifstream::binary),
+ d_finished(false)
+ {
+ message_port_register_out(pmt::mp("out"));
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ burst_source_impl::~burst_source_impl()
+ {
+ if (d_input_file.is_open())
+ {
+ d_input_file.close();
+ }
+ d_finished = true;
+ d_thread->interrupt();
+ d_thread->join();
+ }
+
+ bool burst_source_impl::start()
+ {
+ d_finished = false;
+ d_thread = boost::shared_ptr<gr::thread::thread>
+ (new gr::thread::thread(boost::bind(&burst_source_impl::run, this)));
+ return block::start();
+ }
+
+ bool burst_source_impl::stop()
+ {
+ d_finished = true;
+ d_thread->interrupt();
+ d_thread->join();
+ return block::stop();
+ }
+
+ bool burst_source_impl::finished()
+ {
+ return d_finished;
+ }
+
+ void burst_source_impl::run()
+ {
+ char *unserialized = (char*)malloc(sizeof(char) * PMT_SIZE);
+ while (d_input_file.read(unserialized, PMT_SIZE) && !d_finished)
+ {
+ if (d_input_file.bad())
+ {
+ break;
+ }
+ std::string s(unserialized, PMT_SIZE);
+ pmt::pmt_t burst = pmt::deserialize_str(s);
+ message_port_pub(pmt::mp("out"), burst);
+ }
+ d_finished = true;
+ }
+ } /* namespace gsm */
+} /* namespace gr */
+
diff --git a/lib/misc_utils/burst_source_impl.h b/lib/misc_utils/burst_source_impl.h
new file mode 100644
index 0000000..85217b0
--- /dev/null
+++ b/lib/misc_utils/burst_source_impl.h
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/* @file
+ * @author Roman Khassraf <rkhassraf@gmail.com>
+ * @section LICENSE
+ *
+ * Gr-gsm 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.
+ *
+ * Gr-gsm 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 gr-gsm; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef INCLUDED_GSM_BURST_SOURCE_IMPL_H
+#define INCLUDED_GSM_BURST_SOURCE_IMPL_H
+
+#include <grgsm/misc_utils/burst_source.h>
+#include <fstream>
+
+namespace gr {
+ namespace gsm {
+
+ class burst_source_impl : public burst_source
+ {
+ private:
+ boost::shared_ptr<gr::thread::thread> d_thread;
+ std::ifstream d_input_file;
+ bool d_finished;
+ void run();
+ public:
+ burst_source_impl(const std::string &filename);
+ ~burst_source_impl();
+ bool start();
+ bool stop();
+ bool finished();
+ };
+ } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_BURST_SOURCE_IMPL_H */
+