Skip to content

Commit

Permalink
Added Reed-Solomon encoder block
Browse files Browse the repository at this point in the history
  • Loading branch information
daniestevez committed Jan 2, 2018
1 parent 5da4723 commit 04b243c
Show file tree
Hide file tree
Showing 9 changed files with 616 additions and 1 deletion.
1 change: 1 addition & 0 deletions grc/CMakeLists.txt
Expand Up @@ -44,6 +44,7 @@ install(FILES
satellites_gomx1_beacon_parser.xml
satellites_ks1q_header_remover.xml
satellites_decode_rs.xml
satellites_encode_rs.xml
satellites_lilacsat1_demux.xml
satellites_by701_image_decoder.xml
satellites_by701_telemetry_parser.xml
Expand Down
32 changes: 32 additions & 0 deletions grc/satellites_encode_rs.xml
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<block>
<name>CCSDS Reed-Solomon Encoder</name>
<key>satellites_encode_rs</key>
<category>[Satellites]/FEC</category>
<import>import satellites</import>
<make>satellites.encode_rs($basis)</make>

<param>
<name>Basis</name>
<key>basis</key>
<type>int</type>
<option>
<name>Conventional</name>
<key>0</key>
</option>
<option>
<name>Dual</name>
<key>1</key>
</option>
</param>

<sink>
<name>in</name>
<type>message</type>
</sink>

<source>
<name>out</name>
<type>message</type>
</source>
</block>
1 change: 1 addition & 0 deletions include/satellites/CMakeLists.txt
Expand Up @@ -23,6 +23,7 @@
install(FILES
api.h
decode_rs.h
encode_rs.h
ao40_syncframe.h
ao40_deinterleaver.h
ao40_rs_decoder.h
Expand Down
55 changes: 55 additions & 0 deletions include/satellites/encode_rs.h
@@ -0,0 +1,55 @@
/* -*- c++ -*- */
/*
* Copyright 2018 Daniel Estevez <daniel@destevez.net>.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#ifndef INCLUDED_SATELLITES_ENCODE_RS_H
#define INCLUDED_SATELLITES_ENCODE_RS_H

#include <satellites/api.h>
#include <gnuradio/block.h>

namespace gr {
namespace satellites {

/*!
* \brief <+description of block+>
* \ingroup satellites
*
*/
class SATELLITES_API encode_rs : virtual public gr::block
{
public:
typedef boost::shared_ptr<encode_rs> sptr;

/*!
* \brief Return a shared_ptr to a new instance of satellites::encode_rs.
*
* To avoid accidental use of raw pointers, satellites::encode_rs's
* constructor is in a private implementation
* class. satellites::encode_rs::make is the public interface for
* creating new instances.
*/
static sptr make(int basis);
};

} // namespace satellites
} // namespace gr

#endif /* INCLUDED_SATELLITES_ENCODE_RS_H */

1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Expand Up @@ -27,6 +27,7 @@ link_directories(${Boost_LIBRARY_DIRS})

list(APPEND satellites_sources
decode_rs_impl.cc
encode_rs_impl.cc
ao40_syncframe_impl.cc
ao40_deinterleaver_impl.cc
ao40_rs_decoder_impl.cc
Expand Down
112 changes: 112 additions & 0 deletions lib/encode_rs_impl.cc
@@ -0,0 +1,112 @@
/* -*- c++ -*- */
/*
* Copyright 2018 Daniel Estevez <daniel@destevez.net>.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gnuradio/io_signature.h>
#include "encode_rs_impl.h"

#include <cstdio>

extern "C" {
#include <fec.h>
}

#define MAX_FRAME_LEN 255
#define PARITY_BYTES 32

#define BASIS_CONVENTIONAL 0
#define BASIS_DUAL 1

namespace gr {
namespace satellites {

encode_rs::sptr
encode_rs::make(int basis)
{
return gnuradio::get_initial_sptr
(new encode_rs_impl(basis));
}

/*
* The private constructor
*/
encode_rs_impl::encode_rs_impl(int basis)
: gr::block("encode_rs",
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0))
{
d_basis = basis;

message_port_register_out(pmt::mp("out"));
message_port_register_in(pmt::mp("in"));
set_msg_handler(pmt::mp("in"),
boost::bind(&encode_rs_impl::msg_handler, this, _1));
}

/*
* Our virtual destructor.
*/
encode_rs_impl::~encode_rs_impl()
{
}

void
encode_rs_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
}

int
encode_rs_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
return 0;
}

void
encode_rs_impl::msg_handler (pmt::pmt_t pmt_msg) {
pmt::pmt_t msg = pmt::cdr(pmt_msg);
uint8_t data[MAX_FRAME_LEN];
int frame_len = pmt::length(msg);
size_t offset(0);

assert(frame_len <= MAX_FRAME_LEN - PARITY_BYTES);

memcpy(data, pmt::uniform_vector_elements(msg, offset), frame_len);

if (d_basis == BASIS_CONVENTIONAL) {
encode_rs_8(data, data + frame_len, MAX_FRAME_LEN - frame_len - PARITY_BYTES);
}
else {
encode_rs_ccsds(data, data + frame_len, MAX_FRAME_LEN - frame_len - PARITY_BYTES);
}

// Send by GNUradio message
message_port_pub(pmt::mp("out"),
pmt::cons(pmt::PMT_NIL,
pmt::init_u8vector(frame_len + PARITY_BYTES, data)));
}
} /* namespace satellites */
} /* namespace gr */

53 changes: 53 additions & 0 deletions lib/encode_rs_impl.h
@@ -0,0 +1,53 @@
/* -*- c++ -*- */
/*
* Copyright 2018 Daniel Estevez <daniel@destevez.net>.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#ifndef INCLUDED_SATELLITES_ENCODE_RS_IMPL_H
#define INCLUDED_SATELLITES_ENCODE_RS_IMPL_H

#include <satellites/encode_rs.h>

namespace gr {
namespace satellites {

class encode_rs_impl : public encode_rs
{
private:
int d_basis;

public:
encode_rs_impl(int basis);
~encode_rs_impl();

// Where all the action really happens
void forecast (int noutput_items, gr_vector_int &ninput_items_required);

int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);

void msg_handler(pmt::pmt_t pmt_msg);
};

} // namespace satellites
} // namespace gr

#endif /* INCLUDED_SATELLITES_ENCODE_RS_IMPL_H */

4 changes: 3 additions & 1 deletion swig/satellites_swig.i
Expand Up @@ -9,6 +9,7 @@

%{
#include "satellites/decode_rs.h"
#include "satellites/encode_rs.h"
#include "satellites/ao40_syncframe.h"
#include "satellites/ao40_deinterleaver.h"
#include "satellites/ao40_rs_decoder.h"
Expand All @@ -23,7 +24,8 @@

%include "satellites/decode_rs.h"
GR_SWIG_BLOCK_MAGIC2(satellites, decode_rs);

%include "satellites/encode_rs.h"
GR_SWIG_BLOCK_MAGIC2(satellites, encode_rs);
%include "satellites/ao40_syncframe.h"
GR_SWIG_BLOCK_MAGIC2(satellites, ao40_syncframe);
%include "satellites/ao40_deinterleaver.h"
Expand Down

0 comments on commit 04b243c

Please sign in to comment.