Add new debug message source that can accept raw bytes

This commit is contained in:
Manolis Surligas 2016-06-02 17:06:40 +03:00
parent 0067c19454
commit 6ed86dbae5
10 changed files with 256 additions and 5 deletions

View File

@ -37,5 +37,6 @@ install(FILES
satnogs_whitening.xml
satnogs_udp_msg_sink.xml
satnogs_upsat_transmitter.xml
satnogs_coarse_doppler_correction_cc.xml DESTINATION share/gnuradio/grc/blocks
satnogs_coarse_doppler_correction_cc.xml
satnogs_debug_msg_source_raw.xml DESTINATION share/gnuradio/grc/blocks
)

View File

@ -0,0 +1,41 @@
<?xml version="1.0"?>
<block>
<name>Debug Message Source Raw</name>
<key>satnogs_debug_msg_source_raw</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.debug_msg_source_raw($msg, $delay, $repeat)</make>
<param>
<name>Message</name>
<key>msg</key>
<value>[0x33, 0x44, 0x55, 0x66]</value>
<type>raw</type>
</param>
<param>
<name>Delay (seconds)</name>
<key>delay</key>
<value>0.01</value>
<type>real</type>
</param>
<param>
<name>Repeat</name>
<key>repeat</key>
<type>enum</type>
<option>
<name>Yes</name>
<key>True</key>
</option>
<option>
<name>No</name>
<key>False</key>
</option>
</param>
<source>
<name>msg</name>
<type>message</type>
</source>
</block>

View File

@ -49,5 +49,6 @@ install(FILES
upsat_fsk_frame_encoder.h
whitening.h
udp_msg_sink.h
coarse_doppler_correction_cc.h DESTINATION include/satnogs
coarse_doppler_correction_cc.h
debug_msg_source_raw.h DESTINATION include/satnogs
)

View File

@ -45,7 +45,6 @@ namespace gr
* @param delay delay in seconds between consecutive messages
* @param repeat if set to yes the block will produce a message every
* \p delay seconds
* @return
*/
static sptr
make (const std::string &msg, double delay, bool repeat = true);

View File

@ -0,0 +1,59 @@
/* -*- c++ -*- */
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2016, Libre Space Foundation <http://librespacefoundation.org/>
*
* 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/>.
*/
#ifndef INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_RAW_H
#define INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_RAW_H
#include <satnogs/api.h>
#include <gnuradio/block.h>
namespace gr
{
namespace satnogs
{
/*!
* \brief A block for debug reasons producing specific messages.
* The input message can be anything, opposed to the \p debug_msg_source()
* block that can accept only string messages.
* \ingroup satnogs
*
*/
class SATNOGS_API debug_msg_source_raw : virtual public gr::block
{
public:
typedef boost::shared_ptr<debug_msg_source_raw> sptr;
/**
* Debug message source block.
* @param msg the message
* @param delay delay in seconds between consecutive messages
* @param repeat if set to yes the block will produce a message every
* \p delay seconds
*/
static sptr
make (const std::vector<uint8_t> &msg, double delay, bool repeat);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_RAW_H */

View File

@ -47,7 +47,8 @@ list(APPEND satnogs_sources
upsat_fsk_frame_encoder_impl.cc
whitening.cc
udp_msg_sink_impl.cc
coarse_doppler_correction_cc_impl.cc )
coarse_doppler_correction_cc_impl.cc
debug_msg_source_raw_impl.cc )
set(satnogs_sources "${satnogs_sources}" PARENT_SCOPE)
if(NOT satnogs_sources)

View File

@ -83,7 +83,7 @@ namespace gr
{
d_running = false;
d_thread->join ();
delete d_buf;
delete[] d_buf;
}
} /* namespace satnogs */

View File

@ -0,0 +1,91 @@
/* -*- c++ -*- */
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2016, Libre Space Foundation <http://librespacefoundation.org/>
*
* 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_raw_impl.h"
namespace gr
{
namespace satnogs
{
debug_msg_source_raw::sptr
debug_msg_source_raw::make (const std::vector<uint8_t> &msg, double delay,
bool repeat)
{
return gnuradio::get_initial_sptr (
new debug_msg_source_raw_impl (msg, delay, repeat));
}
/*
* The private constructor
*/
debug_msg_source_raw_impl::debug_msg_source_raw_impl (
const std::vector<uint8_t> &msg, double delay, bool repeat) :
gr::block ("debug_msg_source_raw", gr::io_signature::make (0, 0, 0),
gr::io_signature::make (0, 0, 0)),
d_buf_len (msg.size ()),
d_delay (delay),
d_repeat (repeat),
d_running (true)
{
d_buf = new uint8_t[msg.size()];
memcpy (d_buf, msg.data(), msg.size());
message_port_register_out (pmt::mp ("msg"));
boost::shared_ptr<boost::thread> (
new boost::thread (
boost::bind (&debug_msg_source_raw_impl::msg_sender, this)));
}
void
debug_msg_source_raw_impl::msg_sender ()
{
pmt::pmt_t msg = pmt::make_blob (d_buf, d_buf_len);
if (d_repeat) {
while (d_running) {
boost::this_thread::sleep_for (
boost::chrono::milliseconds ((size_t) (d_delay * 1e3)));
message_port_pub (pmt::mp ("msg"), msg);
}
}
else {
boost::this_thread::sleep_for (
boost::chrono::milliseconds ((size_t) (d_delay * 1e3)));
message_port_pub (pmt::mp ("msg"), msg);
}
}
/*
* Our virtual destructor.
*/
debug_msg_source_raw_impl::~debug_msg_source_raw_impl ()
{
d_running = false;
d_thread->join ();
delete[] d_buf;
}
} /* namespace satnogs */
} /* namespace gr */

View File

@ -0,0 +1,55 @@
/* -*- c++ -*- */
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2016, Libre Space Foundation <http://librespacefoundation.org/>
*
* 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/>.
*/
#ifndef INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_RAW_IMPL_H
#define INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_RAW_IMPL_H
#include <satnogs/debug_msg_source_raw.h>
namespace gr
{
namespace satnogs
{
class debug_msg_source_raw_impl : public debug_msg_source_raw
{
private:
const size_t d_buf_len;
const double d_delay;
const bool d_repeat;
bool d_running;
boost::shared_ptr<boost::thread> d_thread;
uint8_t *d_buf;
void
msg_sender ();
public:
debug_msg_source_raw_impl (const std::vector<uint8_t> &msg, double delay,
bool repeat);
~debug_msg_source_raw_impl ();
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_RAW_IMPL_H */

View File

@ -30,6 +30,7 @@
#include "satnogs/whitening.h"
#include "satnogs/udp_msg_sink.h"
#include "satnogs/coarse_doppler_correction_cc.h"
#include "satnogs/debug_msg_source_raw.h"
%}
@ -73,3 +74,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, upsat_fsk_frame_encoder);
GR_SWIG_BLOCK_MAGIC2(satnogs, udp_msg_sink);
%include "satnogs/coarse_doppler_correction_cc.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, coarse_doppler_correction_cc);
%include "satnogs/debug_msg_source_raw.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, debug_msg_source_raw);