From 0e0a3e0c082d8f3bd22f20720db642fcc6568507 Mon Sep 17 00:00:00 2001 From: Manolis Surligas Date: Tue, 8 Mar 2016 23:19:17 +0200 Subject: [PATCH] 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. --- examples/ax25_example.grc | 269 +++++++++++++++++++++++------ grc/CMakeLists.txt | 5 +- grc/satnogs_ax25_decoder_b.xml | 45 +++++ grc/satnogs_debug_msg_source.xml | 41 +++++ grc/satnogs_udp_msg_source.xml | 34 ++++ include/satnogs/CMakeLists.txt | 5 +- include/satnogs/ax25.h | 6 +- include/satnogs/ax25_decoder_b.h | 56 ++++++ include/satnogs/debug_msg_source.h | 58 +++++++ include/satnogs/udp_msg_source.h | 60 +++++++ lib/CMakeLists.txt | 5 +- lib/ax25_decoder_b_impl.cc | 189 ++++++++++++++++++++ lib/ax25_decoder_b_impl.h | 72 ++++++++ lib/ax25_encoder_bf_impl.cc | 8 +- lib/ax25_encoder_bf_impl.h | 6 +- lib/debug_msg_source_impl.cc | 91 ++++++++++ lib/debug_msg_source_impl.h | 55 ++++++ lib/udp_msg_source_impl.cc | 133 ++++++++++++++ lib/udp_msg_source_impl.h | 53 ++++++ swig/satnogs_swig.i | 9 + 20 files changed, 1137 insertions(+), 63 deletions(-) create mode 100644 grc/satnogs_ax25_decoder_b.xml create mode 100644 grc/satnogs_debug_msg_source.xml create mode 100644 grc/satnogs_udp_msg_source.xml create mode 100644 include/satnogs/ax25_decoder_b.h create mode 100644 include/satnogs/debug_msg_source.h create mode 100644 include/satnogs/udp_msg_source.h create mode 100644 lib/ax25_decoder_b_impl.cc create mode 100644 lib/ax25_decoder_b_impl.h create mode 100644 lib/debug_msg_source_impl.cc create mode 100644 lib/debug_msg_source_impl.h create mode 100644 lib/udp_msg_source_impl.cc create mode 100644 lib/udp_msg_source_impl.h diff --git a/examples/ax25_example.grc b/examples/ax25_example.grc index 03eab84..8f02fa3 100644 --- a/examples/ax25_example.grc +++ b/examples/ax25_example.grc @@ -136,38 +136,7 @@ - blocks_message_debug - - alias - - - - comment - - - - affinity - - - - _enabled - 0 - - - _coordinate - (664, 224) - - - _rotation - 0 - - - id - blocks_message_debug_0 - - - - blocks_message_strobe + digital_binary_slicer_fb alias @@ -186,7 +155,7 @@ _coordinate - (120, 397) + (752, 512) _rotation @@ -194,24 +163,16 @@ id - blocks_message_strobe_0 + digital_binary_slicer_fb_0 maxoutbuf 0 - - msg - 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]) - minoutbuf 0 - - period - 100 - qtgui_time_sink_x @@ -245,7 +206,7 @@ _coordinate - (856, 390) + (608, 382) gui_hint @@ -553,7 +514,7 @@ update_time - 0.10 + 0.02 ylabel @@ -572,6 +533,57 @@ -1 + + satnogs_ax25_decoder_b + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (600, 702) + + + _rotation + 0 + + + id + satnogs_ax25_decoder_b_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + promisc + True + + + addr + ABCD + + + ssid + 0 + + satnogs_ax25_encoder_bf @@ -600,7 +612,7 @@ _coordinate - (536, 479) + (328, 487) _rotation @@ -627,17 +639,156 @@ 0 + + satnogs_clear_text_msg_sink + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (856, 720) + + + _rotation + 0 + + + id + satnogs_clear_text_msg_sink_0 + + + + satnogs_debug_msg_source + + alias + + + + comment + + + + affinity + + + + delay + 1 + + + _enabled + True + + + _coordinate + (88, 686) + + + _rotation + 0 + + + id + satnogs_debug_msg_source_0 + + + maxoutbuf + 0 + + + msg + "HELLO EARTH WORLD FROM SPACE" + + + minoutbuf + 0 + + + repeat + True + + + + satnogs_udp_msg_source + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (64, 430) + + + _rotation + 0 + + + id + satnogs_udp_msg_source_0 + + + addr + "127.0.0.1" + + + mtu + 1500 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + port + 16886 + + - blocks_message_strobe_0 - blocks_message_debug_0 - strobe - print + digital_binary_slicer_fb_0 + satnogs_ax25_decoder_b_0 + 0 + 0 - blocks_message_strobe_0 - satnogs_ax25_encoder_bf_0 - strobe - info + satnogs_ax25_decoder_b_0 + satnogs_clear_text_msg_sink_0 + pdu + in + + + satnogs_ax25_encoder_bf_0 + digital_binary_slicer_fb_0 + 0 + 0 satnogs_ax25_encoder_bf_0 @@ -645,4 +796,16 @@ 0 0 + + satnogs_debug_msg_source_0 + satnogs_ax25_encoder_bf_0 + msg + info + + + satnogs_udp_msg_source_0 + satnogs_ax25_encoder_bf_0 + msg + info + diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index db23e47..2f59ac8 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -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 ) diff --git a/grc/satnogs_ax25_decoder_b.xml b/grc/satnogs_ax25_decoder_b.xml new file mode 100644 index 0000000..55417d2 --- /dev/null +++ b/grc/satnogs_ax25_decoder_b.xml @@ -0,0 +1,45 @@ + + + AX.25 Decoder + satnogs_ax25_decoder_b + satnogs + import satnogs + satnogs.ax25_decoder_b($addr, $ssid, $promisc) + + + Receiver Callsign + addr + string + + + + Receiver SSID + ssid + int + + + + + Promiscuous mode + promisc + enum + + + + + + in + byte + + + + pdu + message + + diff --git a/grc/satnogs_debug_msg_source.xml b/grc/satnogs_debug_msg_source.xml new file mode 100644 index 0000000..7b706e0 --- /dev/null +++ b/grc/satnogs_debug_msg_source.xml @@ -0,0 +1,41 @@ + + + Debug Message Source + satnogs_debug_msg_source + satnogs + import satnogs + satnogs.debug_msg_source($msg, $delay, $repeat) + + + Message + msg + "HELLO WORLD" + string + + + + Delay (seconds) + delay + 0.01 + real + + + + Repeat + repeat + enum + + + + + + msg + message + + diff --git a/grc/satnogs_udp_msg_source.xml b/grc/satnogs_udp_msg_source.xml new file mode 100644 index 0000000..4bb3db8 --- /dev/null +++ b/grc/satnogs_udp_msg_source.xml @@ -0,0 +1,34 @@ + + + UDP Message Source + satnogs_udp_msg_source + satnogs + import satnogs + satnogs.udp_msg_source($addr, $port, $mtu) + + + IP Address + addr + "127.0.0.1" + string + + + + UDP port + port + 16886 + int + + + + MTU + mtu + 1500 + int + + + + msg + message + + diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt index cf5ddf8..2cd05aa 100644 --- a/include/satnogs/CMakeLists.txt +++ b/include/satnogs/CMakeLists.txt @@ -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 ) diff --git a/include/satnogs/ax25.h b/include/satnogs/ax25.h index bd95c96..5d46fc2 100644 --- a/include/satnogs/ax25.h +++ b/include/satnogs/ax25.h @@ -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++){ diff --git a/include/satnogs/ax25_decoder_b.h b/include/satnogs/ax25_decoder_b.h new file mode 100644 index 0000000..a7d8ad8 --- /dev/null +++ b/include/satnogs/ax25_decoder_b.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifndef INCLUDED_SATNOGS_AX25_DECODER_B_H +#define INCLUDED_SATNOGS_AX25_DECODER_B_H + +#include +#include + +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 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 */ + diff --git a/include/satnogs/debug_msg_source.h b/include/satnogs/debug_msg_source.h new file mode 100644 index 0000000..1a0312e --- /dev/null +++ b/include/satnogs/debug_msg_source.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifndef INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_H +#define INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_H + +#include +#include + +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 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 */ + diff --git a/include/satnogs/udp_msg_source.h b/include/satnogs/udp_msg_source.h new file mode 100644 index 0000000..75003a0 --- /dev/null +++ b/include/satnogs/udp_msg_source.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifndef INCLUDED_SATNOGS_UDP_MSG_SOURCE_H +#define INCLUDED_SATNOGS_UDP_MSG_SOURCE_H + +#include +#include + +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 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 */ + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d3f3448..483c87f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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) diff --git a/lib/ax25_decoder_b_impl.cc b/lib/ax25_decoder_b_impl.cc new file mode 100644 index 0000000..fc2dd0d --- /dev/null +++ b/lib/ax25_decoder_b_impl.cc @@ -0,0 +1,189 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "ax25_decoder_b_impl.h" +#include + +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 */ + diff --git a/lib/ax25_decoder_b_impl.h b/lib/ax25_decoder_b_impl.h new file mode 100644 index 0000000..602d6f1 --- /dev/null +++ b/lib/ax25_decoder_b_impl.h @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifndef INCLUDED_SATNOGS_AX25_DECODER_B_IMPL_H +#define INCLUDED_SATNOGS_AX25_DECODER_B_IMPL_H + +#include +#include + +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 */ + diff --git a/lib/ax25_encoder_bf_impl.cc b/lib/ax25_encoder_bf_impl.cc index 6e93d9a..c2d967f 100644 --- a/lib/ax25_encoder_bf_impl.cc +++ b/lib/ax25_encoder_bf_impl.cc @@ -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 diff --git a/lib/ax25_encoder_bf_impl.h b/lib/ax25_encoder_bf_impl.h index 87eca07..d4020b4 100644 --- a/lib/ax25_encoder_bf_impl.h +++ b/lib/ax25_encoder_bf_impl.h @@ -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; diff --git a/lib/debug_msg_source_impl.cc b/lib/debug_msg_source_impl.cc new file mode 100644 index 0000000..48f3acc --- /dev/null +++ b/lib/debug_msg_source_impl.cc @@ -0,0 +1,91 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "debug_msg_source_impl.h" +#include + +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 ( + 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 */ + diff --git a/lib/debug_msg_source_impl.h b/lib/debug_msg_source_impl.h new file mode 100644 index 0000000..2e270d8 --- /dev/null +++ b/lib/debug_msg_source_impl.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifndef INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_IMPL_H +#define INCLUDED_SATNOGS_DEBUG_MSG_SOURCE_IMPL_H + +#include +#include + +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 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 */ + diff --git a/lib/udp_msg_source_impl.cc b/lib/udp_msg_source_impl.cc new file mode 100644 index 0000000..237e126 --- /dev/null +++ b/lib/udp_msg_source_impl.cc @@ -0,0 +1,133 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "udp_msg_source_impl.h" +#include +#include +#include +#include +#include +#include +#include +#include + + +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 ( + 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 */ + diff --git a/lib/udp_msg_source_impl.h b/lib/udp_msg_source_impl.h new file mode 100644 index 0000000..36736f5 --- /dev/null +++ b/lib/udp_msg_source_impl.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * 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 . + */ + +#ifndef INCLUDED_SATNOGS_UDP_MSG_SOURCE_IMPL_H +#define INCLUDED_SATNOGS_UDP_MSG_SOURCE_IMPL_H + +#include +#include + +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 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 */ + diff --git a/swig/satnogs_swig.i b/swig/satnogs_swig.i index e99431f..4e878ea 100644 --- a/swig/satnogs_swig.i +++ b/swig/satnogs_swig.i @@ -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);