added block for measuring round trip times.
This commit is contained in:
committed by
Bastian Bloessl
parent
757efde68a
commit
13471bef84
@@ -22,6 +22,7 @@ install(FILES
|
|||||||
foo_packet_dropper.xml
|
foo_packet_dropper.xml
|
||||||
foo_packet_pad.xml
|
foo_packet_pad.xml
|
||||||
foo_periodic_msg_source.xml
|
foo_periodic_msg_source.xml
|
||||||
|
foo_rtt_measure.xml
|
||||||
foo_wireshark_connector.xml
|
foo_wireshark_connector.xml
|
||||||
DESTINATION share/gnuradio/grc/blocks
|
DESTINATION share/gnuradio/grc/blocks
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<block>
|
||||||
|
<name>RTT measure</name>
|
||||||
|
<key>foo_rtt_measure</key>
|
||||||
|
<category>Foo</category>
|
||||||
|
<import>import foo</import>
|
||||||
|
<make>foo.rtt_measure($interval)</make>
|
||||||
|
|
||||||
|
<param>
|
||||||
|
<name>Send interval</name>
|
||||||
|
<key>interval</key>
|
||||||
|
<value>500</value>
|
||||||
|
<type>int</type>
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<sink>
|
||||||
|
<name>in</name>
|
||||||
|
<type>message</type>
|
||||||
|
</sink>
|
||||||
|
|
||||||
|
<source>
|
||||||
|
<name>dout</name>
|
||||||
|
<type>byte</type>
|
||||||
|
</source>
|
||||||
|
|
||||||
|
<source>
|
||||||
|
<name>out</name>
|
||||||
|
<type>message</type>
|
||||||
|
</source>
|
||||||
|
</block>
|
||||||
@@ -27,5 +27,6 @@ install(FILES
|
|||||||
packet_pad.h
|
packet_pad.h
|
||||||
periodic_msg_source.h
|
periodic_msg_source.h
|
||||||
wireshark_connector.h
|
wireshark_connector.h
|
||||||
|
rtt_measure.h
|
||||||
DESTINATION include/foo
|
DESTINATION include/foo
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Christoph Leitner <c.leitner@student.uibk.ac.at>
|
||||||
|
*
|
||||||
|
* 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_FOO_RTT_MEASURE_H
|
||||||
|
#define INCLUDED_FOO_RTT_MEASURE_H
|
||||||
|
|
||||||
|
#include <foo/api.h>
|
||||||
|
#include <gnuradio/block.h>
|
||||||
|
|
||||||
|
namespace gr {
|
||||||
|
namespace foo {
|
||||||
|
|
||||||
|
class FOO_API rtt_measure : virtual public gr::block
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef boost::shared_ptr<rtt_measure> sptr;
|
||||||
|
static sptr make(unsigned long interval);
|
||||||
|
};
|
||||||
|
} // namespace foo
|
||||||
|
} // namespace gr
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -31,6 +31,7 @@ list(APPEND foo_sources
|
|||||||
packet_pad_impl.cc
|
packet_pad_impl.cc
|
||||||
periodic_msg_source_impl.cc
|
periodic_msg_source_impl.cc
|
||||||
wireshark_connector_impl.cc
|
wireshark_connector_impl.cc
|
||||||
|
rtt_measure_impl.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(gnuradio-foo SHARED ${foo_sources})
|
add_library(gnuradio-foo SHARED ${foo_sources})
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Christoph Leitner <c.leitner@student.uibk.ac.at>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rtt_measure_impl.h"
|
||||||
|
#include <gnuradio/io_signature.h>
|
||||||
|
|
||||||
|
using namespace gr::foo;
|
||||||
|
|
||||||
|
rtt_measure_impl::rtt_measure_impl(unsigned long interval)
|
||||||
|
: block("rtt_measure",
|
||||||
|
gr::io_signature::make(0, 0, 0),
|
||||||
|
gr::io_signature::make(1, 1, sizeof(uint8_t))),
|
||||||
|
d_interval(interval), d_thread(&rtt_measure_impl::run, this),
|
||||||
|
d_stop(false)
|
||||||
|
{
|
||||||
|
message_port_register_in(pmt::mp("in"));
|
||||||
|
message_port_register_out(pmt::mp("out"));
|
||||||
|
}
|
||||||
|
|
||||||
|
rtt_measure_impl::~rtt_measure_impl() {
|
||||||
|
d_stop.store(true);
|
||||||
|
d_thread.interrupt(); //if thread was sleeping
|
||||||
|
d_thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rtt_measure_impl::run()
|
||||||
|
{
|
||||||
|
// flow graph startup delay
|
||||||
|
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
|
||||||
|
std::string text("fnord");
|
||||||
|
pmt::pmt_t msg = pmt::make_blob(text.data(), text.length());
|
||||||
|
while(!d_stop.load()){
|
||||||
|
gr::thread::scoped_lock lock(d_mutex);
|
||||||
|
message_port_pub(pmt::mp("out"), pmt::cons(pmt::PMT_NIL, msg));
|
||||||
|
d_start_time = boost::posix_time::microsec_clock::local_time();
|
||||||
|
lock.unlock();
|
||||||
|
boost::this_thread::sleep(boost::posix_time::milliseconds(d_interval));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rtt_measure_impl::general_work(int noutput, gr_vector_int& ninput_items,
|
||||||
|
gr_vector_const_void_star& input_items,
|
||||||
|
gr_vector_void_star& output_items )
|
||||||
|
{
|
||||||
|
gr_complex *out = (gr_complex*)output_items[0];
|
||||||
|
|
||||||
|
pmt::pmt_t msg(delete_head_nowait(pmt::mp("in")));
|
||||||
|
if(!msg.get()){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
boost::posix_time::time_duration dur =
|
||||||
|
boost::posix_time::microsec_clock::local_time() - start_time();
|
||||||
|
std::string time_string(std::to_string(dur.total_microseconds()) + "\n");
|
||||||
|
std::cout << time_string;
|
||||||
|
|
||||||
|
if(pmt::is_eof_object(msg)) {
|
||||||
|
return -1;
|
||||||
|
} else if(!pmt::is_pair(msg)) {
|
||||||
|
throw std::invalid_argument("only PDU messages allowed");
|
||||||
|
}
|
||||||
|
int to_copy = time_string.length();
|
||||||
|
std::memcpy(out, time_string.data(), to_copy);
|
||||||
|
|
||||||
|
return to_copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::posix_time::ptime
|
||||||
|
rtt_measure_impl::start_time()
|
||||||
|
{
|
||||||
|
gr::thread::scoped_lock(d_mutex);
|
||||||
|
return d_start_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtt_measure::sptr
|
||||||
|
rtt_measure::make(unsigned long interval)
|
||||||
|
{
|
||||||
|
return gnuradio::get_initial_sptr(new rtt_measure_impl(interval));
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Christoph Leitner <c.leitner@student.uibk.ac.at>
|
||||||
|
*
|
||||||
|
* 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_FOO_RTT_MEASURE_IMPL_H
|
||||||
|
#define INCLUDED_FOO_RTT_MEASURE_IMPL_H
|
||||||
|
|
||||||
|
#include <foo/rtt_measure.h>
|
||||||
|
#include <atomic>
|
||||||
|
namespace gr {
|
||||||
|
namespace foo {
|
||||||
|
class rtt_measure_impl : public rtt_measure {
|
||||||
|
private:
|
||||||
|
unsigned long d_interval;
|
||||||
|
std::atomic_bool d_stop;
|
||||||
|
boost::posix_time::ptime d_start_time;
|
||||||
|
gr::thread::mutex d_mutex;
|
||||||
|
gr::thread::thread d_thread;
|
||||||
|
gr::thread::condition_variable d_msg_received;
|
||||||
|
public:
|
||||||
|
rtt_measure_impl(unsigned long interval);
|
||||||
|
~rtt_measure_impl();
|
||||||
|
void run();
|
||||||
|
int general_work(int noutput, gr_vector_int& ninput_items,
|
||||||
|
gr_vector_const_void_star& input_items,
|
||||||
|
gr_vector_void_star& output_items );
|
||||||
|
boost::posix_time::ptime start_time();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "foo/packet_pad.h"
|
#include "foo/packet_pad.h"
|
||||||
#include "foo/periodic_msg_source.h"
|
#include "foo/periodic_msg_source.h"
|
||||||
#include "foo/wireshark_connector.h"
|
#include "foo/wireshark_connector.h"
|
||||||
|
#include "foo/rtt_measure.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
%include "foo/packet_pad.h"
|
%include "foo/packet_pad.h"
|
||||||
%include "foo/periodic_msg_source.h"
|
%include "foo/periodic_msg_source.h"
|
||||||
%include "foo/wireshark_connector.h"
|
%include "foo/wireshark_connector.h"
|
||||||
|
%include "foo/rtt_measure.h"
|
||||||
|
|
||||||
|
|
||||||
GR_SWIG_BLOCK_MAGIC2(foo, burst_tagger);
|
GR_SWIG_BLOCK_MAGIC2(foo, burst_tagger);
|
||||||
@@ -26,3 +28,4 @@ GR_SWIG_BLOCK_MAGIC2(foo, packet_dropper);
|
|||||||
GR_SWIG_BLOCK_MAGIC2(foo, packet_pad);
|
GR_SWIG_BLOCK_MAGIC2(foo, packet_pad);
|
||||||
GR_SWIG_BLOCK_MAGIC2(foo, periodic_msg_source);
|
GR_SWIG_BLOCK_MAGIC2(foo, periodic_msg_source);
|
||||||
GR_SWIG_BLOCK_MAGIC2(foo, wireshark_connector);
|
GR_SWIG_BLOCK_MAGIC2(foo, wireshark_connector);
|
||||||
|
GR_SWIG_BLOCK_MAGIC2(foo, rtt_measure);
|
||||||
|
|||||||
Reference in New Issue
Block a user