From 7e3107282accf637f52b55b5c049a70735167509 Mon Sep 17 00:00:00 2001 From: Anton Ottosson Date: Wed, 14 Jul 2021 19:34:12 +0200 Subject: [PATCH] Added Extract CSI block. This block takes PDU messages as input, looks for a "csi" entry in the meta dictionary, and if found outputs a complex CSI vector on a stream output. The meta is also sent along as stream tags. --- grc/CMakeLists.txt | 1 + grc/ieee802_11_extract_csi.block.yml | 21 +++++++ include/ieee802_11/CMakeLists.txt | 1 + include/ieee802_11/extract_csi.h | 41 ++++++++++++++ lib/CMakeLists.txt | 1 + lib/extract_csi_impl.cc | 85 ++++++++++++++++++++++++++++ lib/extract_csi_impl.h | 50 ++++++++++++++++ swig/ieee802_11_swig.i | 3 + 8 files changed, 203 insertions(+) create mode 100644 grc/ieee802_11_extract_csi.block.yml create mode 100644 include/ieee802_11/extract_csi.h create mode 100644 lib/extract_csi_impl.cc create mode 100644 lib/extract_csi_impl.h diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 5b44980..bd1a3f3 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -22,6 +22,7 @@ install(FILES ieee802_11_chunks_to_symbols.block.yml ieee802_11_decode_mac.block.yml ieee802_11_ether_encap.block.yml + ieee802_11_extract_csi.block.yml ieee802_11_frame_equalizer.block.yml ieee802_11_mac.block.yml ieee802_11_mapper.block.yml diff --git a/grc/ieee802_11_extract_csi.block.yml b/grc/ieee802_11_extract_csi.block.yml new file mode 100644 index 0000000..498dbf0 --- /dev/null +++ b/grc/ieee802_11_extract_csi.block.yml @@ -0,0 +1,21 @@ +id: ieee802_11_extract_csi +label: Extract CSI +category: '[IEEE802.11]' + +templates: + imports: import ieee802_11 + make: ieee802_11.extract_csi() + +inputs: +- label: pdu in + domain: message + optional: false + +outputs: +- label: csi out + domain: stream + dtype: complex + vlen: 52 + optional: false + +file_format: 1 diff --git a/include/ieee802_11/CMakeLists.txt b/include/ieee802_11/CMakeLists.txt index 5b65039..a9a81a5 100644 --- a/include/ieee802_11/CMakeLists.txt +++ b/include/ieee802_11/CMakeLists.txt @@ -25,6 +25,7 @@ list(APPEND include_sources constellations.h decode_mac.h ether_encap.h + extract_csi.h frame_equalizer.h mac.h mapper.h diff --git a/include/ieee802_11/extract_csi.h b/include/ieee802_11/extract_csi.h new file mode 100644 index 0000000..2110bda --- /dev/null +++ b/include/ieee802_11/extract_csi.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 2021 Anton Ottosson. + * + * 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_IEEE802_11_EXTRACT_CSI_H +#define INCLUDED_IEEE802_11_EXTRACT_CSI_H + +#include +#include + +namespace gr { + namespace ieee802_11 { + + class IEEE802_11_API extract_csi : virtual public gr::sync_block + { + public: + typedef boost::shared_ptr sptr; + static sptr make(); + }; + + } // namespace ieee802_11 +} // namespace gr + +#endif /* INCLUDED_IEEE802_11_EXTRACT_CSI_H */ + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 24d3f38..869f02d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -39,6 +39,7 @@ list(APPEND ieee802_11_sources equalizer/lms.cc equalizer/sta.cc ether_encap_impl.cc + extract_csi_impl.cc frame_equalizer_impl.cc mac.cc mapper.cc diff --git a/lib/extract_csi_impl.cc b/lib/extract_csi_impl.cc new file mode 100644 index 0000000..dd2c7a9 --- /dev/null +++ b/lib/extract_csi_impl.cc @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * Copyright 2021 Anton Ottosson. + * + * 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 "extract_csi_impl.h" + +namespace gr { + namespace ieee802_11 { + + extract_csi::sptr + extract_csi::make() + { + return gnuradio::get_initial_sptr + (new extract_csi_impl()); + } + + + extract_csi_impl::extract_csi_impl() + : gr::sync_block("extract_csi", + gr::io_signature::make(0, 0, 0), + gr::io_signature::make(1, 1, 52 * sizeof(gr_complex))) + { + message_port_register_in(pmt::mp("pdu in")); + } + + extract_csi_impl::~extract_csi_impl() + { + } + + int + extract_csi_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + pmt::pmt_t pdu(delete_head_nowait(pmt::mp("pdu in"))); + + if (pdu.get() == NULL) return 0; + + if (!pmt::is_pair(pdu) || !pmt::is_dict(pmt::car(pdu))) + throw std::runtime_error("received a malformed pdu message"); + + d_meta = pmt::car(pdu); + + if (!pmt::dict_has_key(d_meta, pmt::mp("csi"))) return 0; + + d_csi = pmt::c32vector_elements(pmt::dict_ref(d_meta, pmt::mp("csi"), pmt::PMT_NIL)); + + gr_complex* out = (gr_complex*) output_items[0]; + + std::copy(d_csi.begin(), d_csi.end(), out); + + pmt::pmt_t keys(pmt::dict_keys(d_meta)); + for (int i = 0; i < pmt::length(keys); i++) { + pmt::pmt_t k(pmt::nth(i, keys)); + pmt::pmt_t v(pmt::dict_ref(d_meta, k, pmt::PMT_NIL)); + add_item_tag(0, nitems_written(0), k, v, alias_pmt()); + } + + return 1; + } + + } /* namespace ieee802_11 */ +} /* namespace gr */ + diff --git a/lib/extract_csi_impl.h b/lib/extract_csi_impl.h new file mode 100644 index 0000000..d2b3e5a --- /dev/null +++ b/lib/extract_csi_impl.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2021 Anton Ottosson. + * + * 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_IEEE802_11_EXTRACT_CSI_IMPL_H +#define INCLUDED_IEEE802_11_EXTRACT_CSI_IMPL_H + +#include + +namespace gr { + namespace ieee802_11 { + + class extract_csi_impl : public extract_csi + { + private: + pmt::pmt_t d_meta; + std::vector d_csi; + + public: + extract_csi_impl(); + ~extract_csi_impl(); + + int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ); + }; + + } // namespace ieee802_11 +} // namespace gr + +#endif /* INCLUDED_IEEE802_11_EXTRACT_CSI_IMPL_H */ + diff --git a/swig/ieee802_11_swig.i b/swig/ieee802_11_swig.i index 7ffbc23..47a31ef 100644 --- a/swig/ieee802_11_swig.i +++ b/swig/ieee802_11_swig.i @@ -28,6 +28,7 @@ #include "ieee802_11/constellations.h" #include "ieee802_11/decode_mac.h" #include "ieee802_11/ether_encap.h" +#include "ieee802_11/extract_csi.h" #include "ieee802_11/frame_equalizer.h" #include "ieee802_11/mac.h" #include "ieee802_11/mapper.h" @@ -48,6 +49,7 @@ %include "ieee802_11/constellations.h" %include "ieee802_11/decode_mac.h" %include "ieee802_11/ether_encap.h" +%include "ieee802_11/extract_csi.h" %include "ieee802_11/frame_equalizer.h" %include "ieee802_11/mac.h" %include "ieee802_11/mapper.h" @@ -59,6 +61,7 @@ GR_SWIG_BLOCK_MAGIC2(ieee802_11, chunks_to_symbols); GR_SWIG_BLOCK_MAGIC2(ieee802_11, decode_mac); GR_SWIG_BLOCK_MAGIC2(ieee802_11, ether_encap); +GR_SWIG_BLOCK_MAGIC2(ieee802_11, extract_csi); GR_SWIG_BLOCK_MAGIC2(ieee802_11, frame_equalizer); GR_SWIG_BLOCK_MAGIC2(ieee802_11, mac); GR_SWIG_BLOCK_MAGIC2(ieee802_11, mapper);