Commit 4bcd9c8a authored by Manolis Surligas's avatar Manolis Surligas

Start the implementation of a generic frame synchronizer

The generic frame synchronizer will be able to adapt in a variety of
common framing schemes used by popular modems.
parent 2122b531
image: debian:latest
before_script:
- apt-get update -qq && apt-get install -y -qq gnuradio-dev libcppunit-dev libpng++-dev libvorbis-dev libnova-dev cmake swig pkg-config build-essential
- apt-get update -qq && apt-get install -y -qq gnuradio-dev libcppunit-dev libpng++-dev libvorbis-dev cmake swig pkg-config build-essential git
test:
script:
......
......@@ -51,6 +51,7 @@ list(APPEND enabled_blocks
satnogs_quad_demod_filter_ff.xml
satnogs_ogg_source.xml
satnogs_noaa_apt_sink.xml
satnogs_whitening.xml
)
if(${INCLUDE_DEBUG_BLOCKS})
......
......@@ -41,4 +41,5 @@
<block>satnogs_quad_demod_filter_ff</block>
<block>satnogs_ccsds_rs_decoder_mm</block>
<block>satnogs_decoder_8b10b</block>
<block>variable_whitening</block>
</cat>
\ No newline at end of file
<?xml version="1.0"?>
<block>
<name>Whitening</name>
<key>variable_whitening</key>
<import>import satnogs</import>
<var_make>self.$(id) = $(id) = satnogs.whitening_make($mask, $seed, $order)</var_make>
<var_value>satnogs.whitening_make($mask, $seed, $order)</var_value>
<make></make>
<param>
<name>Ignore Me</name>
<key>value</key>
<value>'ok'</value>
<type>raw</type>
<hide>all</hide>
</param>
<param>
<name>Mask</name>
<key>mask</key>
<type>int</type>
</param>
<param>
<name>Seed</name>
<key>seed</key>
<type>int</type>
</param>
<param>
<name>Order</name>
<key>order</key>
<type>int</type>
</param>
</block>
......@@ -22,6 +22,7 @@
#define INCLUDED_SATNOGS_FRAME_ACQUISITION_H
#include <satnogs/api.h>
#include <satnogs/whitening.h>
#include <gnuradio/sync_block.h>
namespace gr
......@@ -39,19 +40,42 @@ class SATNOGS_API frame_acquisition : virtual public gr::sync_block
public:
typedef boost::shared_ptr<frame_acquisition> sptr;
/*!
* \brief Return a shared_ptr to a new instance of satnogs::frame_acquisition.
*
* To avoid accidental use of raw pointers, satnogs::frame_acquisition's
* constructor is in a private implementation
* class. satnogs::frame_acquisition::make is the public interface for
* creating new instances.
*/
typedef enum {
CRC_NONE = 0,
CRC16,
CRC32
} checksum_t;
static sptr
make_generic_var_len (const std::vector<uint8_t>& preamble,
size_t preamble_threshold,
const std::vector<uint8_t>& sync,
size_t sync_threshold,
size_t frame_size_len = 1,
checksum_t crc = CRC_NONE,
whitening::sptr descrambler = nullptr,
size_t max_frame_len = 2048);
static sptr
make (const std::vector<uint8_t>& preamble,
size_t preamble_threshold,
const std::vector<uint8_t>& sync,
size_t sync_threshold);
make_generic_const_len(const std::vector<uint8_t>& preamble,
size_t preamble_threshold,
const std::vector<uint8_t>& sync,
size_t sync_threshold,
size_t frame_len = 1,
checksum_t crc = CRC_NONE,
whitening::sptr descrambler = nullptr,
size_t max_frame_len = 2048);
static sptr
make_golay24_var_len (const std::vector<uint8_t>& preamble,
size_t preamble_threshold,
const std::vector<uint8_t>& sync,
size_t sync_threshold,
checksum_t crc = CRC_NONE,
whitening::sptr descrambler = nullptr,
size_t max_frame_len = 2048);
};
} // namespace satnogs
......
......@@ -23,41 +23,52 @@
#include <satnogs/api.h>
#include <gnuradio/digital/lfsr.h>
#include <boost/shared_ptr.hpp>
namespace gr
{
namespace satnogs
{
namespace satnogs
{
/*!
* \brief Performs data whitening and de-whitening
*
*/
class SATNOGS_API whitening
{
public:
static int base_unique_id;
int
unique_id ();
typedef boost::shared_ptr<whitening> sptr;
static sptr
make(uint32_t mask, uint32_t seed, uint32_t order);
/*!
* \brief Performs data whitening and de-whitening
*
*/
class SATNOGS_API whitening
{
public:
whitening (uint32_t mask, uint32_t seed, uint32_t order);
whitening (uint32_t mask, uint32_t seed, uint32_t order);
void
reset();
void
reset ();
void scramble(uint8_t *out, const uint8_t *in, size_t len,
bool msb = false);
void descramble(uint8_t *out, const uint8_t *in, size_t len,
bool msb = false);
void
scramble (uint8_t *out, const uint8_t *in, size_t len, bool msb = false);
void
descramble (uint8_t *out, const uint8_t *in, size_t len, bool msb = false);
void
scramble_one_bit_per_byte (uint8_t *out, const uint8_t *in,
size_t bits_num);
void
descramble_one_bit_per_byte (uint8_t *out, const uint8_t *in,
size_t bits_num);
void
scramble_one_bit_per_byte (uint8_t *out, const uint8_t *in, size_t bits_num);
void
descramble_one_bit_per_byte (uint8_t *out, const uint8_t *in,
size_t bits_num);
private:
digital::lfsr d_lfsr;
};
private:
digital::lfsr d_lfsr;
int d_id;
};
} // namespace satnogs
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_WHITENING_H */
......
This diff is collapsed.
......@@ -33,10 +33,23 @@ class frame_acquisition_impl : public frame_acquisition
{
public:
frame_acquisition_impl (const std::vector<uint8_t>& preamble,
typedef enum {
GENERIC_VAR_FRAME_LEN = 0,
GENERIC_CONSTANT_FRAME_LEN,
GOLAY24_CODED_FRAME_LEN
} variant_t;
frame_acquisition_impl (variant_t variant,
const std::vector<uint8_t>& preamble,
size_t preamble_threshold,
const std::vector<uint8_t>& sync,
size_t sync_threshold);
size_t sync_threshold,
size_t frame_size_len,
size_t frame_len,
checksum_t crc,
whitening::sptr descrambler,
size_t max_frame_len);
~frame_acquisition_impl ();
// Where all the action really happens
......@@ -45,12 +58,53 @@ public:
gr_vector_void_star &output_items);
private:
/**
* Decoding FSM
*/
typedef enum
{
SEARCHING, //!< when searching for the start of the preamble
SEARCHING_SYNC,
DECODING_GENERIC_FRAME_LEN,
DECODING_GOLAY24_FRAME_LEN,
DECODING_PAYLOAD
} decoding_state_t;
const variant_t d_variant;
shift_reg d_preamble;
shift_reg d_preamble_shift_reg;
const size_t d_preamble_len;
const size_t d_preamble_thrsh;
shift_reg d_sync;
shift_reg d_sync_shift_reg;
const size_t d_sync_len;
const size_t d_sync_thrsh;
decoding_state_t d_state;
uint32_t d_cnt;
const uint32_t d_frame_size_field_len;
uint32_t d_frame_len;
const uint32_t d_max_frame_len;
const checksum_t d_crc;
whitening::sptr d_whitening;
uint8_t *d_pdu;
int
searching_preamble(const uint8_t *in, int len);
int
searching_sync(const uint8_t *in, int len);
int dec_generic_frame_len(const uint8_t *in, int len);
int dec_golay24_frame_len(const uint8_t *in, int len);
int
decoding(const uint8_t *in, int len);
void
reset();
};
} // namespace satnogs
......
......@@ -31,6 +31,23 @@ namespace gr
namespace satnogs
{
int whitening::base_unique_id = 1;
/**
* Data whitening and de-whitening class
* @param mask the polynomial mask
* @param seed the initial seed
* @param order the order of the shift register. This is equal to the
* number of memory stages.
*/
whitening::sptr
whitening::make (uint32_t mask, uint32_t seed, uint32_t order)
{
return whitening::sptr(new whitening(mask, seed, order));
}
/**
* Data whitening and de-whitening class
* @param mask the polynomial mask
......@@ -39,8 +56,16 @@ namespace satnogs
* number of memory stages.
*/
whitening::whitening (uint32_t mask, uint32_t seed, uint32_t order) :
d_lfsr (mask, seed, order)
d_lfsr (mask, seed, order),
d_id(0)
{
d_id = base_unique_id++;
}
int
whitening::unique_id ()
{
return d_id;
}
/**
......
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