aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoman Khassraf <roman@khassraf.at>2015-08-03 16:17:46 +0200
committerRoman Khassraf <roman@khassraf.at>2015-08-03 16:17:46 +0200
commitc323454a3fbd8d617022ee309613f21c8b18d797 (patch)
treec5623f341eb017d42200c2039f43d7a4e4a4fce7 /lib
parent09405388e0bf95021654b8c7f07226fe795565d5 (diff)
Implemented message file source and sink. Issue #101
Diffstat (limited to 'lib')
-rw-r--r--lib/CMakeLists.txt2
-rw-r--r--lib/misc_utils/message_file_sink_impl.cc73
-rw-r--r--lib/misc_utils/message_file_sink_impl.h46
-rw-r--r--lib/misc_utils/message_file_source_impl.cc106
-rw-r--r--lib/misc_utils/message_file_source_impl.h50
5 files changed, 277 insertions, 0 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 61f0858..1ddab6d 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -54,6 +54,8 @@ list(APPEND grgsm_sources
misc_utils/burst_source_impl.cc
misc_utils/burst_sink_qa_impl.cc
misc_utils/burst_source_qa_impl.cc
+ misc_utils/message_file_sink_impl.cc
+ misc_utils/message_file_source_impl.cc
decryption/decryption_impl.cc )
add_library(gnuradio-grgsm SHARED ${grgsm_sources})
diff --git a/lib/misc_utils/message_file_sink_impl.cc b/lib/misc_utils/message_file_sink_impl.cc
new file mode 100644
index 0000000..7e52993
--- /dev/null
+++ b/lib/misc_utils/message_file_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 "message_file_sink_impl.h"
+#include <stdio.h>
+
+namespace gr {
+ namespace gsm {
+
+ message_file_sink::sptr
+ message_file_sink::make(const std::string &filename)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_file_sink_impl(filename));
+ }
+
+ /*
+ * The private constructor
+ */
+ message_file_sink_impl::message_file_sink_impl(const std::string &filename)
+ : gr::block("message_file_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(&message_file_sink_impl::process_message, this, _1));
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ message_file_sink_impl::~message_file_sink_impl()
+ {
+ if (d_output_file.is_open())
+ {
+ d_output_file.close();
+ }
+ }
+
+ void message_file_sink_impl::process_message(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/message_file_sink_impl.h b/lib/misc_utils/message_file_sink_impl.h
new file mode 100644
index 0000000..6757e69
--- /dev/null
+++ b/lib/misc_utils/message_file_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_MESSAGE_FILE_SINK_IMPL_H
+#define INCLUDED_GSM_MESSAGE_FILE_SINK_IMPL_H
+
+#include <grgsm/misc_utils/message_file_sink.h>
+#include <fstream>
+
+namespace gr {
+ namespace gsm {
+
+ class message_file_sink_impl : public message_file_sink
+ {
+ private:
+ std::ofstream d_output_file;
+ public:
+ message_file_sink_impl(const std::string &filename);
+ ~message_file_sink_impl();
+ void process_message(pmt::pmt_t msg);
+ };
+
+ } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_MESSAGE_FILE_SINK_IMPL_H */
+
diff --git a/lib/misc_utils/message_file_source_impl.cc b/lib/misc_utils/message_file_source_impl.cc
new file mode 100644
index 0000000..540fe9e
--- /dev/null
+++ b/lib/misc_utils/message_file_source_impl.cc
@@ -0,0 +1,106 @@
+/* -*- 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 "message_file_source_impl.h"
+#include <stdio.h>
+
+#define PMT_SIZE 49
+
+namespace gr {
+ namespace gsm {
+
+ message_file_source::sptr
+ message_file_source::make(const std::string &filename)
+ {
+ return gnuradio::get_initial_sptr
+ (new message_file_source_impl(filename));
+ }
+
+ /*
+ * The private constructor
+ */
+ message_file_source_impl::message_file_source_impl(const std::string &filename)
+ : gr::block("message_file_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.
+ */
+ message_file_source_impl::~message_file_source_impl()
+ {
+ if (d_finished == false){
+ d_finished = true;
+ }
+ }
+
+ bool message_file_source_impl::start()
+ {
+ d_finished = false;
+ d_thread = boost::shared_ptr<gr::thread::thread>
+ (new gr::thread::thread(boost::bind(&message_file_source_impl::run, this)));
+ return block::start();
+ }
+
+ bool message_file_source_impl::stop()
+ {
+ d_finished = true;
+ d_thread->interrupt();
+ d_thread->join();
+ return block::stop();
+ }
+
+ bool message_file_source_impl::finished()
+ {
+ return d_finished;
+ }
+
+ void message_file_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_input_file.close();
+ post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::from_long(1)));
+ }
+ } /* namespace gsm */
+} /* namespace gr */
+
diff --git a/lib/misc_utils/message_file_source_impl.h b/lib/misc_utils/message_file_source_impl.h
new file mode 100644
index 0000000..42f65cb
--- /dev/null
+++ b/lib/misc_utils/message_file_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_MESSAGE_FILE_SOURCE_IMPL_H
+#define INCLUDED_GSM_MESSAGE_FILE_SOURCE_IMPL_H
+
+#include <grgsm/misc_utils/message_file_source.h>
+#include <fstream>
+
+namespace gr {
+ namespace gsm {
+
+ class message_file_source_impl : public message_file_source
+ {
+ private:
+ boost::shared_ptr<gr::thread::thread> d_thread;
+ std::ifstream d_input_file;
+ bool d_finished;
+ void run();
+ public:
+ message_file_source_impl(const std::string &filename);
+ ~message_file_source_impl();
+ bool start();
+ bool stop();
+ bool finished();
+ };
+ } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_MESSAGE_FILE_SOURCE_IMPL_H */
+