hamnet70-gnuradio-legacy/gr-hamnet70/lib/scrambler_impl.cc

91 lines
2.2 KiB
C++
Raw Normal View History

/* -*- c++ -*- */
/*
* Copyright 2019 Thomas Kolb.
*
* 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 "scrambler_impl.h"
namespace gr {
namespace hamnet70 {
scrambler::sptr
scrambler::make(uint8_t start, uint8_t polynom)
{
return gnuradio::get_initial_sptr
(new scrambler_impl(start, polynom));
}
/*
* The private constructor
*/
scrambler_impl::scrambler_impl(uint8_t start, uint8_t polynom)
: gr::tagged_stream_block("scrambler",
gr::io_signature::make(1, 1, sizeof(uint8_t)),
gr::io_signature::make(1, 1, sizeof(uint8_t)), "packet_len"),
d_start(start),
d_polynom(polynom)
{}
/*
* Our virtual destructor.
*/
scrambler_impl::~scrambler_impl()
{
}
int
scrambler_impl::calculate_output_stream_length(const gr_vector_int &ninput_items)
{
int noutput_items = ninput_items[0];
return noutput_items ;
}
int
scrambler_impl::work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const uint8_t *in = (const uint8_t *) input_items[0];
uint8_t *out = (uint8_t *) output_items[0];
uint8_t lfsr = d_start;
for(size_t i = 0; i < noutput_items; i++) {
*out = *in ^ lfsr;
if(lfsr & 0x1) {
lfsr = (lfsr >> 1) ^ d_polynom;
} else {
lfsr >>= 1;
}
}
// Tell runtime system how many output items we produced.
return noutput_items;
}
} /* namespace hamnet70 */
} /* namespace gr */