Commit 1c30dfe1 authored by Manolis Surligas's avatar Manolis Surligas

Add AX.25 decoder with legacy support for the hardware radios

parent ddb6ce05
This diff is collapsed.
......@@ -23,7 +23,6 @@ install(FILES
satnogs_multi_format_msg_sink.xml
satnogs_cw_to_symbol.xml
satnogs_sine_matched_filter_ff.xml
satnogs_ax25_decoder_b.xml
satnogs_udp_msg_source.xml
satnogs_debug_msg_source.xml
satnogs_json_to_ecss_src.xml
......@@ -37,5 +36,6 @@ install(FILES
satnogs_upsat_transmitter.xml
satnogs_coarse_doppler_correction_cc.xml
satnogs_debug_msg_source_raw.xml
satnogs_ax25_encoder_mb.xml DESTINATION share/gnuradio/grc/blocks
satnogs_ax25_encoder_mb.xml
satnogs_ax25_decoder_bm.xml DESTINATION share/gnuradio/grc/blocks
)
<?xml version="1.0"?>
<block>
<name>AX.25 Decoder</name>
<key>satnogs_ax25_decoder_b</key>
<key>satnogs_ax25_decoder_bm</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.ax25_decoder_b($addr, $ssid, $promisc)</make>
<make>satnogs.ax25_decoder_bm($addr, $ssid, $promisc, $descrambling, $max_frame_len)</make>
<param>
<name>Receiver Callsign</name>
<key>addr</key>
<value>'GND'</value>
<type>string</type>
</param>
<param>
<name>Receiver SSID</name>
<key>ssid</key>
<value>0</value>
<type>int</type>
</param>
......@@ -33,6 +35,27 @@
</option>
</param>
<param>
<name>G3RUH descrambling</name>
<key>descrambling</key>
<type>enum</type>
<option>
<name>Yes</name>
<key>True</key>
</option>
<option>
<name>No</name>
<key>False</key>
</option>
</param>
<param>
<name>Maximum frame length</name>
<key>max_frame_len</key>
<value>256</value>
<type>int</type>
</param>
<sink>
<name>in</name>
<type>byte</type>
......@@ -42,4 +65,11 @@
<name>pdu</name>
<type>message</type>
</source>
<source>
<name>failed_pdu</name>
<type>message</type>
<optional>1</optional>
</source>
</block>
......@@ -34,7 +34,6 @@ install(FILES
cw_to_symbol.h
sine_matched_filter_ff.h
utils.h
ax25_decoder_b.h
udp_msg_source.h
debug_msg_source.h
json_to_ecss_src.h
......@@ -49,5 +48,6 @@ install(FILES
udp_msg_sink.h
coarse_doppler_correction_cc.h
debug_msg_source_raw.h
ax25_encoder_mb.h DESTINATION include/satnogs
ax25_encoder_mb.h
ax25_decoder_bm.h DESTINATION include/satnogs
)
......@@ -18,39 +18,72 @@
* 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
#ifndef INCLUDED_SATNOGS_AX25_DECODER_BM_H
#define INCLUDED_SATNOGS_AX25_DECODER_BM_H
#include <satnogs/api.h>
#include <gnuradio/sync_block.h>
namespace gr {
namespace satnogs {
namespace gr
{
namespace satnogs
{
/*!
* \brief AX.25 decoding block
* \brief AX.25 decoder that supports the legacy hardware radios.
*
* This block takes as input a quadrature demodulated bit stream.
* Each byte should contains only one bit of information at the LSB.
*
* The block will try to find an AX.25 frame. If the frame pass the
* CRC check then a blob PMT message is produced at the message output
* indicated with name 'out'. Otherwise if the frame did not pass the
* CRC check or the size was invalid, a blob PMT message is generated at
* the output port with the name 'fail'. This will help to recover at least
* some bytes from a corrupted message.
*
* The block also supports destination callsign check. Only frames with
* the right destination Callsign will be accepted. This feature can be
* disabled using the promisc parameter.
*
* \ingroup satnogs
*
*/
class SATNOGS_API ax25_decoder_b : virtual public gr::sync_block
class SATNOGS_API ax25_decoder_bm : virtual public gr::sync_block
{
public:
typedef boost::shared_ptr<ax25_decoder_b> sptr;
public:
typedef boost::shared_ptr<ax25_decoder_bm> sptr;
/**
* AX.25 decoder block.
* This block takes as input a quadrature demodulated bit stream.
* Each byte should contains only one bit of information at the LSB.
*
* The block will try to find an AX.25 frame. If the frame pass the
* CRC check then a blob PMT message is produced at the message output
* indicated with name 'pdu'. Otherwise if the frame did not pass the
* CRC check or the size was invalid, a blob PMT message is generated at
* the output port with the name 'failed_pdu'.
* This will help to recover at least some bytes from a corrupted message.
*
* The block also supports destination callsign check. Only frames with
* the right destination Callsign will be accepted. This feature can be
* disabled using the promisc parameter.
* @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.
* @param promisc if set to yes, the Callsign check is disabled
* @param descramble if set to yes, the data will be descrambled prior
* decoding using the G3RUH self-synchronizing descrambler.
* @param max_frame_len the maximum allowed frame length
* @return
*/
static sptr make(std::string addr, uint8_t ssid, bool promisc=true);
static sptr
make (const std::string& addr, uint8_t ssid, bool promisc = false,
bool descramble = true,
size_t max_frame_len = 512);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_AX25_DECODER_B_H */
#endif /* INCLUDED_SATNOGS_AX25_DECODER_BM_H */
......@@ -32,7 +32,6 @@ list(APPEND satnogs_sources
multi_format_msg_sink_impl.cc
cw_to_symbol_impl.cc
sine_matched_filter_ff_impl.cc
ax25_decoder_b_impl.cc
udp_msg_source_impl.cc
debug_msg_source_impl.cc
tcp_rigctl_msg_source_impl.cc
......@@ -47,7 +46,8 @@ list(APPEND satnogs_sources
udp_msg_sink_impl.cc
coarse_doppler_correction_cc_impl.cc
debug_msg_source_raw_impl.cc
ax25_encoder_mb_impl.cc )
ax25_encoder_mb_impl.cc
ax25_decoder_bm_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 "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 */
This diff is collapsed.
......@@ -18,23 +18,23 @@
* 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
#ifndef INCLUDED_SATNOGS_AX25_DECODER_BM_IMPL_H
#define INCLUDED_SATNOGS_AX25_DECODER_BM_IMPL_H
#include <satnogs/ax25_decoder_b.h>
#include <satnogs/ax25.h>
#include <satnogs/ax25_decoder_bm.h>
#include <gnuradio/digital/lfsr.h>
namespace gr
{
namespace satnogs
{
class ax25_decoder_b_impl : public ax25_decoder_b
class ax25_decoder_bm_impl : public ax25_decoder_bm
{
private:
typedef enum {
NO_SYNC,
IN_SYNC
typedef enum
{
NO_SYNC, IN_SYNC, FRAME_END
} decoding_state_t;
/**
......@@ -42,22 +42,32 @@ namespace gr
* forwards all successfully decoded frames
*/
const bool d_promisc;
const bool d_descramble;
const size_t d_max_frame_len;
decoding_state_t d_state;
uint8_t d_dec_b;
uint8_t d_prev_bit;
uint8_t d_prev_bit_nrzi;
size_t d_received_bytes;
size_t d_decoded_bits;
size_t d_cont_1;
digital::lfsr d_lfsr;
uint8_t *d_frame_buffer;
void reset_state();
void enter_sync_state();
void update_recv_frame(uint8_t byte);
void
reset_state ();
void
enter_sync_state ();
void
enter_frame_end ();
void
descramble_and_decode (const uint8_t *in, size_t nitems);
void
decode (const uint8_t *in, size_t nitems);
public:
ax25_decoder_b_impl (std::string addr, uint8_t ssid, bool promisc);
~ax25_decoder_b_impl ();
ax25_decoder_bm_impl (const std::string& addr, uint8_t ssid, bool promisc,
bool descramble, size_t max_frame_len);
~ax25_decoder_bm_impl ();
// Where all the action really happens
int
......@@ -68,5 +78,5 @@ namespace gr
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_AX25_DECODER_B_IMPL_H */
#endif /* INCLUDED_SATNOGS_AX25_DECODER_BM_IMPL_H */
......@@ -45,8 +45,10 @@ namespace gr
digital::lfsr d_lfsr;
boost::mutex d_mutex;
void add_sob(uint64_t item);
void add_eob(uint64_t item);
void
add_sob (uint64_t item);
void
add_eob (uint64_t item);
public:
ax25_encoder_mb_impl (const std::string& dest_addr, uint8_t dest_ssid,
......
......@@ -16,7 +16,6 @@
#include "satnogs/multi_format_msg_sink.h"
#include "satnogs/cw_to_symbol.h"
#include "satnogs/sine_matched_filter_ff.h"
#include "satnogs/ax25_decoder_b.h"
#include "satnogs/udp_msg_source.h"
#include "satnogs/debug_msg_source.h"
#include "satnogs/tcp_rigctl_msg_source.h"
......@@ -30,6 +29,7 @@
#include "satnogs/coarse_doppler_correction_cc.h"
#include "satnogs/debug_msg_source_raw.h"
#include "satnogs/ax25_encoder_mb.h"
#include "satnogs/ax25_decoder_bm.h"
%}
......@@ -48,8 +48,6 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, cw_to_symbol);
%include "satnogs/sine_matched_filter_ff.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, sine_matched_filter_ff);
%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"
......@@ -75,3 +73,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, coarse_doppler_correction_cc);
GR_SWIG_BLOCK_MAGIC2(satnogs, debug_msg_source_raw);
%include "satnogs/ax25_encoder_mb.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, ax25_encoder_mb);
%include "satnogs/ax25_decoder_bm.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, ax25_decoder_bm);
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