diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt
index 122b647..1991aa8 100644
--- a/grc/CMakeLists.txt
+++ b/grc/CMakeLists.txt
@@ -52,5 +52,6 @@ if(${INCLUDE_DEBUG_BLOCKS})
endif()
install(FILES
${enabled_blocks}
- satnogs_quad_demod_filter_ff.xml DESTINATION share/gnuradio/grc/blocks
+ satnogs_quad_demod_filter_ff.xml
+ satnogs_decoder_8b10b.xml DESTINATION share/gnuradio/grc/blocks
)
diff --git a/grc/satnogs_decoder_8b10b.xml b/grc/satnogs_decoder_8b10b.xml
new file mode 100644
index 0000000..3432851
--- /dev/null
+++ b/grc/satnogs_decoder_8b10b.xml
@@ -0,0 +1,48 @@
+
+
+ 8b10b Decoder
+ satnogs_decoder_8b10b
+ [SatNOGS]
+ import satnogs
+ satnogs.decoder_8b10b($control_symbol, $max_frame_len,
+ $comp_type)
+
+
+ Control symbols
+ control_symbol
+ 0011111010
+ string
+
+
+
+ Maximum frame length
+ max_frame_len
+ 1500
+ int
+
+
+
+ Comparison type
+ comp_type
+ enum
+
+
+
+
+
+ in
+ byte
+
+
+
+ pdu
+ message
+
+
+
diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt
index ea2a968..d66a61a 100644
--- a/include/satnogs/CMakeLists.txt
+++ b/include/satnogs/CMakeLists.txt
@@ -67,5 +67,6 @@ endif()
install(FILES
${HEADER_FILES}
- quad_demod_filter_ff.h DESTINATION include/satnogs
+ quad_demod_filter_ff.h
+ decoder_8b10b.h DESTINATION include/satnogs
)
\ No newline at end of file
diff --git a/include/satnogs/decoder_8b10b.h b/include/satnogs/decoder_8b10b.h
new file mode 100644
index 0000000..cc53b64
--- /dev/null
+++ b/include/satnogs/decoder_8b10b.h
@@ -0,0 +1,58 @@
+/* -*- 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_DECODER_8B10B_H
+#define INCLUDED_SATNOGS_DECODER_8B10B_H
+
+#include
+#include
+
+namespace gr
+{
+ namespace satnogs
+ {
+
+ /*!
+ * \brief <+description of block+>
+ * \ingroup satnogs
+ *
+ */
+ class SATNOGS_API decoder_8b10b : virtual public gr::sync_block
+ {
+ public:
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Return a shared_ptr to a new instance of satnogs::decoder_8b10b.
+ *
+ * To avoid accidental use of raw pointers, satnogs::decoder_8b10b's
+ * constructor is in a private implementation
+ * class. satnogs::decoder_8b10b::make is the public interface for
+ * creating new instances.
+ */
+ static sptr make(const std::string& control_symbol,size_t max_frame_len,int comp_type);
+ };
+
+}
+ // namespace satnogs
+}// namespace gr
+
+#endif /* INCLUDED_SATNOGS_DECODER_8B10B_H */
+
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 5fd37e5..99857af 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -65,7 +65,8 @@ list(APPEND satnogs_sources
noaa_apt_sink_impl.cc
frame_file_sink_impl.cc
iq_sink_impl.cc
- quad_demod_filter_ff_impl.cc)
+ quad_demod_filter_ff_impl.cc
+ decoder_8b10b_impl.cc)
if(${INCLUDE_DEBUG_BLOCKS})
list(APPEND satnogs_sources ${satnogs_debug_sources})
diff --git a/lib/decoder_8b10b_impl.cc b/lib/decoder_8b10b_impl.cc
new file mode 100644
index 0000000..77b023b
--- /dev/null
+++ b/lib/decoder_8b10b_impl.cc
@@ -0,0 +1,119 @@
+/* -*- 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 "decoder_8b10b_impl.h"
+#include
+
+namespace gr
+{
+ namespace satnogs
+ {
+
+ decoder_8b10b::sptr
+ decoder_8b10b::make (const std::string& control_symbol,
+ size_t max_frame_len, int comp_type)
+ {
+ return gnuradio::get_initial_sptr (
+ new decoder_8b10b_impl (control_symbol, max_frame_len, comp_type));
+ }
+
+ /*
+ * The private constructor
+ */
+ decoder_8b10b_impl::decoder_8b10b_impl (const std::string& control_symbol,
+ size_t max_frame_len, int comp_type) :
+ gr::sync_block ("decoder_8b10b",
+ gr::io_signature::make (1, 1, sizeof(char)),
+ gr::io_signature::make (0, 0, 0)),
+ d_max_frame_len (max_frame_len),
+ d_comp_type (comp_type),
+ d_control_symbol_pos (0),
+ d_control_symbol_neg (0),
+ d_data_reg (0)
+ {
+ message_port_register_out (pmt::mp ("pdu"));
+ if (!set_access_code (control_symbol)) {
+ GR_LOG_ERROR(d_logger, "control_symbol is not 10 bits");
+ throw std::out_of_range ("control_symbol is not 10 bits");
+ }
+ }
+
+ /*
+ * Our virtual destructor.
+ */
+ decoder_8b10b_impl::~decoder_8b10b_impl ()
+ {
+ }
+
+ bool
+ decoder_8b10b_impl::set_access_code (const std::string &control_symbol)
+ {
+ unsigned len = control_symbol.length (); // # of bytes in string
+
+ /* if the control sequence is not 10-bit then throw exception */
+ if (len != 10) {
+ return false;
+ }
+
+ for (size_t i = 0; i < len; i++) {
+ d_control_symbol_pos = (d_control_symbol_pos << 1)
+ | (control_symbol[i] & 0x1);
+ }
+ d_control_symbol_neg = ~d_control_symbol_pos;
+
+ return true;
+ }
+
+ int
+ decoder_8b10b_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];
+ for (int i = 0; i < noutput_items; i++) {
+
+ d_data_reg = (d_data_reg << 1) | (in[i] & 0x1);
+
+ unsigned long long wrong_bits = (d_data_reg ^ d_control_symbol_pos)
+ & 0x3FF;
+ unsigned int nwrong = gr::blocks::count_bits64 (wrong_bits);
+
+ if (nwrong <= 1) {
+ d_data_reg = 0;
+ printf ("Packet found \n");
+ }
+
+ //GR_LOG_DEBUG(d_logger, boost::format ("Wrong number: %u") % wrong_bits);
+
+ }
+
+ // Tell runtime system how many output items we produced.
+ return noutput_items;
+ }
+
+ }
+/* namespace satnogs */
+} /* namespace gr */
+
diff --git a/lib/decoder_8b10b_impl.h b/lib/decoder_8b10b_impl.h
new file mode 100644
index 0000000..e128355
--- /dev/null
+++ b/lib/decoder_8b10b_impl.h
@@ -0,0 +1,59 @@
+/* -*- 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_DECODER_8B10B_IMPL_H
+#define INCLUDED_SATNOGS_DECODER_8B10B_IMPL_H
+
+#include
+
+namespace gr
+{
+ namespace satnogs
+ {
+
+ class decoder_8b10b_impl : public decoder_8b10b
+ {
+ private:
+ size_t d_max_frame_len;
+ int d_comp_type;
+ uint16_t d_control_symbol_pos;
+ uint16_t d_control_symbol_neg;
+ uint16_t d_data_reg;
+
+ public:
+ decoder_8b10b_impl (const std::string& control_symbol,
+ size_t max_frame_len, int comp_type);
+ ~decoder_8b10b_impl ();
+
+ bool
+ set_access_code (const std::string &access_code);
+
+ // 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_DECODER_8B10B_IMPL_H */
+
diff --git a/swig/satnogs_swig0.i b/swig/satnogs_swig0.i
index e73340a..04654af 100644
--- a/swig/satnogs_swig0.i
+++ b/swig/satnogs_swig0.i
@@ -32,6 +32,7 @@
#include "satnogs/frame_file_sink.h"
#include "satnogs/iq_sink.h"
#include "satnogs/quad_demod_filter_ff.h"
+#include "satnogs/decoder_8b10b.h"
%}
@@ -100,3 +101,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, frame_file_sink);
GR_SWIG_BLOCK_MAGIC2(satnogs, iq_sink);
%include "satnogs/quad_demod_filter_ff.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, quad_demod_filter_ff);
+%include "satnogs/decoder_8b10b.h"
+GR_SWIG_BLOCK_MAGIC2(satnogs, decoder_8b10b);