Added tagged stream and async scrambler blocks

This commit is contained in:
Thomas Kolb 2019-08-04 01:43:43 +02:00
parent 53a06afd69
commit dfc37ecb8d
15 changed files with 567 additions and 2 deletions

View file

@ -22,5 +22,7 @@ install(FILES
hamnet70_correct_frequency.xml
hamnet70_freq_est_lr.xml
hamnet70_pid_controller.xml
hamnet70_insert_delayed_tag.xml DESTINATION share/gnuradio/grc/blocks
hamnet70_insert_delayed_tag.xml
hamnet70_scrambler.xml
hamnet70_async_scrambler.xml DESTINATION share/gnuradio/grc/blocks
)

View file

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<block>
<name>Async Scrambler</name>
<key>hamnet70_async_scrambler</key>
<category>[hamnet70]</category>
<import>import hamnet70</import>
<make>hamnet70.async_scrambler($start, $polynom)</make>
<param>
<name>Start Value</name>
<key>start</key>
<type>int</type>
<!--value>0xFF</value-->
</param>
<param>
<name>Polynom</name>
<key>polynom</key>
<type>int</type>
<!--value>0x38</value-->
</param>
<sink>
<name>pdu_in</name>
<type>message</type>
</sink>
<source>
<name>pdu_out</name>
<type>message</type>
</source>
</block>

View file

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<block>
<name>Scrambler</name>
<key>hamnet70_scrambler</key>
<category>[hamnet70]</category>
<import>import hamnet70</import>
<make>hamnet70.scrambler($start, $polynom)</make>
<param>
<name>Start Value</name>
<key>start</key>
<type>int</type>
<!--value>0xFF</value-->
</param>
<param>
<name>Polynom</name>
<key>polynom</key>
<type>int</type>
<!--value>0x38</value-->
</param>
<sink>
<name>in</name>
<type>byte</type>
</sink>
<source>
<name>out</name>
<type>byte</type>
</source>
</block>

View file

@ -27,5 +27,7 @@ install(FILES
correct_frequency.h
freq_est_lr.h
pid_controller.h
insert_delayed_tag.h DESTINATION include/hamnet70
insert_delayed_tag.h
scrambler.h
async_scrambler.h DESTINATION include/hamnet70
)

View file

@ -0,0 +1,56 @@
/* -*- 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.
*/
#ifndef INCLUDED_HAMNET70_ASYNC_SCRAMBLER_H
#define INCLUDED_HAMNET70_ASYNC_SCRAMBLER_H
#include <hamnet70/api.h>
#include <gnuradio/block.h>
namespace gr {
namespace hamnet70 {
/*!
* \brief <+description of block+>
* \ingroup hamnet70
*
*/
class HAMNET70_API async_scrambler : virtual public gr::block
{
public:
typedef boost::shared_ptr<async_scrambler> sptr;
/*!
* \brief Return a shared_ptr to a new instance of hamnet70::async_scrambler.
*
* To avoid accidental use of raw pointers, hamnet70::async_scrambler's
* constructor is in a private implementation
* class. hamnet70::async_scrambler::make is the public interface for
* creating new instances.
*/
static sptr make(uint8_t start = 0xFF, uint8_t polynom = 0x38);
};
} // namespace hamnet70
} // namespace gr
#endif /* INCLUDED_HAMNET70_ASYNC_SCRAMBLER_H */

View file

@ -0,0 +1,56 @@
/* -*- 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.
*/
#ifndef INCLUDED_HAMNET70_SCRAMBLER_H
#define INCLUDED_HAMNET70_SCRAMBLER_H
#include <hamnet70/api.h>
#include <gnuradio/tagged_stream_block.h>
namespace gr {
namespace hamnet70 {
/*!
* \brief <+description of block+>
* \ingroup hamnet70
*
*/
class HAMNET70_API scrambler : virtual public gr::tagged_stream_block
{
public:
typedef boost::shared_ptr<scrambler> sptr;
/*!
* \brief Return a shared_ptr to a new instance of hamnet70::scrambler.
*
* To avoid accidental use of raw pointers, hamnet70::scrambler's
* constructor is in a private implementation
* class. hamnet70::scrambler::make is the public interface for
* creating new instances.
*/
static sptr make(uint8_t start = 0xFF, uint8_t polynom = 0x38);
};
} // namespace hamnet70
} // namespace gr
#endif /* INCLUDED_HAMNET70_SCRAMBLER_H */

View file

@ -31,6 +31,8 @@ list(APPEND hamnet70_sources
freq_est_lr_impl.cc
pid_controller_impl.cc
insert_delayed_tag_impl.cc
scrambler_impl.cc
async_scrambler_impl.cc
)
set(hamnet70_sources "${hamnet70_sources}" PARENT_SCOPE)

View file

@ -0,0 +1,96 @@
/* -*- 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 <volk/volk.h>
#include <gnuradio/io_signature.h>
#include "async_scrambler_impl.h"
namespace gr {
namespace hamnet70 {
async_scrambler::sptr
async_scrambler::make(uint8_t start, uint8_t polynom)
{
return gnuradio::get_initial_sptr
(new async_scrambler_impl(start, polynom));
}
/*
* The private constructor
*/
async_scrambler_impl::async_scrambler_impl(uint8_t start, uint8_t polynom)
: gr::block("async_scrambler",
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0)),
d_start(start),
d_polynom(polynom)
{
d_in_port = pmt::mp("pdu_in");
d_out_port = pmt::mp("pdu_out");
message_port_register_in(d_in_port);
message_port_register_out(d_out_port);
set_msg_handler(d_in_port, boost::bind(&async_scrambler_impl::scramble, this ,_1) );
}
/*
* Our virtual destructor.
*/
async_scrambler_impl::~async_scrambler_impl()
{
}
void async_scrambler_impl::scramble(pmt::pmt_t pdu)
{
// extract input pdu
pmt::pmt_t meta(pmt::car(pdu));
pmt::pmt_t bytes(pmt::cdr(pdu));
unsigned int crc;
size_t pkt_len(0);
const uint8_t* bytes_in = pmt::u8vector_elements(bytes, pkt_len);
uint8_t* bytes_out = (uint8_t*)volk_malloc(pkt_len*sizeof(uint8_t),
volk_get_alignment());
uint8_t lfsr = d_start;
for(size_t i = 0; i < pkt_len; i++) {
bytes_out[i] = bytes_in[i] ^ lfsr;
if(lfsr & 0x1) {
lfsr = (lfsr >> 1) ^ d_polynom;
} else {
lfsr >>= 1;
}
}
pmt::pmt_t output = pmt::init_u8vector(pkt_len, bytes_out); // this copies the values from bytes_out into the u8vector
pmt::pmt_t msg_pair = pmt::cons(meta, output);
message_port_pub(d_out_port, msg_pair);
volk_free(bytes_out);
}
} /* namespace hamnet70 */
} /* namespace gr */

View file

@ -0,0 +1,58 @@
/* -*- 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.
*/
#ifndef INCLUDED_HAMNET70_ASYNC_SCRAMBLER_IMPL_H
#define INCLUDED_HAMNET70_ASYNC_SCRAMBLER_IMPL_H
#include <hamnet70/async_scrambler.h>
namespace gr {
namespace hamnet70 {
class async_scrambler_impl : public async_scrambler
{
private:
pmt::pmt_t d_in_port;
pmt::pmt_t d_out_port;
uint8_t d_start;
uint8_t d_polynom;
public:
async_scrambler_impl(uint8_t start, uint8_t polynom);
~async_scrambler_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 scramble(pmt::pmt_t pdu);
};
} // namespace hamnet70
} // namespace gr
#endif /* INCLUDED_HAMNET70_ASYNC_SCRAMBLER_IMPL_H */

View file

@ -0,0 +1,90 @@
/* -*- 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 */

View file

@ -0,0 +1,53 @@
/* -*- 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.
*/
#ifndef INCLUDED_HAMNET70_SCRAMBLER_IMPL_H
#define INCLUDED_HAMNET70_SCRAMBLER_IMPL_H
#include <hamnet70/scrambler.h>
namespace gr {
namespace hamnet70 {
class scrambler_impl : public scrambler
{
private:
uint8_t d_start;
uint8_t d_polynom;
protected:
int calculate_output_stream_length(const gr_vector_int &ninput_items);
public:
scrambler_impl(uint8_t start, uint8_t polynom);
~scrambler_impl();
// Where all the action really happens
int work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace hamnet70
} // namespace gr
#endif /* INCLUDED_HAMNET70_SCRAMBLER_IMPL_H */

View file

@ -47,3 +47,5 @@ set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig)
#GR_ADD_TEST(qa_freq_est_lr ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_freq_est_lr.py)
#GR_ADD_TEST(qa_pid_controller ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_pid_controller.py)
#GR_ADD_TEST(qa_insert_delayed_tag ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_insert_delayed_tag.py)
#GR_ADD_TEST(qa_scrambler ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_scrambler.py)
#GR_ADD_TEST(qa_async_scrambler ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_async_scrambler.py)

View file

@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# 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.
#
from gnuradio import gr, gr_unittest
from gnuradio import blocks
import hamnet70_swig as hamnet70
class qa_async_scrambler (gr_unittest.TestCase):
def setUp (self):
self.tb = gr.top_block ()
def tearDown (self):
self.tb = None
def test_001_t (self):
# set up fg
self.tb.run ()
# check data
if __name__ == '__main__':
gr_unittest.run(qa_async_scrambler, "qa_async_scrambler.xml")

View file

@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# 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.
#
from gnuradio import gr, gr_unittest
from gnuradio import blocks
import hamnet70_swig as hamnet70
class qa_scrambler (gr_unittest.TestCase):
def setUp (self):
self.tb = gr.top_block ()
def tearDown (self):
self.tb = None
def test_001_t (self):
# set up fg
self.tb.run ()
# check data
if __name__ == '__main__':
gr_unittest.run(qa_scrambler, "qa_scrambler.xml")

View file

@ -13,6 +13,8 @@
#include "hamnet70/freq_est_lr.h"
#include "hamnet70/pid_controller.h"
#include "hamnet70/insert_delayed_tag.h"
#include "hamnet70/scrambler.h"
#include "hamnet70/async_scrambler.h"
%}
@ -27,3 +29,7 @@ GR_SWIG_BLOCK_MAGIC2(hamnet70, freq_est_lr);
GR_SWIG_BLOCK_MAGIC2(hamnet70, pid_controller);
%include "hamnet70/insert_delayed_tag.h"
GR_SWIG_BLOCK_MAGIC2(hamnet70, insert_delayed_tag);
%include "hamnet70/scrambler.h"
GR_SWIG_BLOCK_MAGIC2(hamnet70, scrambler);
%include "hamnet70/async_scrambler.h"
GR_SWIG_BLOCK_MAGIC2(hamnet70, async_scrambler);