Implement a shift register with dynamic size
std::bitset can be used only with compile time known size. Most of the flowgraphs take the shift register size as a parameter through the GRC so it cannot be used. This commit implements a shift register using the std::deque that supports arbitrary number of memory stages
This commit is contained in:
parent
1afb2bae18
commit
40aaeece1c
|
@ -72,5 +72,7 @@ install(FILES
|
|||
ccsds_rs_decoder_mm.h
|
||||
fox_telem_mm.h
|
||||
lrpt_sync.h
|
||||
lrpt_decoder.h DESTINATION include/satnogs
|
||||
lrpt_decoder.h
|
||||
frame_acquisition.h
|
||||
shift_reg.h DESTINATION include/satnogs
|
||||
)
|
|
@ -0,0 +1,61 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, 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_FRAME_ACQUISITION_H
|
||||
#define INCLUDED_SATNOGS_FRAME_ACQUISITION_H
|
||||
|
||||
#include <satnogs/api.h>
|
||||
#include <gnuradio/sync_block.h>
|
||||
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief <+description of block+>
|
||||
* \ingroup satnogs
|
||||
*
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
static sptr
|
||||
make (const std::vector<uint8_t>& preamble,
|
||||
size_t preamble_threshold,
|
||||
const std::vector<uint8_t>& sync,
|
||||
size_t sync_threshold);
|
||||
};
|
||||
|
||||
} // namespace satnogs
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_SATNOGS_FRAME_ACQUISITION_H */
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, 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_SHIFT_REG_H
|
||||
#define INCLUDED_SATNOGS_SHIFT_REG_H
|
||||
|
||||
#include <satnogs/api.h>
|
||||
#include <deque>
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Implements a bit shift register
|
||||
*
|
||||
*/
|
||||
class SATNOGS_API shift_reg
|
||||
{
|
||||
public:
|
||||
shift_reg (size_t len = 32);
|
||||
~shift_reg ();
|
||||
|
||||
void
|
||||
reset();
|
||||
|
||||
void
|
||||
set();
|
||||
|
||||
size_t
|
||||
len() const;
|
||||
|
||||
size_t
|
||||
size() const;
|
||||
|
||||
size_t
|
||||
count();
|
||||
|
||||
shift_reg
|
||||
operator|(const shift_reg& rhs);
|
||||
|
||||
shift_reg
|
||||
operator&(const shift_reg& rhs);
|
||||
|
||||
shift_reg
|
||||
operator^(const shift_reg& rhs);
|
||||
|
||||
shift_reg&
|
||||
operator>>=(bool bit);
|
||||
|
||||
bool&
|
||||
operator[](size_t pos);
|
||||
|
||||
bool
|
||||
operator[](size_t pos) const;
|
||||
|
||||
shift_reg&
|
||||
operator<<=(bool bit);
|
||||
|
||||
void
|
||||
push_front(bool bit);
|
||||
|
||||
void
|
||||
push_back(bool bit);
|
||||
|
||||
bool
|
||||
front();
|
||||
|
||||
bool
|
||||
back();
|
||||
|
||||
|
||||
private:
|
||||
const size_t d_len;
|
||||
std::deque<bool> d_reg;
|
||||
};
|
||||
|
||||
} // namespace satnogs
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_SATNOGS_SHIFT_REG_H */
|
||||
|
|
@ -71,7 +71,9 @@ list(APPEND satnogs_sources
|
|||
fox_telem_mm_impl.cc
|
||||
lrpt_sync_impl.cc
|
||||
convolutional_deinterleaver.cc
|
||||
lrpt_decoder_impl.cc)
|
||||
lrpt_decoder_impl.cc
|
||||
frame_acquisition_impl.cc
|
||||
shift_reg.cc)
|
||||
|
||||
if(${INCLUDE_DEBUG_BLOCKS})
|
||||
list(APPEND satnogs_sources ${satnogs_debug_sources})
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, 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 "frame_acquisition_impl.h"
|
||||
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
frame_acquisition::sptr
|
||||
frame_acquisition::make (const std::vector<uint8_t>& preamble,
|
||||
size_t preamble_threshold,
|
||||
const std::vector<uint8_t>& sync,
|
||||
size_t sync_threshold)
|
||||
{
|
||||
return gnuradio::get_initial_sptr (
|
||||
new frame_acquisition_impl (preamble, preamble_threshold, sync,
|
||||
sync_threshold));
|
||||
}
|
||||
|
||||
frame_acquisition_impl::frame_acquisition_impl (
|
||||
const std::vector<uint8_t>& preamble, size_t preamble_threshold,
|
||||
const std::vector<uint8_t>& sync, size_t sync_threshold) :
|
||||
gr::sync_block ("frame_acquisition",
|
||||
gr::io_signature::make (1, 1, sizeof(uint8_t)),
|
||||
gr::io_signature::make (0, 0, 0)),
|
||||
d_preamble(preamble.size() * 8),
|
||||
d_preamble_len(preamble.size() * 8),
|
||||
d_preamble_thrsh(preamble_threshold),
|
||||
d_sync(sync.size() * 8),
|
||||
d_sync_len(sync.size() * 8),
|
||||
d_sync_thrsh(sync_threshold)
|
||||
{
|
||||
set_output_multiple(8);
|
||||
for(uint8_t b : preamble) {
|
||||
d_preamble <<= (b >> 7);
|
||||
d_preamble <<= ((b >> 6) & 0x1);
|
||||
d_preamble <<= ((b >> 6) & 0x1);
|
||||
d_preamble <<= ((b >> 5) & 0x1);
|
||||
d_preamble <<= ((b >> 4) & 0x1);
|
||||
d_preamble <<= ((b >> 3) & 0x1);
|
||||
d_preamble <<= ((b >> 2) & 0x1);
|
||||
d_preamble <<= ((b >> 1) & 0x1);
|
||||
d_preamble <<= (b & 0x1);
|
||||
}
|
||||
for(uint8_t b : sync) {
|
||||
d_sync <<= (b >> 7);
|
||||
d_sync <<= ((b >> 6) & 0x1);
|
||||
d_sync <<= ((b >> 6) & 0x1);
|
||||
d_sync <<= ((b >> 5) & 0x1);
|
||||
d_sync <<= ((b >> 4) & 0x1);
|
||||
d_sync <<= ((b >> 3) & 0x1);
|
||||
d_sync <<= ((b >> 2) & 0x1);
|
||||
d_sync <<= ((b >> 1) & 0x1);
|
||||
d_sync <<= (b & 0x1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Our virtual destructor.
|
||||
*/
|
||||
frame_acquisition_impl::~frame_acquisition_impl ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
frame_acquisition_impl::work (int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const uint8_t *in = (const uint8_t *) input_items[0];
|
||||
|
||||
// Do <+signal processing+>
|
||||
|
||||
// Tell runtime system how many output items we produced.
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
} /* namespace satnogs */
|
||||
} /* namespace gr */
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, 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_FRAME_ACQUISITION_IMPL_H
|
||||
#define INCLUDED_SATNOGS_FRAME_ACQUISITION_IMPL_H
|
||||
|
||||
#include <satnogs/shift_reg.h>
|
||||
#include <satnogs/frame_acquisition.h>
|
||||
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
class frame_acquisition_impl : public frame_acquisition
|
||||
{
|
||||
|
||||
public:
|
||||
frame_acquisition_impl (const std::vector<uint8_t>& preamble,
|
||||
size_t preamble_threshold,
|
||||
const std::vector<uint8_t>& sync,
|
||||
size_t sync_threshold);
|
||||
~frame_acquisition_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);
|
||||
|
||||
private:
|
||||
shift_reg d_preamble;
|
||||
const size_t d_preamble_len;
|
||||
const size_t d_preamble_thrsh;
|
||||
shift_reg d_sync;
|
||||
const size_t d_sync_len;
|
||||
const size_t d_sync_thrsh;
|
||||
};
|
||||
|
||||
} // namespace satnogs
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_SATNOGS_FRAME_ACQUISITION_IMPL_H */
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, 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 <satnogs/shift_reg.h>
|
||||
|
||||
namespace gr {
|
||||
namespace satnogs {
|
||||
|
||||
/**
|
||||
* Creates a new shift register
|
||||
* @param len the number of the memory stages
|
||||
*/
|
||||
shift_reg::shift_reg (size_t len)
|
||||
: d_len(len),
|
||||
d_reg(len, 0)
|
||||
{
|
||||
if(len < 1) {
|
||||
throw std::invalid_argument("Shift register should contain at least one stage");
|
||||
}
|
||||
}
|
||||
|
||||
shift_reg::~shift_reg ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all the memory stages to 0
|
||||
*/
|
||||
void
|
||||
shift_reg::reset ()
|
||||
{
|
||||
for(size_t i = 0; i < d_len; i++) {
|
||||
d_reg[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all the memory stages to 1
|
||||
*/
|
||||
void
|
||||
shift_reg::set ()
|
||||
{
|
||||
for(size_t i = 0; i < d_len; i++) {
|
||||
d_reg[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the number of the memory stages of the shift register
|
||||
*/
|
||||
size_t
|
||||
shift_reg::len () const
|
||||
{
|
||||
return d_len;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the number of the memory stages of the shift register
|
||||
*/
|
||||
size_t
|
||||
shift_reg::size () const
|
||||
{
|
||||
return d_len;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the number of 1 bits
|
||||
*/
|
||||
size_t
|
||||
shift_reg::count ()
|
||||
{
|
||||
size_t cnt = 0;
|
||||
for(bool i : d_reg) {
|
||||
cnt += i;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
shift_reg
|
||||
shift_reg::operator | (const shift_reg& rhs)
|
||||
{
|
||||
shift_reg ret(d_len);
|
||||
for(size_t i = 0; i < d_len; i++) {
|
||||
ret[i] = d_reg[i] | rhs[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
shift_reg
|
||||
shift_reg::operator & (const shift_reg& rhs)
|
||||
{
|
||||
shift_reg ret(d_len);
|
||||
for(size_t i = 0; i < d_len; i++) {
|
||||
ret[i] = d_reg[i] & rhs[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
shift_reg
|
||||
shift_reg::operator ^ (const shift_reg& rhs)
|
||||
{
|
||||
shift_reg ret(d_len);
|
||||
for(size_t i = 0; i < d_len; i++) {
|
||||
ret[i] = d_reg[i] ^ rhs[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
shift_reg&
|
||||
shift_reg::operator >>= (bool bit)
|
||||
{
|
||||
push_front(bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool&
|
||||
shift_reg::operator [] (size_t pos)
|
||||
{
|
||||
return d_reg[pos];
|
||||
}
|
||||
|
||||
bool
|
||||
shift_reg::operator[](size_t pos) const
|
||||
{
|
||||
return d_reg[pos];
|
||||
}
|
||||
|
||||
shift_reg&
|
||||
shift_reg::operator <<= (bool bit)
|
||||
{
|
||||
push_back(bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push at the front a new value and pops from the back
|
||||
* @param bit the new value
|
||||
*/
|
||||
void
|
||||
shift_reg::push_front (bool bit)
|
||||
{
|
||||
d_reg.pop_back();
|
||||
d_reg.push_front(bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push at the back a new value and pops from the front
|
||||
* @param bit the new value
|
||||
*/
|
||||
void
|
||||
shift_reg::push_back (bool bit)
|
||||
{
|
||||
d_reg.pop_front();
|
||||
d_reg.push_back(bit);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the first element in the queue from right to left
|
||||
*/
|
||||
bool
|
||||
shift_reg::front ()
|
||||
{
|
||||
return d_reg.front();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the last element in the queue from right to left
|
||||
*/
|
||||
bool
|
||||
shift_reg::back ()
|
||||
{
|
||||
return d_reg.back();
|
||||
}
|
||||
|
||||
} /* namespace satnogs */
|
||||
} /* namespace gr */
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
#include "satnogs/fox_telem_mm.h"
|
||||
#include "satnogs/lrpt_decoder.h"
|
||||
#include "satnogs/lrpt_sync.h"
|
||||
#include "satnogs/frame_acquisition.h"
|
||||
%}
|
||||
|
||||
|
||||
|
@ -121,3 +122,6 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, lrpt_sync);
|
|||
|
||||
%include "satnogs/lrpt_decoder.h"
|
||||
GR_SWIG_BLOCK_MAGIC2(satnogs, lrpt_decoder);
|
||||
|
||||
%include "satnogs/frame_acquisition.h"
|
||||
GR_SWIG_BLOCK_MAGIC2(satnogs, frame_acquisition);
|
||||
|
|
Loading…
Reference in New Issue