From 8705d123370f6c7c7c5a65461eaac8172501bf74 Mon Sep 17 00:00:00 2001 From: consti10 Date: Wed, 9 Aug 2023 13:26:54 +0200 Subject: [PATCH] signal quality impr --- WBLib.cmake | 2 +- ...SSIForWifiCard.hpp => RSSIAccumulator.hpp} | 6 +-- src/SignalQualityAccumulator.hpp | 46 +++++++++++++++++++ src/WBTxRx.cpp | 4 +- src/WBTxRx.h | 8 +++- 5 files changed, 58 insertions(+), 8 deletions(-) rename src/{RSSIForWifiCard.hpp => RSSIAccumulator.hpp} (95%) create mode 100644 src/SignalQualityAccumulator.hpp diff --git a/WBLib.cmake b/WBLib.cmake index 98141d8d..cd49675f 100644 --- a/WBLib.cmake +++ b/WBLib.cmake @@ -31,7 +31,7 @@ target_sources(wifibroadcast PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/WBTxRx.cpp ${CMAKE_CURRENT_LIST_DIR}/src/Ieee80211Header.hpp ${CMAKE_CURRENT_LIST_DIR}/src/RadiotapHeader.hpp - ${CMAKE_CURRENT_LIST_DIR}/src/RSSIForWifiCard.hpp + ${CMAKE_CURRENT_LIST_DIR}/src/RSSIAccumulator.hpp ) target_include_directories(wifibroadcast PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/HelperSources diff --git a/src/RSSIForWifiCard.hpp b/src/RSSIAccumulator.hpp similarity index 95% rename from src/RSSIForWifiCard.hpp rename to src/RSSIAccumulator.hpp index e4545f5c..2374e42d 100644 --- a/src/RSSIForWifiCard.hpp +++ b/src/RSSIAccumulator.hpp @@ -2,8 +2,8 @@ // Created by consti10 on 30.06.23. // -#ifndef WIFIBROADCAST_RSSIFORWIFICARD_HPP -#define WIFIBROADCAST_RSSIFORWIFICARD_HPP +#ifndef WIFIBROADCAST_RSSIACCUMULATOR_HPP +#define WIFIBROADCAST_RSSIACCUMULATOR_HPP #include @@ -92,4 +92,4 @@ class RSSIAccumulator{ int m_rssi_identifier=0; }; -#endif // WIFIBROADCAST_RSSIFORWIFICARD_HPP +#endif // WIFIBROADCAST_RSSIACCUMULATOR_HPP diff --git a/src/SignalQualityAccumulator.hpp b/src/SignalQualityAccumulator.hpp new file mode 100644 index 00000000..51ad939c --- /dev/null +++ b/src/SignalQualityAccumulator.hpp @@ -0,0 +1,46 @@ +// +// Created by consti10 on 09.08.23. +// + +#ifndef WIFIBROADCAST_SIGNALQUALITYACCUMULATOR_HPP +#define WIFIBROADCAST_SIGNALQUALITYACCUMULATOR_HPP + +#include + +#include "TimeHelper.hpp" +#include "wifibroadcast-spdlog.h" + +/** + * Helper to accumulate (rtl8812au) signal quality values + */ +class SignalQualityAccumulator{ + public: + void add_signal_quality(int signal_quality_perc){ + if(signal_quality_perc>100 || signal_quality_perc<0){ + wifibroadcast::log::get_default()->debug("Invalid signal quality {}",signal_quality_perc); + return ; + } + m_acc.add(signal_quality_perc); + if(m_acc.getNSamples()>10 || m_acc.get_delta_since_last_reset()>std::chrono::milliseconds(500)){ + const auto tmp=m_acc.getMinMaxAvg(); + const auto avg=tmp.avg; + if(avg>=0 && avg<=100){ + m_curr_signal_quality=avg; + } + m_acc.reset(); + } + } + void reset(){ + m_acc.reset(); + m_curr_signal_quality=-1; + } + int8_t get_current_signal_quality()const{ + return m_curr_signal_quality; + } + private: + BaseAvgCalculator m_acc; + // -1 if invalid, [0,100] otherwise + int8_t m_curr_signal_quality=-1; +}; + +#endif // WIFIBROADCAST_SIGNALQUALITYACCUMULATOR_HPP diff --git a/src/WBTxRx.cpp b/src/WBTxRx.cpp index 38f90bea..ae432d0d 100644 --- a/src/WBTxRx.cpp +++ b/src/WBTxRx.cpp @@ -435,8 +435,8 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr, m_rx_stats.last_received_packet_channel_width=parsedPacket->channel_width.value(); } if(parsedPacket->signal_quality.has_value()){ - //m_console->debug("Signal quality: {}",parsedPacket->signal_quality.value()); - this_wifi_card_stats.signal_quality=parsedPacket->signal_quality.value(); + this_wifi_card_calc.signal_quality.add_signal_quality(parsedPacket->signal_quality.value()); + this_wifi_card_stats.signal_quality=this_wifi_card_calc.signal_quality.get_current_signal_quality(); } if(wlan_idx==0){ m_pollution_openhd_rx_packets++; diff --git a/src/WBTxRx.h b/src/WBTxRx.h index 1bcaeff2..d9dd326c 100644 --- a/src/WBTxRx.h +++ b/src/WBTxRx.h @@ -15,9 +15,10 @@ #include "Encryption.hpp" #include "Ieee80211Header.hpp" #include "NonceSeqNrHelper.h" -#include "RSSIForWifiCard.hpp" +#include "RSSIAccumulator.hpp" #include "RadiotapHeader.hpp" #include "SeqNrHelper.hpp" +#include "SignalQualityAccumulator.hpp" #include "TimeHelper.hpp" /** @@ -197,7 +198,8 @@ class WBTxRx { int64_t count_p_any=0; int64_t count_p_valid=0; int32_t curr_packet_loss=-1; - int signal_quality=-1; + // [0,100] if valid, -1 otherwise + int8_t signal_quality=-1; // These values are updated in regular intervals as long as packets are coming in int8_t card_dbm=-128; // Depends on driver int8_t antenna1_dbm=-128; @@ -285,11 +287,13 @@ class WBTxRx { RSSIAccumulator card_rssi{}; RSSIAccumulator antenna1_rssi{}; RSSIAccumulator antenna2_rssi{}; + SignalQualityAccumulator signal_quality{}; void reset_all(){ seq_nr.reset(); card_rssi.reset(); antenna1_rssi.reset(); antenna2_rssi.reset(); + signal_quality.reset(); } }; std::vector> m_per_card_calc;