Skip to content

Commit

Permalink
signal quality impr
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Aug 9, 2023
1 parent da3351b commit 8705d12
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion WBLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/RSSIForWifiCard.hpp → src/RSSIAccumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <optional>

Expand Down Expand Up @@ -92,4 +92,4 @@ class RSSIAccumulator{
int m_rssi_identifier=0;
};

#endif // WIFIBROADCAST_RSSIFORWIFICARD_HPP
#endif // WIFIBROADCAST_RSSIACCUMULATOR_HPP
46 changes: 46 additions & 0 deletions src/SignalQualityAccumulator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Created by consti10 on 09.08.23.
//

#ifndef WIFIBROADCAST_SIGNALQUALITYACCUMULATOR_HPP
#define WIFIBROADCAST_SIGNALQUALITYACCUMULATOR_HPP

#include <optional>

#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<int> m_acc;
// -1 if invalid, [0,100] otherwise
int8_t m_curr_signal_quality=-1;
};

#endif // WIFIBROADCAST_SIGNALQUALITYACCUMULATOR_HPP
4 changes: 2 additions & 2 deletions src/WBTxRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
8 changes: 6 additions & 2 deletions src/WBTxRx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::shared_ptr<PerCardCalculators>> m_per_card_calc;
Expand Down

0 comments on commit 8705d12

Please sign in to comment.