Skip to content

Commit

Permalink
finalze scan. Now it is simple by default, but can be used advanced, …
Browse files Browse the repository at this point in the history
…too. Limitations of qt charts apply.
  • Loading branch information
Consti10 committed Dec 6, 2023
1 parent 8d95193 commit 67c987b
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 24 deletions.
3 changes: 2 additions & 1 deletion app/telemetry/action/ohdaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ bool OHDAction::send_command_reboot_gnd(bool reboot)
return res==CmdSender::Result::CMD_SUCCESS;
}

bool OHDAction::send_command_analyze_channels_blocking()
bool OHDAction::send_command_analyze_channels_blocking(int freq_bands)
{
mavlink_command_long_t cmd{};
cmd.target_system=OHD_SYS_ID_GROUND;
cmd.target_component=MAV_COMP_ID_ONBOARD_COMPUTER;
cmd.command=OPENHD_CMD_INITIATE_CHANNEL_ANALYZE;
cmd.param1=static_cast<float>(freq_bands);
const auto res=CmdSender::instance().send_command_long_blocking(cmd);
return res==CmdSender::Result::CMD_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion app/telemetry/action/ohdaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OHDAction : public QObject
Q_INVOKABLE bool send_command_reboot_gnd(bool reboot);

// Sent to the ground unit only
bool send_command_analyze_channels_blocking();
bool send_command_analyze_channels_blocking(int freq_bands);
bool send_command_start_scan_channels_blocking(int freq_bands,int channel_widths);
private:
};
Expand Down
16 changes: 16 additions & 0 deletions app/telemetry/settings/frequencyhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ QList<int> FrequencyHelper::get_frequencies(int filter)
return ret;
}

QList<int> FrequencyHelper::filter_frequencies_40mhz_ht40plus_only(QList<int> frequencies)
{
std::vector<uint32_t> frequencies2;
for(auto& freq:frequencies){
frequencies2.push_back(freq);
}
QList<int> ret;
auto channels=openhd::frequencies_to_channels(frequencies2);
for(auto& channel:channels){
if(channel.in_40Mhz_ht40_plus){
ret.push_back(channel.frequency);
}
}
return ret;
}

QList<int> FrequencyHelper::get_frequencies_all_40Mhz()
{
QList<int> ret;
Expand Down
2 changes: 2 additions & 0 deletions app/telemetry/settings/frequencyhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class FrequencyHelper : public QObject
static FrequencyHelper &instance();
// Filter: 0 - OpenHD 1-5 only, 1= all 2.4G freq, 2 = all 5.8G freq
Q_INVOKABLE QList<int> get_frequencies(int filter);
Q_INVOKABLE QList<int> filter_frequencies_40mhz_ht40plus_only(QList<int>);

Q_INVOKABLE QList<int> get_frequencies_all_40Mhz();

Q_INVOKABLE bool get_frequency_radar(int frequency_mhz);
Expand Down
19 changes: 18 additions & 1 deletion app/telemetry/settings/pollutionhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,19 @@ QStringList PollutionHelper::pollution_frequencies_int_to_qstringlist(QList<int>
for(auto& freq:frequencies){
std::stringstream ss;
ss<<freq<<"Mhz";
ret.push_back(QString(ss.str().c_str()));
auto pollution=threadsafe_get_pollution_for_frequency(freq);
if(pollution.has_value()){
/*if(pollution.value().n_foreign_packets<1){
ss<<"\nFREE";
}else{
ss<<"\nPOLLUTED";
}*/
ret.push_back(QString(ss.str().c_str()));
}else{
//ss<<" N/A";
//ret.push_back(QString(ss.str().c_str()));
ret.push_back(" ");
}
}
return ret;
}
Expand All @@ -73,6 +85,11 @@ QVariantList PollutionHelper::pollution_frequencies_int_get_pollution(QList<int>
if(normalize){
ret.push_back(static_cast<int>(pollution.value().n_foreign_packets_normalized));
}else{
/*if(pollution.value().n_foreign_packets<1){
ret.push_back(static_cast<int>(0));
}else{
ret.push_back(static_cast<int>(100));
}*/
ret.push_back(static_cast<int>(pollution.value().n_foreign_packets));
}

Expand Down
4 changes: 2 additions & 2 deletions app/telemetry/settings/wblinksettingshelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ WBLinkSettingsHelper& WBLinkSettingsHelper::instance()
return tmp;
}

bool WBLinkSettingsHelper::start_analyze_channels()
bool WBLinkSettingsHelper::start_analyze_channels(int freq_bands)
{
if(OHDAction::instance().send_command_analyze_channels_blocking()){
if(OHDAction::instance().send_command_analyze_channels_blocking(freq_bands)){
set_analyze_progress_perc(0);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion app/telemetry/settings/wblinksettingshelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WBLinkSettingsHelper : public QObject
void validate_and_set_gnd_channel_width_mhz(int channel_width_mhz);
void validate_and_set_air_channel_width_mhz(int channel_width_mhz);
public:
Q_INVOKABLE bool start_analyze_channels();
Q_INVOKABLE bool start_analyze_channels(int freq_bands);
// freq_bands:
// 0: 2.4G and 5.8G
// 1: 2.4G only
Expand Down
87 changes: 69 additions & 18 deletions qml/ui/configpopup/openhd_settings/PopupAnalyzeChannels.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Rectangle{

property bool m_normalize_data: false;
property int m_chart_view_minimum_width: 1280;
property int m_chart_view_minimum_width2: 1280;

property bool m_chart_enlarged: false;

Expand All @@ -44,9 +43,9 @@ Rectangle{

ListModel{
id: model_filter
ListElement {title: "NO FILTER"; value: 0}
ListElement {title: "2.4G ONLY"; value: 1}
ListElement {title: "5.8G ONLY"; value: 2}
ListElement {title: "OHD [1-5]"; value: 0}
ListElement {title: "All 2.4G"; value: 1}
ListElement {title: "All 5.8G"; value: 2}
}

property string m_info_string: "Analyze channels for pollution by wifi access points.\n"+
Expand Down Expand Up @@ -105,7 +104,8 @@ Rectangle{
id:startButton
text: "START"
onClicked: {
var result=_wbLinkSettingsHelper.start_analyze_channels()
var how_many_freq_bands=comboBoxWhichFrequencyToAnalyze.currentIndex
var result=_wbLinkSettingsHelper.start_analyze_channels(how_many_freq_bands)
if(result!==true){
_qopenhd.show_toast("Busy,please try again later",true);
}else{
Expand All @@ -117,7 +117,7 @@ Rectangle{
ComboBox {
Layout.preferredWidth: 150
Layout.minimumWidth: 50
id: comboBoxFilter
id: comboBoxWhichFrequencyToAnalyze
model: model_filter
textRole: "title"
onCurrentIndexChanged: {
Expand All @@ -130,6 +130,9 @@ Rectangle{
onCheckedChanged: {
m_normalize_data=checked
pollution_chart.update_pollution_graph();
if(m_normalize_data){
_qopenhd.show_toast("WARNING: THIS VIEW CAN BE DECEIVING !");
}
}
}
Text{
Expand Down Expand Up @@ -171,16 +174,17 @@ Rectangle{

ChartView {
id: pollution_chart
clip: true
//width: main_background.width>m_chart_view_minimum_width ? main_background.width : m_chart_view_minimum_width;
width: {
const screen_width = main_background.width-10;
if(comboBoxFilter.currentIndex==0){
return screen_width>m_chart_view_minimum_width ? screen_width : m_chart_view_minimum_width;
}
if(comboBoxFilter.currentIndex==1){
return screen_width
// 2.4G and OHD 1-5 should always fit into screen size
const filter=comboBoxWhichFrequencyToAnalyze.currentIndex;
if(filter==0 || filter==1){
return screen_width;
}
return screen_width>m_chart_view_minimum_width2 ? screen_width : m_chart_view_minimum_width2;
// All the 5.8G frequencies together do not!
return screen_width>m_chart_view_minimum_width ? screen_width : m_chart_view_minimum_width;
}
//width: m_chart_enlarged ? 1280 : main_background.width
height: parent.height
Expand All @@ -191,14 +195,30 @@ Rectangle{
//const frequencies_list = _wbLinkSettingsHelper.get_pollution_qstringlist();
//bar_axis_x.categories=frequencies_list;
//const supported_frequencies = _wbLinkSettingsHelper.get_supported_frequencies();
const all_40Mhz_frequencies_unfiltered=_frequencyHelper.get_frequencies_all_40Mhz();
const all_40Mhz_frequencies = _frequencyHelper.filter_frequencies(all_40Mhz_frequencies_unfiltered,comboBoxFilter.currentIndex);
var categories = _pollutionHelper.pollution_frequencies_int_to_qstringlist(all_40Mhz_frequencies);
var values = _pollutionHelper.pollution_frequencies_int_get_pollution(all_40Mhz_frequencies,m_normalize_data);
const channels_to_analyze=comboBoxWhichFrequencyToAnalyze.currentIndex;
var frequencies_to_analyze=_frequencyHelper.get_frequencies(0);
if(channels_to_analyze==0){
frequencies_to_analyze=_frequencyHelper.get_frequencies(0);
}else if(channels_to_analyze==1){
frequencies_to_analyze=_frequencyHelper.get_frequencies(1);
}else{
frequencies_to_analyze=_frequencyHelper.get_frequencies(2);
frequencies_to_analyze=_frequencyHelper.filter_frequencies_40mhz_ht40plus_only(frequencies_to_analyze);
}
var categories = _pollutionHelper.pollution_frequencies_int_to_qstringlist(frequencies_to_analyze);
var values = _pollutionHelper.pollution_frequencies_int_get_pollution(frequencies_to_analyze,m_normalize_data);
bar_axis_x.categories=categories;
bar_set.values=values;
if(m_normalize_data){
element_x_axis.labelsVisible=false;
element_x_axis.min=0;
element_x_axis.max=100;
}else{
element_x_axis.labelsVisible=true;
element_x_axis.min=0;
element_x_axis.max=30;
}
}

BarSeries {
id: hm_bar_series
axisX: BarCategoryAxis {
Expand All @@ -207,9 +227,33 @@ Rectangle{
//min: "0"
//max: "500"
}
axisY: ValueAxis {
/*axisY: ValueAxis {
labelsVisible: false
gridVisible:false
}*/
axisY: CategoryAxis{
id: element_x_axis
min: 0
max: 30
labelsPosition: CategoryAxis.AxisLabelsPositionOnValue
CategoryRange {
label: "perfect"
endValue: 0

}
CategoryRange {
label: "good"
endValue: 10

}
CategoryRange {
label: "medium"
endValue: 20
}
CategoryRange {
label: "bad"
endValue: 30
}
}
BarSet {
id: bar_set
Expand All @@ -219,6 +263,13 @@ Rectangle{
//values: [0,0,0,0]
color: "red"
}
/*BarSet{
id: bar_set2
label: "GOOD"
color: "green"
values: [5,10,3,100]
}*/
labelsPosition: AbstractBarSeries.LabelsInsideEnd
}
}
}
Expand Down

0 comments on commit 67c987b

Please sign in to comment.