From e620d48c815610d2b859f2542aa9e24e788ed544 Mon Sep 17 00:00:00 2001 From: Anton Ottosson Date: Sat, 17 Jul 2021 16:54:23 +0200 Subject: [PATCH] Make metadata pipeline more uniform and GR-like. The Frame Equalizer used to propagate metadata as a dictionary stored in a single tag. Now it instead propagates each entry as a separate tag, which is more in line with how standard GNU Radio blocks do it (see for example PDU to Tagged Stream block). This is also how the Extract CSI block does it. This modification also removes a lot of unnecessary variables and type conversions (from and to pmt types) in the Decode MAC block. --- lib/decode_mac.cc | 50 ++++++++++++------------------------- lib/frame_equalizer_impl.cc | 17 ++++++++----- 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/lib/decode_mac.cc b/lib/decode_mac.cc index 06b30a8..01d9f0a 100644 --- a/lib/decode_mac.cc +++ b/lib/decode_mac.cc @@ -36,14 +36,10 @@ public: gr::io_signature::make(0, 0, 0)), d_log(log), d_debug(debug), - d_snr(0), - d_nom_freq(0.0), - d_freq_offset(0.0), d_ofdm(BPSK_1_2), d_frame(d_ofdm, 0), d_frame_complete(true) { - message_port_register_out(pmt::mp("out")); } @@ -64,8 +60,7 @@ public: while (i < ninput_items[0]) { - get_tags_in_range( - tags, 0, nread + i, nread + i + 1, pmt::string_to_symbol("wifi_start")); + get_tags_in_range(tags, 0, nread + i, nread + i + 1); if (tags.size()) { if (d_frame_complete == false) { @@ -77,21 +72,16 @@ public: } d_frame_complete = false; - pmt::pmt_t dict = tags[0].value; + // Enter tags into metadata dictionary + d_meta = pmt::make_dict(); + for (auto tag : tags) + d_meta = pmt::dict_add(d_meta, tag.key, tag.value); + int len_data = pmt::to_uint64(pmt::dict_ref( - dict, pmt::mp("frame_bytes"), pmt::from_uint64(MAX_PSDU_SIZE + 1))); + d_meta, pmt::mp("frame_bytes"), pmt::from_uint64(MAX_PSDU_SIZE + 1))); int encoding = pmt::to_uint64( - pmt::dict_ref(dict, pmt::mp("encoding"), pmt::from_uint64(0))); - d_snr = pmt::to_double( - pmt::dict_ref(dict, pmt::mp("snr"), pmt::from_double(0))); - d_nom_freq = pmt::to_double( - pmt::dict_ref(dict, pmt::mp("freq"), pmt::from_double(0))); - d_freq_offset = pmt::to_double( - pmt::dict_ref(dict, pmt::mp("freq_offset"), pmt::from_double(0))); - d_beta = pmt::to_double( - pmt::dict_ref(dict, pmt::mp("beta"), pmt::from_double(0))); - d_csi = pmt::c32vector_elements( - pmt::dict_ref(dict, pmt::mp("csi"), pmt::make_c32vector(52, 0))); + pmt::dict_ref(d_meta, pmt::mp("encoding"), pmt::from_uint64(0))); + ofdm_param ofdm = ofdm_param((Encoding)encoding); frame_param frame = frame_param(ofdm, len_data); @@ -160,16 +150,10 @@ public: // create PDU pmt::pmt_t blob = pmt::make_blob(out_bytes + 2, d_frame.psdu_size - 4); - pmt::pmt_t enc = pmt::from_uint64(d_ofdm.encoding); - pmt::pmt_t dict = pmt::make_dict(); - dict = pmt::dict_add(dict, pmt::mp("encoding"), enc); - dict = pmt::dict_add(dict, pmt::mp("snr"), pmt::from_double(d_snr)); - dict = pmt::dict_add(dict, pmt::mp("nomfreq"), pmt::from_double(d_nom_freq)); - dict = pmt::dict_add(dict, pmt::mp("freqofs"), pmt::from_double(d_freq_offset)); - dict = pmt::dict_add(dict, pmt::mp("beta"), pmt::from_double(d_beta)); - dict = pmt::dict_add(dict, pmt::mp("csi"), pmt::init_c32vector(52, d_csi)); - dict = pmt::dict_add(dict, pmt::mp("dlt"), pmt::from_long(LINKTYPE_IEEE802_11)); - message_port_pub(pmt::mp("out"), pmt::cons(dict, blob)); + d_meta = pmt::dict_add( + d_meta, pmt::mp("dlt"), pmt::from_long(LINKTYPE_IEEE802_11)); + + message_port_pub(pmt::mp("out"), pmt::cons(d_meta, blob)); } void deinterleave() @@ -249,13 +233,11 @@ private: bool d_debug; bool d_log; + pmt::pmt_t d_meta; + frame_param d_frame; ofdm_param d_ofdm; - double d_snr; // dB - double d_nom_freq; // nominal frequency, Hz - double d_freq_offset; // frequency offset, Hz - double d_beta; - std::vector d_csi; + viterbi_decoder d_decoder; uint8_t d_rx_symbols[48 * MAX_SYM]; diff --git a/lib/frame_equalizer_impl.cc b/lib/frame_equalizer_impl.cc index bad1506..a9c0963 100644 --- a/lib/frame_equalizer_impl.cc +++ b/lib/frame_equalizer_impl.cc @@ -224,7 +224,7 @@ int frame_equalizer_impl::general_work(int noutput_items, dict, pmt::mp("encoding"), pmt::from_uint64(d_frame_encoding)); dict = pmt::dict_add( dict, pmt::mp("snr"), pmt::from_double(d_equalizer->get_snr())); - dict = pmt::dict_add(dict, pmt::mp("freq"), pmt::from_double(d_freq)); + dict = pmt::dict_add(dict, pmt::mp("nom_freq"), pmt::from_double(d_freq)); dict = pmt::dict_add(dict, pmt::mp("freq_offset"), pmt::from_double(d_freq_offset_from_synclong)); @@ -234,11 +234,16 @@ int frame_equalizer_impl::general_work(int noutput_items, dict = pmt::dict_add( dict, pmt::mp("csi"), pmt::init_c32vector(csi.size(), csi)); - add_item_tag(0, - nitems_written(0) + o, - pmt::string_to_symbol("wifi_start"), - dict, - pmt::string_to_symbol(alias())); + pmt::pmt_t pairs = pmt::dict_items(dict); + for (int i = 0; i < pmt::length(pairs); i++) { + pmt::pmt_t pair = pmt::nth(i, pairs); + add_item_tag(0, + nitems_written(0) + o, + pmt::car(pair), + pmt::cdr(pair), + alias_pmt()); + } + } }