diff --git a/gr-hamnet70/grc/CMakeLists.txt b/gr-hamnet70/grc/CMakeLists.txt index 74a04b7..8ff9626 100644 --- a/gr-hamnet70/grc/CMakeLists.txt +++ b/gr-hamnet70/grc/CMakeLists.txt @@ -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 ) diff --git a/gr-hamnet70/grc/hamnet70_async_scrambler.xml b/gr-hamnet70/grc/hamnet70_async_scrambler.xml new file mode 100644 index 0000000..8a011dd --- /dev/null +++ b/gr-hamnet70/grc/hamnet70_async_scrambler.xml @@ -0,0 +1,30 @@ + + + Async Scrambler + hamnet70_async_scrambler + [hamnet70] + import hamnet70 + hamnet70.async_scrambler($start, $polynom) + + Start Value + start + int + + + + Polynom + polynom + int + + + + + pdu_in + message + + + + pdu_out + message + + diff --git a/gr-hamnet70/grc/hamnet70_scrambler.xml b/gr-hamnet70/grc/hamnet70_scrambler.xml new file mode 100644 index 0000000..1f120c4 --- /dev/null +++ b/gr-hamnet70/grc/hamnet70_scrambler.xml @@ -0,0 +1,30 @@ + + + Scrambler + hamnet70_scrambler + [hamnet70] + import hamnet70 + hamnet70.scrambler($start, $polynom) + + Start Value + start + int + + + + Polynom + polynom + int + + + + + in + byte + + + + out + byte + + diff --git a/gr-hamnet70/include/hamnet70/CMakeLists.txt b/gr-hamnet70/include/hamnet70/CMakeLists.txt index 1c7e214..0b2749f 100644 --- a/gr-hamnet70/include/hamnet70/CMakeLists.txt +++ b/gr-hamnet70/include/hamnet70/CMakeLists.txt @@ -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 ) diff --git a/gr-hamnet70/include/hamnet70/async_scrambler.h b/gr-hamnet70/include/hamnet70/async_scrambler.h new file mode 100644 index 0000000..224ccb2 --- /dev/null +++ b/gr-hamnet70/include/hamnet70/async_scrambler.h @@ -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 +#include + +namespace gr { + namespace hamnet70 { + + /*! + * \brief <+description of block+> + * \ingroup hamnet70 + * + */ + class HAMNET70_API async_scrambler : virtual public gr::block + { + public: + typedef boost::shared_ptr 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 */ + diff --git a/gr-hamnet70/include/hamnet70/scrambler.h b/gr-hamnet70/include/hamnet70/scrambler.h new file mode 100644 index 0000000..1e721d6 --- /dev/null +++ b/gr-hamnet70/include/hamnet70/scrambler.h @@ -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 +#include + +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 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 */ + diff --git a/gr-hamnet70/lib/CMakeLists.txt b/gr-hamnet70/lib/CMakeLists.txt index 39e9829..1143942 100644 --- a/gr-hamnet70/lib/CMakeLists.txt +++ b/gr-hamnet70/lib/CMakeLists.txt @@ -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) diff --git a/gr-hamnet70/lib/async_scrambler_impl.cc b/gr-hamnet70/lib/async_scrambler_impl.cc new file mode 100644 index 0000000..09b0bfa --- /dev/null +++ b/gr-hamnet70/lib/async_scrambler_impl.cc @@ -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 +#include +#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 */ + diff --git a/gr-hamnet70/lib/async_scrambler_impl.h b/gr-hamnet70/lib/async_scrambler_impl.h new file mode 100644 index 0000000..a256caf --- /dev/null +++ b/gr-hamnet70/lib/async_scrambler_impl.h @@ -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 + +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 */ + diff --git a/gr-hamnet70/lib/scrambler_impl.cc b/gr-hamnet70/lib/scrambler_impl.cc new file mode 100644 index 0000000..35b8886 --- /dev/null +++ b/gr-hamnet70/lib/scrambler_impl.cc @@ -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 +#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 */ + diff --git a/gr-hamnet70/lib/scrambler_impl.h b/gr-hamnet70/lib/scrambler_impl.h new file mode 100644 index 0000000..eeeb497 --- /dev/null +++ b/gr-hamnet70/lib/scrambler_impl.h @@ -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 + +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 */ + diff --git a/gr-hamnet70/python/CMakeLists.txt b/gr-hamnet70/python/CMakeLists.txt index bf7a130..0be348d 100644 --- a/gr-hamnet70/python/CMakeLists.txt +++ b/gr-hamnet70/python/CMakeLists.txt @@ -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) diff --git a/gr-hamnet70/python/qa_async_scrambler.py b/gr-hamnet70/python/qa_async_scrambler.py new file mode 100755 index 0000000..2952407 --- /dev/null +++ b/gr-hamnet70/python/qa_async_scrambler.py @@ -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") diff --git a/gr-hamnet70/python/qa_scrambler.py b/gr-hamnet70/python/qa_scrambler.py new file mode 100755 index 0000000..2d3d51f --- /dev/null +++ b/gr-hamnet70/python/qa_scrambler.py @@ -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") diff --git a/gr-hamnet70/swig/hamnet70_swig.i b/gr-hamnet70/swig/hamnet70_swig.i index 8929e8b..9e29b71 100644 --- a/gr-hamnet70/swig/hamnet70_swig.i +++ b/gr-hamnet70/swig/hamnet70_swig.i @@ -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);