Commit 652c257b authored by Manolis Surligas's avatar Manolis Surligas

Add UDP PMT message sink block

parent 382e5a61
......@@ -34,5 +34,6 @@ install(FILES
satnogs_doppler_correction_cc.xml
satnogs_upsat_fsk_frame_acquisition.xml
satnogs_upsat_fsk_frame_encoder.xml
satnogs_whitening.xml DESTINATION share/gnuradio/grc/blocks
satnogs_whitening.xml
satnogs_udp_msg_sink.xml DESTINATION share/gnuradio/grc/blocks
)
<?xml version="1.0"?>
<block>
<name>UDP Message Sink</name>
<key>satnogs_udp_msg_sink</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.udp_msg_sink($addr, $port, $mtu)</make>
<param>
<name>IP Address</name>
<key>addr</key>
<value>"127.0.0.1"</value>
<type>string</type>
</param>
<param>
<name>UDP port</name>
<key>port</key>
<value>16886</value>
<type>int</type>
</param>
<param>
<name>MTU</name>
<key>mtu</key>
<value>1500</value>
<type>int</type>
</param>
<sink>
<name>in</name>
<type>message</type>
</sink>
</block>
......@@ -47,5 +47,6 @@ install(FILES
freq_drift.h
upsat_fsk_frame_acquisition.h
upsat_fsk_frame_encoder.h
whitening.h DESTINATION include/satnogs
whitening.h
udp_msg_sink.h DESTINATION include/satnogs
)
/* -*- 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_UDP_MSG_SINK_H
#define INCLUDED_SATNOGS_UDP_MSG_SINK_H
#include <satnogs/api.h>
#include <gnuradio/block.h>
namespace gr {
namespace satnogs {
/*!
* \brief <+description of block+>
* \ingroup satnogs
*
*/
class SATNOGS_API udp_msg_sink : virtual public gr::block
{
public:
typedef boost::shared_ptr<udp_msg_sink> sptr;
/**
* UDP sink that accepts PMT messages
* @param addr the address of the destination host
* @param port the destination UDP port
* @param mtu the maximum MTU
*/
static sptr make(const std::string& addr, uint16_t port, size_t mtu);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_UDP_MSG_SINK_H */
......@@ -45,7 +45,8 @@ list(APPEND satnogs_sources
freq_drift.cc
upsat_fsk_frame_acquisition_impl.cc
upsat_fsk_frame_encoder_impl.cc
whitening.cc )
whitening.cc
udp_msg_sink_impl.cc )
set(satnogs_sources "${satnogs_sources}" PARENT_SCOPE)
if(NOT satnogs_sources)
......
/* -*- 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 "udp_msg_sink_impl.h"
#include <satnogs/log.h>
namespace gr {
namespace satnogs {
udp_msg_sink::sptr
udp_msg_sink::make(const std::string& addr, uint16_t port, size_t mtu)
{
return gnuradio::get_initial_sptr
(new udp_msg_sink_impl(addr, port, mtu));
}
/*
* The private constructor
*/
udp_msg_sink_impl::udp_msg_sink_impl (const std::string& addr,
uint16_t port, size_t mtu) :
gr::block ("udp_msg_sink",
gr::io_signature::make (0, 0, 0),
gr::io_signature::make (0, 0, 0)),
d_iface_addr(addr),
d_udp_port(port),
d_mtu(mtu)
{
message_port_register_in(pmt::mp("in"));
set_msg_handler(pmt::mp("in"),
boost::bind(&udp_msg_sink_impl::msg_handler,
this, _1));
/* Open the socket */
if ((d_sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
perror ("opening UDP socket");
throw std::runtime_error("Could not open UDP socket");
}
memset (&d_sin, 0, sizeof(struct sockaddr_in));
d_sin.sin_family = AF_INET;
d_sin.sin_port = htons (d_udp_port);
if( inet_aton(d_iface_addr.c_str(), &(d_sin.sin_addr)) == 0){
LOG_ERROR("Wrong IP address");
close(d_sock);
throw std::runtime_error("Wrong IP address");
}
}
void
udp_msg_sink_impl::msg_handler (pmt::pmt_t msg)
{
const void *buf = pmt::blob_data(msg);
size_t len = pmt::blob_length(msg);
if(len < d_mtu){
sendto(d_sock, buf, len, 0, (sockaddr *) &d_sin, sizeof(sockaddr_in));
}
}
/*
* Our virtual destructor.
*/
udp_msg_sink_impl::~udp_msg_sink_impl()
{
close(d_sock);
}
} /* namespace satnogs */
} /* namespace gr */
/* -*- 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_UDP_MSG_SINK_IMPL_H
#define INCLUDED_SATNOGS_UDP_MSG_SINK_IMPL_H
#include <satnogs/udp_msg_sink.h>
#include <satnogs/log.h>
#include <ifaddrs.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
namespace gr
{
namespace satnogs
{
class udp_msg_sink_impl : public udp_msg_sink
{
private:
const std::string d_iface_addr;
const uint16_t d_udp_port;
const size_t d_mtu;
int d_sock;
struct sockaddr_in d_sin;
void msg_handler(pmt::pmt_t msg);
public:
udp_msg_sink_impl (const std::string& addr, uint16_t port, size_t mtu);
~udp_msg_sink_impl ();
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_UDP_MSG_SINK_IMPL_H */
......@@ -28,6 +28,7 @@
#include "satnogs/upsat_fsk_frame_acquisition.h"
#include "satnogs/upsat_fsk_frame_encoder.h"
#include "satnogs/whitening.h"
#include "satnogs/udp_msg_sink.h"
%}
......@@ -67,3 +68,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, upsat_fsk_frame_acquisition);
%include "satnogs/upsat_fsk_frame_encoder.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, upsat_fsk_frame_encoder);
%include "satnogs/whitening.h"
%include "satnogs/udp_msg_sink.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, udp_msg_sink);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment