diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt
index c90b792..a1ee1cb 100644
--- a/include/satnogs/CMakeLists.txt
+++ b/include/satnogs/CMakeLists.txt
@@ -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
)
\ No newline at end of file
diff --git a/include/satnogs/frame_acquisition.h b/include/satnogs/frame_acquisition.h
new file mode 100644
index 0000000..c1c7368
--- /dev/null
+++ b/include/satnogs/frame_acquisition.h
@@ -0,0 +1,61 @@
+/* -*- c++ -*- */
+/*
+ * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
+ *
+ * Copyright (C) 2018, 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_FRAME_ACQUISITION_H
+#define INCLUDED_SATNOGS_FRAME_ACQUISITION_H
+
+#include
+#include
+
+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 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& preamble,
+ size_t preamble_threshold,
+ const std::vector& sync,
+ size_t sync_threshold);
+};
+
+} // namespace satnogs
+} // namespace gr
+
+#endif /* INCLUDED_SATNOGS_FRAME_ACQUISITION_H */
+
diff --git a/include/satnogs/shift_reg.h b/include/satnogs/shift_reg.h
new file mode 100644
index 0000000..b301d43
--- /dev/null
+++ b/include/satnogs/shift_reg.h
@@ -0,0 +1,99 @@
+/* -*- c++ -*- */
+/*
+ * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
+ *
+ * Copyright (C) 2018, 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_SHIFT_REG_H
+#define INCLUDED_SATNOGS_SHIFT_REG_H
+
+#include
+#include
+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 d_reg;
+};
+
+} // namespace satnogs
+} // namespace gr
+
+#endif /* INCLUDED_SATNOGS_SHIFT_REG_H */
+
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index cbbe6c9..3a574a3 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -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})
diff --git a/lib/frame_acquisition_impl.cc b/lib/frame_acquisition_impl.cc
new file mode 100644
index 0000000..10d3505
--- /dev/null
+++ b/lib/frame_acquisition_impl.cc
@@ -0,0 +1,106 @@
+/* -*- c++ -*- */
+/*
+ * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
+ *
+ * Copyright (C) 2018, 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 "frame_acquisition_impl.h"
+
+namespace gr
+{
+namespace satnogs
+{
+
+frame_acquisition::sptr
+frame_acquisition::make (const std::vector& preamble,
+ size_t preamble_threshold,
+ const std::vector& 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& preamble, size_t preamble_threshold,
+ const std::vector& 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 */
+
diff --git a/lib/frame_acquisition_impl.h b/lib/frame_acquisition_impl.h
new file mode 100644
index 0000000..afe1f71
--- /dev/null
+++ b/lib/frame_acquisition_impl.h
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
+ *
+ * Copyright (C) 2018, 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_FRAME_ACQUISITION_IMPL_H
+#define INCLUDED_SATNOGS_FRAME_ACQUISITION_IMPL_H
+
+#include
+#include
+
+namespace gr
+{
+namespace satnogs
+{
+
+class frame_acquisition_impl : public frame_acquisition
+{
+
+public:
+ frame_acquisition_impl (const std::vector& preamble,
+ size_t preamble_threshold,
+ const std::vector& 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 */
+
diff --git a/lib/shift_reg.cc b/lib/shift_reg.cc
new file mode 100644
index 0000000..4bd4683
--- /dev/null
+++ b/lib/shift_reg.cc
@@ -0,0 +1,204 @@
+/* -*- c++ -*- */
+/*
+ * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
+ *
+ * Copyright (C) 2018, 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
+
+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 */
+
diff --git a/swig/satnogs_swig0.i b/swig/satnogs_swig0.i
index c0b417b..dca6a2a 100644
--- a/swig/satnogs_swig0.i
+++ b/swig/satnogs_swig0.i
@@ -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);