forked from Consti10/wifibroadcast
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters