diff --git a/examples/wifi_loopback.grc b/examples/wifi_loopback.grc index 7b15056..6270998 100644 --- a/examples/wifi_loopback.grc +++ b/examples/wifi_loopback.grc @@ -1,5 +1,5 @@ - + Sat Feb 1 18:28:19 2014 @@ -52,10 +52,18 @@ realtime_scheduling + + thread_safe_setters + + alias + + comment + + _coordinate (7, 4) @@ -65,33 +73,6 @@ 0 - - variable - - id - out_buf_size - - - _enabled - True - - - value - 96000 - - - alias - - - - _coordinate - (1136, 147) - - - _rotation - 0 - - variable @@ -110,6 +91,10 @@ alias + + comment + + _coordinate (179, 4) @@ -123,7 +108,7 @@ variable id - variable_0 + out_buf_size _enabled @@ -131,15 +116,19 @@ value - 0 + 96000 alias + + comment + + _coordinate - (952, 384) + (1136, 147) _rotation @@ -192,6 +181,10 @@ alias + + comment + + _coordinate (1067, 10) @@ -219,6 +212,10 @@ alias + + comment + + _coordinate (422, 11) @@ -278,6 +275,10 @@ alias + + comment + + _coordinate (693, 7) @@ -325,6 +326,10 @@ maxoutbuf 0 + + comment + + _coordinate (592, 280) @@ -364,6 +369,10 @@ maxoutbuf 0 + + comment + + _coordinate (384, 264) @@ -373,41 +382,6 @@ 180 - - ieee802_11_ofdm_parse_mac - - id - ieee802_11_ofdm_parse_mac_0 - - - _enabled - True - - - log - True - - - debug - True - - - alias - - - - affinity - - - - _coordinate - (104, 251) - - - _rotation - 180 - - blocks_multiply_xx @@ -446,6 +420,10 @@ maxoutbuf 0 + + comment + + _coordinate (544, 432) @@ -505,6 +483,10 @@ maxoutbuf 0 + + comment + + _coordinate (328, 539) @@ -564,6 +546,10 @@ alias + + comment + + _coordinate (814, 8) @@ -573,53 +559,6 @@ 0 - - variable_static_text - - id - snr - - - _enabled - True - - - label - SNR - - - value - str(10 * math.log10(signal_power/noise_power)) + "dB" - - - converver - str_converter - - - formatter - None - - - grid_pos - - - - notebook - - - - alias - - - - _coordinate - (515, 8) - - - _rotation - 0 - - analog_noise_source_x @@ -662,6 +601,10 @@ maxoutbuf 0 + + comment + + _coordinate (856, 259) @@ -709,6 +652,10 @@ maxoutbuf 0 + + comment + + _coordinate (696, 443) @@ -752,6 +699,10 @@ maxoutbuf 0 + + comment + + _coordinate (696, 155) @@ -799,6 +750,10 @@ affinity + + comment + + _coordinate (888, 155) @@ -846,6 +801,10 @@ maxoutbuf 0 + + comment + + _coordinate (416, 139) @@ -905,6 +864,10 @@ alias + + comment + + _coordinate (947, 7) @@ -914,108 +877,6 @@ 0 - - variable_slider - - id - pdu_length - - - _enabled - True - - - label - - - - value - 500 - - - min - 0 - - - max - 1500 - - - num_steps - 1000 - - - style - wx.SL_HORIZONTAL - - - converver - int_converter - - - grid_pos - - - - notebook - - - - alias - - - - _coordinate - (1120, 227) - - - _rotation - 0 - - - - blocks_message_strobe - - id - blocks_message_strobe_0 - - - _enabled - True - - - msg - pmt.intern("".join("x" for i in range(pdu_length))) - - - period - 300 - - - alias - - - - affinity - - - - minoutbuf - 0 - - - maxoutbuf - 0 - - - _coordinate - (48, 131) - - - _rotation - 0 - - foo_packet_pad2 @@ -1062,6 +923,10 @@ maxoutbuf 0 + + comment + + _coordinate (320, 395) @@ -1071,6 +936,423 @@ 0 + + blocks_pdu_to_tagged_stream + + id + blocks_pdu_to_tagged_stream_0 + + + _enabled + True + + + type + float + + + tag + packet_len + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + comment + + + + _coordinate + (136, 635) + + + _rotation + 0 + + + + ieee802_11_ofdm_parse_mac + + id + ieee802_11_ofdm_parse_mac_0 + + + _enabled + True + + + log + True + + + debug + True + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + comment + + + + _coordinate + (104, 251) + + + _rotation + 180 + + + + blocks_message_strobe + + id + blocks_message_strobe_0 + + + _enabled + True + + + msg + pmt.intern("".join("x" for i in range(pdu_length))) + + + period + interval + + + alias + + + + affinity + + + + minoutbuf + 0 + + + maxoutbuf + 0 + + + comment + + + + _coordinate + (48, 131) + + + _rotation + 0 + + + + variable_slider + + id + pdu_length + + + _enabled + True + + + label + + + + value + 10 + + + min + 0 + + + max + 1500 + + + num_steps + 1000 + + + style + wx.SL_HORIZONTAL + + + converver + int_converter + + + grid_pos + + + + notebook + + + + alias + + + + comment + + + + _coordinate + (1120, 227) + + + _rotation + 0 + + + + variable_slider + + id + interval + + + _enabled + True + + + label + PDU Interval (ms) + + + value + 10 + + + min + 0 + + + max + 1000 + + + num_steps + 1000 + + + style + wx.SL_HORIZONTAL + + + converver + int_converter + + + grid_pos + + + + notebook + + + + alias + + + + comment + + + + _coordinate + (1120, 355) + + + _rotation + 0 + + + + variable_static_text + + id + snr + + + _enabled + True + + + label + SNR + + + value + str(10 * math.log10(signal_power/noise_power)) + "dB" + + + converver + str_converter + + + formatter + None + + + grid_pos + + + + notebook + + + + alias + + + + comment + + + + _coordinate + (515, 8) + + + _rotation + 0 + + + + wxgui_numbersink2 + + id + wxgui_numbersink2_0 + + + _enabled + True + + + type + float + + + title + Frame Error Rate + + + units + % + + + samp_rate + 1 + + + min_value + 0 + + + max_value + 100 + + + factor + 1.0 + + + decimal_places + 2 + + + ref_level + 0 + + + number_rate + 15 + + + peak_hold + False + + + average + False + + + avg_alpha + 0 + + + show_gauge + True + + + win_size + + + + grid_pos + + + + notebook + + + + alias + + + + affinity + + + + comment + + + + _coordinate + (672, 563) + + + _rotation + 0 + + analog_sig_source_x_0 blocks_multiply_xx_0 @@ -1131,12 +1413,6 @@ mac_out phy in - - ieee802_11_ofdm_mac_0 - wifi_phy_hier_0 - phy out - mac_in - ieee802_11_ofdm_mac_0 foo_wireshark_connector_0 @@ -1149,4 +1425,22 @@ 0 0 + + ieee802_11_ofdm_mac_0 + wifi_phy_hier_0 + phy out + mac_in + + + ieee802_11_ofdm_parse_mac_0 + blocks_pdu_to_tagged_stream_0 + fer + pdus + + + blocks_pdu_to_tagged_stream_0 + wxgui_numbersink2_0 + 0 + 0 + diff --git a/grc/ieee802_11_ofdm_parse_mac.xml b/grc/ieee802_11_ofdm_parse_mac.xml index cb6d9c9..2ebc9a2 100644 --- a/grc/ieee802_11_ofdm_parse_mac.xml +++ b/grc/ieee802_11_ofdm_parse_mac.xml @@ -44,5 +44,11 @@ message + + fer + message + 1 + + diff --git a/lib/ofdm_parse_mac.cc b/lib/ofdm_parse_mac.cc index 98232ca..4da7b12 100644 --- a/lib/ofdm_parse_mac.cc +++ b/lib/ofdm_parse_mac.cc @@ -23,6 +23,8 @@ using namespace gr::ieee802_11; +#define FER_ALPHA 0.2f + class ofdm_parse_mac_impl : public ofdm_parse_mac { public: @@ -36,6 +38,10 @@ ofdm_parse_mac_impl(bool log, bool debug) : message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), boost::bind(&ofdm_parse_mac_impl::parse, this, _1)); + + message_port_register_out(pmt::mp("fer")); + d_last_fer = 0.0f; + d_last_seq_no = 0; } ~ofdm_parse_mac_impl() { @@ -251,13 +257,36 @@ void parse_data(char *buf, int length) { } dout << std::endl; - dout << "seq nr: " << int(h->seq_nr >> 4) << std::endl; + int seq_no = int(h->seq_nr >> 4); + dout << "seq nr: " << seq_no << std::endl; dout << "mac 1: "; print_mac_address(h->addr1, true); dout << "mac 2: "; print_mac_address(h->addr2, true); dout << "mac 3: "; print_mac_address(h->addr3, true); + + int lost_frames = seq_no - d_last_seq_no - 1; + dout << "d_last_seq_no: " << d_last_seq_no << std::endl; + dout << "lost frames: " << lost_frames << std::endl; + + // calculate instantaneous error rate + float curr_fer = 0.0f; + if (lost_frames > 0) + curr_fer = 1 - (1 / (static_cast(lost_frames) + 1)); + dout << "instantaneous fer: " << curr_fer << std::endl; + + // update FER estimate + float fer = (1.0f - FER_ALPHA) * d_last_fer + FER_ALPHA * curr_fer; + dout << "rolling fer: " << fer << std::endl; + + // keep track of values + d_last_seq_no = seq_no; + d_last_fer = fer; + + // publish FER estimate + pmt::pmt_t pdu = pmt::make_f32vector(1, fer * 100); + message_port_pub(pmt::mp("fer"), pmt::cons( pmt::PMT_NIL, pdu )); } void parse_control(char *buf, int length) { @@ -341,7 +370,8 @@ void print_ascii(char* buf, int length) { private: bool d_log; bool d_debug; - + float d_last_fer; + int d_last_seq_no; }; ofdm_parse_mac::sptr