2016-03-08 22:19:17 +01:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
|
|
|
*
|
2019-12-10 15:25:48 +01:00
|
|
|
* Copyright (C) 2016, 2019
|
|
|
|
* Libre Space Foundation <http://libre.space>
|
2016-03-08 22:19:17 +01:00
|
|
|
*
|
|
|
|
* This program 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 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gnuradio/io_signature.h>
|
|
|
|
#include "debug_msg_source_impl.h"
|
2019-12-10 15:25:48 +01:00
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <chrono>
|
2016-03-08 22:19:17 +01:00
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
namespace gr {
|
|
|
|
namespace satnogs {
|
2016-03-08 22:19:17 +01:00
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
debug_msg_source::sptr
|
|
|
|
debug_msg_source::make(const std::string &msg, double delay, bool repeat)
|
|
|
|
{
|
|
|
|
return gnuradio::get_initial_sptr(
|
|
|
|
new debug_msg_source_impl(msg, delay, repeat));
|
|
|
|
}
|
2016-03-08 22:19:17 +01:00
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
/*
|
|
|
|
* The private constructor
|
|
|
|
*/
|
|
|
|
debug_msg_source_impl::debug_msg_source_impl(const std::string &msg,
|
|
|
|
double delay, bool repeat) :
|
|
|
|
gr::block("debug_msg_source", gr::io_signature::make(0, 0, 0),
|
|
|
|
gr::io_signature::make(0, 0, 0)),
|
|
|
|
d_buf_len(msg.length()),
|
|
|
|
d_delay(delay),
|
|
|
|
d_repeat(repeat),
|
|
|
|
d_running(true)
|
|
|
|
{
|
|
|
|
d_buf = new uint8_t[msg.length()];
|
|
|
|
memcpy(d_buf, msg.c_str(), msg.length());
|
|
|
|
message_port_register_out(pmt::mp("msg"));
|
|
|
|
boost::shared_ptr<boost::thread> (
|
|
|
|
new boost::thread(
|
|
|
|
boost::bind(&debug_msg_source_impl::msg_sender, this)));
|
|
|
|
}
|
2016-03-08 22:19:17 +01:00
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
void
|
|
|
|
debug_msg_source_impl::msg_sender()
|
|
|
|
{
|
|
|
|
pmt::pmt_t msg = pmt::make_blob(d_buf, d_buf_len);
|
|
|
|
if (d_repeat) {
|
|
|
|
while (d_running) {
|
2019-12-10 15:25:48 +01:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds((size_t)(d_delay * 1e3)));
|
2019-09-12 15:25:10 +02:00
|
|
|
message_port_pub(pmt::mp("msg"), msg);
|
2016-03-08 22:19:17 +01:00
|
|
|
}
|
2019-09-12 15:25:10 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-12-10 15:25:48 +01:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds((size_t)(d_delay * 1e3)));
|
2019-09-12 15:25:10 +02:00
|
|
|
message_port_pub(pmt::mp("msg"), msg);
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 22:19:17 +01:00
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
/*
|
|
|
|
* Our virtual destructor.
|
|
|
|
*/
|
|
|
|
debug_msg_source_impl::~debug_msg_source_impl()
|
|
|
|
{
|
|
|
|
d_running = false;
|
|
|
|
d_thread->join();
|
|
|
|
delete[] d_buf;
|
|
|
|
}
|
2016-03-08 22:19:17 +01:00
|
|
|
|
2019-09-12 15:25:10 +02:00
|
|
|
} /* namespace satnogs */
|
2016-03-08 22:19:17 +01:00
|
|
|
} /* namespace gr */
|
|
|
|
|