blob: ddcd5833d0305ff5aec8c43b7d9011b2e3106b65 [file] [log] [blame]
Roman Khassrafcd5a48b2015-05-28 19:23:55 +02001/* -*- c++ -*- */
2/* @file
Piotr Krysika6268a52017-08-23 16:02:19 +02003 * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassrafcd5a48b2015-05-28 19:23:55 +02004 * @section LICENSE
5 *
6 * Gr-gsm is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * Gr-gsm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gr-gsm; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
Roman Khassraf1c3419e2015-08-03 10:58:57 +020028#include "burst_file_sink_impl.h"
Roman Khassrafcd5a48b2015-05-28 19:23:55 +020029#include "stdio.h"
30
31namespace gr {
32 namespace gsm {
33
Roman Khassraf1c3419e2015-08-03 10:58:57 +020034 burst_file_sink::sptr
35 burst_file_sink::make(const std::string &filename)
Roman Khassrafcd5a48b2015-05-28 19:23:55 +020036 {
37 return gnuradio::get_initial_sptr
Roman Khassraf1c3419e2015-08-03 10:58:57 +020038 (new burst_file_sink_impl(filename));
Roman Khassrafcd5a48b2015-05-28 19:23:55 +020039 }
40
41 /*
42 * The private constructor
43 */
Roman Khassraf1c3419e2015-08-03 10:58:57 +020044 burst_file_sink_impl::burst_file_sink_impl(const std::string &filename)
45 : gr::block("burst_file_sink",
Roman Khassrafcd5a48b2015-05-28 19:23:55 +020046 gr::io_signature::make(0, 0, 0),
47 gr::io_signature::make(0, 0, 0)),
48 d_output_file(filename.c_str(), std::ofstream::binary)
49 {
50 message_port_register_in(pmt::mp("in"));
Vadim Yanitskiya1169202021-05-03 19:00:43 +020051 set_msg_handler(pmt::mp("in"), boost::bind(&burst_file_sink_impl::process_burst, this, boost::placeholders::_1));
Roman Khassrafcd5a48b2015-05-28 19:23:55 +020052 }
53
54 /*
55 * Our virtual destructor.
56 */
Roman Khassraf1c3419e2015-08-03 10:58:57 +020057 burst_file_sink_impl::~burst_file_sink_impl()
Roman Khassrafcd5a48b2015-05-28 19:23:55 +020058 {
59 if (d_output_file.is_open())
60 {
61 d_output_file.close();
62 }
63 }
64
Roman Khassraf1c3419e2015-08-03 10:58:57 +020065 void burst_file_sink_impl::process_burst(pmt::pmt_t msg)
Roman Khassrafcd5a48b2015-05-28 19:23:55 +020066 {
67 std::string s = pmt::serialize_str(msg);
68 const char *serialized = s.data();
69 d_output_file.write(serialized, s.length());
70 }
71 } /* namespace gsm */
72} /* namespace gr */
73