Finish the AX.25 decoder and add a UDP message source block

The AX.25 decoder is now decoding the received frames.
Also, the module now provides a UDP message source block. This block
will be responsible to receive UDP packets and transform them into PMT
messages for further processing in the GNU Radio flowgraph. As the
communication with the satnogs-client will be done in the same host, we
do not have to care about packet loss.

Furthermore, the module now provides and a debug message  source block
for easy debugging.
This commit is contained in:
Manolis Surligas 2016-03-08 23:19:17 +02:00
parent 75289e11d5
commit 0e0a3e0c08
20 changed files with 1137 additions and 63 deletions

View File

@ -136,38 +136,7 @@
</param>
</block>
<block>
<key>blocks_message_debug</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>0</value>
</param>
<param>
<key>_coordinate</key>
<value>(664, 224)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>blocks_message_debug_0</value>
</param>
</block>
<block>
<key>blocks_message_strobe</key>
<key>digital_binary_slicer_fb</key>
<param>
<key>alias</key>
<value></value>
@ -186,7 +155,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(120, 397)</value>
<value>(752, 512)</value>
</param>
<param>
<key>_rotation</key>
@ -194,24 +163,16 @@
</param>
<param>
<key>id</key>
<value>blocks_message_strobe_0</value>
<value>digital_binary_slicer_fb_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>msg</key>
<value>pmt.init_u8vector(30, [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,8, 9])</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>period</key>
<value>100</value>
</param>
</block>
<block>
<key>qtgui_time_sink_x</key>
@ -245,7 +206,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(856, 390)</value>
<value>(608, 382)</value>
</param>
<param>
<key>gui_hint</key>
@ -553,7 +514,7 @@
</param>
<param>
<key>update_time</key>
<value>0.10</value>
<value>0.02</value>
</param>
<param>
<key>ylabel</key>
@ -572,6 +533,57 @@
<value>-1</value>
</param>
</block>
<block>
<key>satnogs_ax25_decoder_b</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(600, 702)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>satnogs_ax25_decoder_b_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>promisc</key>
<value>True</value>
</param>
<param>
<key>addr</key>
<value>ABCD</value>
</param>
<param>
<key>ssid</key>
<value>0</value>
</param>
</block>
<block>
<key>satnogs_ax25_encoder_bf</key>
<param>
@ -600,7 +612,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(536, 479)</value>
<value>(328, 487)</value>
</param>
<param>
<key>_rotation</key>
@ -627,17 +639,156 @@
<value>0</value>
</param>
</block>
<block>
<key>satnogs_clear_text_msg_sink</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>1</value>
</param>
<param>
<key>_coordinate</key>
<value>(856, 720)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>satnogs_clear_text_msg_sink_0</value>
</param>
</block>
<block>
<key>satnogs_debug_msg_source</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>delay</key>
<value>1</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(88, 686)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>satnogs_debug_msg_source_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>msg</key>
<value>"HELLO EARTH WORLD FROM SPACE"</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>repeat</key>
<value>True</value>
</param>
</block>
<block>
<key>satnogs_udp_msg_source</key>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(64, 430)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>satnogs_udp_msg_source_0</value>
</param>
<param>
<key>addr</key>
<value>"127.0.0.1"</value>
</param>
<param>
<key>mtu</key>
<value>1500</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>port</key>
<value>16886</value>
</param>
</block>
<connection>
<source_block_id>blocks_message_strobe_0</source_block_id>
<sink_block_id>blocks_message_debug_0</sink_block_id>
<source_key>strobe</source_key>
<sink_key>print</sink_key>
<source_block_id>digital_binary_slicer_fb_0</source_block_id>
<sink_block_id>satnogs_ax25_decoder_b_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>blocks_message_strobe_0</source_block_id>
<sink_block_id>satnogs_ax25_encoder_bf_0</sink_block_id>
<source_key>strobe</source_key>
<sink_key>info</sink_key>
<source_block_id>satnogs_ax25_decoder_b_0</source_block_id>
<sink_block_id>satnogs_clear_text_msg_sink_0</sink_block_id>
<source_key>pdu</source_key>
<sink_key>in</sink_key>
</connection>
<connection>
<source_block_id>satnogs_ax25_encoder_bf_0</source_block_id>
<sink_block_id>digital_binary_slicer_fb_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>satnogs_ax25_encoder_bf_0</source_block_id>
@ -645,4 +796,16 @@
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>satnogs_debug_msg_source_0</source_block_id>
<sink_block_id>satnogs_ax25_encoder_bf_0</sink_block_id>
<source_key>msg</source_key>
<sink_key>info</sink_key>
</connection>
<connection>
<source_block_id>satnogs_udp_msg_source_0</source_block_id>
<sink_block_id>satnogs_ax25_encoder_bf_0</sink_block_id>
<source_key>msg</source_key>
<sink_key>info</sink_key>
</connection>
</flow_graph>

View File

@ -24,5 +24,8 @@ install(FILES
satnogs_cw_to_symbol.xml
satnogs_afsk_decoder.xml
satnogs_sine_matched_filter_ff.xml
satnogs_ax25_encoder_bf.xml DESTINATION share/gnuradio/grc/blocks
satnogs_ax25_encoder_bf.xml
satnogs_ax25_decoder_b.xml
satnogs_udp_msg_source.xml
satnogs_debug_msg_source.xml DESTINATION share/gnuradio/grc/blocks
)

View File

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<block>
<name>AX.25 Decoder</name>
<key>satnogs_ax25_decoder_b</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.ax25_decoder_b($addr, $ssid, $promisc)</make>
<param>
<name>Receiver Callsign</name>
<key>addr</key>
<type>string</type>
</param>
<param>
<name>Receiver SSID</name>
<key>ssid</key>
<type>int</type>
</param>
<param>
<name>Promiscuous mode</name>
<key>promisc</key>
<type>enum</type>
<option>
<name>No</name>
<key>False</key>
</option>
<option>
<name>Yes</name>
<key>True</key>
</option>
</param>
<sink>
<name>in</name>
<type>byte</type>
</sink>
<source>
<name>pdu</name>
<type>message</type>
</source>
</block>

View File

@ -0,0 +1,41 @@
<?xml version="1.0"?>
<block>
<name>Debug Message Source</name>
<key>satnogs_debug_msg_source</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.debug_msg_source($msg, $delay, $repeat)</make>
<param>
<name>Message</name>
<key>msg</key>
<value>"HELLO WORLD"</value>
<type>string</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

@ -0,0 +1,34 @@
<?xml version="1.0"?>
<block>
<name>UDP Message Source</name>
<key>satnogs_udp_msg_source</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.udp_msg_source($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>
<source>
<name>msg</name>
<type>message</type>
</source>
</block>

View File

@ -35,5 +35,8 @@ install(FILES
afsk_decoder.h
sine_matched_filter_ff.h
utils.h
ax25_encoder_bf.h DESTINATION include/satnogs
ax25_encoder_bf.h
ax25_decoder_b.h
udp_msg_source.h
debug_msg_source.h DESTINATION include/satnogs
)

View File

@ -157,11 +157,10 @@ namespace gr
* inserted
*/
if(type == AX25_I_FRAME){
out[i] = 0xF0;
i++;
out[i++] = 0xF0;
}
memcpy(out + i, info, info_len);
i =+ info_len;
i += info_len;
/* Compute the FCS. Ignore the first flag byte */
fcs = ax25_fcs(out + 1, i - 1);
@ -188,6 +187,7 @@ namespace gr
/* Leading FLAG field does not need bit stuffing */
memcpy(out, AX25_SYNC_FLAG_MAP, 8 * sizeof(float));
out_idx = 8;
/* Skip the leading and trailing FLAG field */
buffer++;
for(i = 0; i < 8 * (buffer_len - 2); i++){

View File

@ -0,0 +1,56 @@
/* -*- 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_AX25_DECODER_B_H
#define INCLUDED_SATNOGS_AX25_DECODER_B_H
#include <satnogs/api.h>
#include <gnuradio/sync_block.h>
namespace gr {
namespace satnogs {
/*!
* \brief AX.25 decoding block
* \ingroup satnogs
*
*/
class SATNOGS_API ax25_decoder_b : virtual public gr::sync_block
{
public:
typedef boost::shared_ptr<ax25_decoder_b> sptr;
/**
* AX.25 decoder block.
*
* @param addr the Callsign of the receiver
* @param ssid the SSID of the receiver
* @param promisc if set to true, all the successfully decoded frames
* are forwarded. Otherwise, only those that have as destination address
* and SSID specified by the addr and ssid parameters respectively.
*/
static sptr make(std::string addr, uint8_t ssid, bool promisc=true);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_AX25_DECODER_B_H */

View File

@ -0,0 +1,58 @@
/* -*- 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_H
#define INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_H
#include <satnogs/api.h>
#include <gnuradio/block.h>
namespace gr
{
namespace satnogs
{
/*!
* \brief A block for debug reasons producing specific messages
* \ingroup satnogs
*
*/
class SATNOGS_API debug_msg_source : virtual public gr::block
{
public:
typedef boost::shared_ptr<debug_msg_source> 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
* @return
*/
static sptr
make (const std::string &msg, double delay, bool repeat = true);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_H */

View File

@ -0,0 +1,60 @@
/* -*- 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_SOURCE_H
#define INCLUDED_SATNOGS_UDP_MSG_SOURCE_H
#include <satnogs/api.h>
#include <gnuradio/block.h>
namespace gr
{
namespace satnogs
{
/*!
* \brief UDP message/command accepter.
*
* This block received UDP messages from localhost or other network hosts
* and produces PMT messages.
*
* \ingroup satnogs
*
*/
class SATNOGS_API udp_msg_source : virtual public gr::block
{
public:
typedef boost::shared_ptr<udp_msg_source> sptr;
/**
* Creates a UDP message accepter block
* @param addr the address to bind the UDP socket
* @param port the UDP port to wait for packets
* @param mtu the maximum MTU. Used to pre-allocate a maximum packet size
*/
static sptr
make (const std::string& addr, uint16_t port, size_t mtu = 1500);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_UDP_MSG_SOURCE_H */

View File

@ -33,7 +33,10 @@ list(APPEND satnogs_sources
cw_to_symbol_impl.cc
afsk_decoder_impl.cc
sine_matched_filter_ff_impl.cc
ax25_encoder_bf_impl.cc )
ax25_encoder_bf_impl.cc
ax25_decoder_b_impl.cc
udp_msg_source_impl.cc
debug_msg_source_impl.cc )
set(satnogs_sources "${satnogs_sources}" PARENT_SCOPE)
if(NOT satnogs_sources)

189
lib/ax25_decoder_b_impl.cc Normal file
View File

@ -0,0 +1,189 @@
/* -*- 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 "ax25_decoder_b_impl.h"
#include <satnogs/log.h>
namespace gr {
namespace satnogs {
ax25_decoder_b::sptr
ax25_decoder_b::make(std::string addr, uint8_t ssid, bool promisc)
{
return gnuradio::get_initial_sptr
(new ax25_decoder_b_impl(addr, ssid, promisc));
}
/*
* The private constructor
*/
ax25_decoder_b_impl::ax25_decoder_b_impl (std::string addr, uint8_t ssid,
bool promisc) :
gr::sync_block ("ax25_decoder_b",
gr::io_signature::make (1, 1, sizeof(uint8_t)),
gr::io_signature::make (0, 0, 0)),
d_promisc(promisc),
d_state(NO_SYNC),
d_dec_b(0),
d_prev_bit(0),
d_received_bytes(0),
d_decoded_bits(0),
d_cont_1(0),
d_frame_buffer(new uint8_t[AX25_MAX_FRAME_LEN
+ AX25_MAX_ADDR_LEN
+ AX25_MAX_CTRL_LEN
+ sizeof(uint16_t)])
{
message_port_register_out (pmt::mp ("pdu"));
}
void
ax25_decoder_b_impl::reset_state ()
{
d_state = NO_SYNC;
d_dec_b = 0;
d_decoded_bits = 0;
d_received_bytes = 0;
d_cont_1 = 0;
}
void
ax25_decoder_b_impl::enter_sync_state ()
{
d_state = IN_SYNC;
d_dec_b = 0;
d_decoded_bits = 0;
d_received_bytes = 0;
d_prev_bit = 0;
d_cont_1 = 0;
}
void
ax25_decoder_b_impl::update_recv_frame (uint8_t byte)
{
uint16_t fcs;
uint16_t recv_fcs = 0x0;
if( d_decoded_bits ) {
return;
}
if(byte == AX25_SYNC_FLAG) {
/* First check if the size of the frame is valid */
if(d_received_bytes < AX25_MIN_ADDR_LEN + sizeof(uint16_t)){
reset_state();
return;
}
/* Check if the frame is correct using the FCS field */
fcs = ax25_fcs (d_frame_buffer, d_received_bytes - sizeof(uint16_t));
recv_fcs = (((uint16_t) d_frame_buffer[d_received_bytes - 2]) << 8)
| d_frame_buffer[d_received_bytes - 1];
if( fcs == recv_fcs ) {
message_port_pub (
pmt::mp ("pdu"),
pmt::make_blob (d_frame_buffer,
d_received_bytes - sizeof(uint16_t)));
}
else {
LOG_WARN("Wrong FCS: Should be 0%x, computed as 0%x", recv_fcs, fcs);
}
LOG_WARN("Frame size %lu", d_received_bytes);
reset_state();
}
else{
d_frame_buffer[d_received_bytes++] = byte;
if(d_received_bytes > AX25_MAX_FRAME_LEN){
LOG_WARN("Maximum frame size reached. Abort decoding this frame");
reset_state();
}
}
d_dec_b = 0;
}
/*
* Our virtual destructor.
*/
ax25_decoder_b_impl::~ax25_decoder_b_impl()
{
delete[] d_frame_buffer;
}
int
ax25_decoder_b_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
int i;
const uint8_t *in = (const uint8_t *) input_items[0];
for (i = 0; i < noutput_items; i++) {
switch (d_state)
{
case NO_SYNC:
d_dec_b = (d_dec_b << 1) | in[i];
/*
* If the decoder find the sync flag of the AX.25 frame start the
* decoding process
*/
if(d_dec_b == AX25_SYNC_FLAG){
enter_sync_state();
}
break;
case IN_SYNC:
if(in[i]){
if(d_prev_bit) {
d_cont_1++;
}
else {
d_cont_1 = 1;
}
d_dec_b |= 1 << d_decoded_bits;
d_decoded_bits = (d_decoded_bits + 1) % 8;
update_recv_frame(d_dec_b);
d_prev_bit = 1;
}
else{
/* Check if this a stuffed zero bit */
if(d_cont_1 < 5) {
d_decoded_bits = (d_decoded_bits + 1) % 8;
update_recv_frame(d_dec_b);
}
d_prev_bit = 0;
d_cont_1 = 0;
}
break;
default:
LOG_ERROR("Invalid decoding state");
}
}
return noutput_items;
}
} /* namespace satnogs */
} /* namespace gr */

72
lib/ax25_decoder_b_impl.h Normal file
View File

@ -0,0 +1,72 @@
/* -*- 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_AX25_DECODER_B_IMPL_H
#define INCLUDED_SATNOGS_AX25_DECODER_B_IMPL_H
#include <satnogs/ax25_decoder_b.h>
#include <satnogs/ax25.h>
namespace gr
{
namespace satnogs
{
class ax25_decoder_b_impl : public ax25_decoder_b
{
private:
typedef enum {
NO_SYNC,
IN_SYNC
} decoding_state_t;
/**
* If this flag is set, the decoder operates in promiscuous mode and
* forwards all successfully decoded frames
*/
const bool d_promisc;
decoding_state_t d_state;
uint8_t d_dec_b;
uint8_t d_prev_bit;
size_t d_received_bytes;
size_t d_decoded_bits;
size_t d_cont_1;
uint8_t *d_frame_buffer;
void reset_state();
void enter_sync_state();
void update_recv_frame(uint8_t byte);
public:
ax25_decoder_b_impl (std::string addr, uint8_t ssid, bool promisc);
~ax25_decoder_b_impl ();
// Where all the action really happens
int
work (int noutput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_AX25_DECODER_B_IMPL_H */

View File

@ -55,7 +55,10 @@ namespace gr
gr::io_signature::make (1, 1, sizeof(float))),
d_type (type),
d_remaining (0),
d_produced(0)
d_produced(0),
d_endoded_frame(new float[(AX25_MAX_FRAME_LEN * 2)]),
d_tmp_buf(new uint8_t[AX25_MAX_FRAME_LEN * 2]),
d_addr_field(new uint8_t[AX25_MAX_ADDR_LEN])
{
/* Input is a key-value pair containing the info field data */
message_port_register_in (pmt::mp ("info"));
@ -68,6 +71,9 @@ namespace gr
*/
ax25_encoder_bf_impl::~ax25_encoder_bf_impl ()
{
delete[] d_endoded_frame;
delete[] d_tmp_buf;
delete[] d_addr_field;
}
int

View File

@ -34,9 +34,9 @@ namespace gr {
size_t d_remaining;
size_t d_produced;
/* Twice the maximum frame length is enough to hold all possible input data*/
float d_endoded_frame[(AX25_MAX_FRAME_LEN * 2)];
uint8_t d_tmp_buf[AX25_MAX_FRAME_LEN * 2];
uint8_t d_addr_field[AX25_MAX_ADDR_LEN];
float *d_endoded_frame;
uint8_t *d_tmp_buf;
uint8_t *d_addr_field;
size_t d_addr_len;
boost::mutex d_mutex;

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_impl.h"
#include <boost/chrono.hpp>
namespace gr
{
namespace satnogs
{
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));
}
/*
* 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)));
}
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) {
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_impl::~debug_msg_source_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_IMPL_H
#define INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_IMPL_H
#include <satnogs/debug_msg_source.h>
#include <boost/thread.hpp>
namespace gr
{
namespace satnogs
{
class debug_msg_source_impl : public debug_msg_source
{
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_impl (const std::string &msg, double delay, bool repeat);
~debug_msg_source_impl ();
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_IMPL_H */

133
lib/udp_msg_source_impl.cc Normal file
View File

@ -0,0 +1,133 @@
/* -*- 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_source_impl.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
{
udp_msg_source::sptr
udp_msg_source::make (const std::string& addr, uint16_t port, size_t mtu)
{
return gnuradio::get_initial_sptr (
new udp_msg_source_impl (addr, port, mtu));
}
/*
* The private constructor
*/
udp_msg_source_impl::udp_msg_source_impl (const std::string& addr,
uint16_t port,
size_t mtu) :
gr::block ("udp_msg_source",
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),
d_running (true)
{
message_port_register_out(pmt::mp("msg"));
boost::shared_ptr<boost::thread> (
new boost::thread (
boost::bind (&udp_msg_source_impl::udp_msg_accepter, this)));
}
void
udp_msg_source_impl::udp_msg_accepter ()
{
int sock;
struct sockaddr_in sin;
struct sockaddr client_addr;
socklen_t client_addr_len;
ssize_t ret;
uint8_t *buf;
if ((sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
perror ("opening UDP socket");
exit (EXIT_FAILURE);
}
memset (&client_addr, 0, sizeof(struct sockaddr));
memset (&sin, 0, sizeof(struct sockaddr_in));
sin.sin_family = AF_INET;
sin.sin_port = htons (d_udp_port);
if( inet_aton(d_iface_addr.c_str(), &(sin.sin_addr)) == 0){
LOG_ERROR("Wrong IP address");
close(sock);
exit (EXIT_FAILURE);
}
if (bind (sock, (struct sockaddr *) &sin, sizeof(struct sockaddr_in))
== -1) {
perror ("UDP bind");
close(sock);
exit (EXIT_FAILURE);
}
/* All good until now. Allocate buffer memory and proceed */
buf = new uint8_t(d_mtu);
while(d_running){
ret = recvfrom(sock, buf, d_mtu, 0, &client_addr, &client_addr_len);
if(ret > 0) {
message_port_pub(pmt::mp("msg"), pmt::make_blob(buf, ret));
}
else{
perror("UDP recvfrom");
close(sock);
delete buf;
exit(EXIT_FAILURE);
}
}
close(sock);
delete buf;
exit (EXIT_SUCCESS);
}
/*
* Our virtual destructor.
*/
udp_msg_source_impl::~udp_msg_source_impl ()
{
d_running = false;
d_thread->join ();
}
} /* namespace satnogs */
} /* namespace gr */

53
lib/udp_msg_source_impl.h Normal file
View File

@ -0,0 +1,53 @@
/* -*- 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_SOURCE_IMPL_H
#define INCLUDED_SATNOGS_UDP_MSG_SOURCE_IMPL_H
#include <satnogs/udp_msg_source.h>
#include <boost/thread.hpp>
namespace gr
{
namespace satnogs
{
class udp_msg_source_impl : public udp_msg_source
{
private:
const std::string d_iface_addr;
const uint16_t d_udp_port;
const size_t d_mtu;
bool d_running;
boost::shared_ptr<boost::thread> d_thread;
void
udp_msg_accepter ();
public:
udp_msg_source_impl (const std::string& addr, uint16_t port, size_t mtu);
~udp_msg_source_impl ();
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_UDP_MSG_SOURCE_IMPL_H */

View File

@ -18,6 +18,9 @@
#include "satnogs/afsk_decoder.h"
#include "satnogs/sine_matched_filter_ff.h"
#include "satnogs/ax25_encoder_bf.h"
#include "satnogs/ax25_decoder_b.h"
#include "satnogs/udp_msg_source.h"
#include "satnogs/debug_msg_source.h"
%}
@ -38,3 +41,9 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, afsk_decoder);
GR_SWIG_BLOCK_MAGIC2(satnogs, sine_matched_filter_ff);
%include "satnogs/ax25_encoder_bf.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, ax25_encoder_bf);
%include "satnogs/ax25_decoder_b.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, ax25_decoder_b);
%include "satnogs/udp_msg_source.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, udp_msg_source);
%include "satnogs/debug_msg_source.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, debug_msg_source);