From 67c987b67f0a817947f59a5c16838a160f27e286 Mon Sep 17 00:00:00 2001 From: consti10 Date: Wed, 6 Dec 2023 11:10:49 +0100 Subject: [PATCH] finalze scan. Now it is simple by default, but can be used advanced, too. Limitations of qt charts apply. --- app/telemetry/action/ohdaction.cpp | 3 +- app/telemetry/action/ohdaction.h | 2 +- app/telemetry/settings/frequencyhelper.cpp | 16 ++++ app/telemetry/settings/frequencyhelper.h | 2 + app/telemetry/settings/pollutionhelper.cpp | 19 +++- .../settings/wblinksettingshelper.cpp | 4 +- app/telemetry/settings/wblinksettingshelper.h | 2 +- .../openhd_settings/PopupAnalyzeChannels.qml | 87 +++++++++++++++---- 8 files changed, 111 insertions(+), 24 deletions(-) diff --git a/app/telemetry/action/ohdaction.cpp b/app/telemetry/action/ohdaction.cpp index 7aa740721..15a279415 100644 --- a/app/telemetry/action/ohdaction.cpp +++ b/app/telemetry/action/ohdaction.cpp @@ -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(freq_bands); const auto res=CmdSender::instance().send_command_long_blocking(cmd); return res==CmdSender::Result::CMD_SUCCESS; } diff --git a/app/telemetry/action/ohdaction.h b/app/telemetry/action/ohdaction.h index 9a6ccb5de..3673bf879 100644 --- a/app/telemetry/action/ohdaction.h +++ b/app/telemetry/action/ohdaction.h @@ -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: }; diff --git a/app/telemetry/settings/frequencyhelper.cpp b/app/telemetry/settings/frequencyhelper.cpp index 543a798dc..5249a3c3a 100644 --- a/app/telemetry/settings/frequencyhelper.cpp +++ b/app/telemetry/settings/frequencyhelper.cpp @@ -39,6 +39,22 @@ QList FrequencyHelper::get_frequencies(int filter) return ret; } +QList FrequencyHelper::filter_frequencies_40mhz_ht40plus_only(QList frequencies) +{ + std::vector frequencies2; + for(auto& freq:frequencies){ + frequencies2.push_back(freq); + } + QList 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 FrequencyHelper::get_frequencies_all_40Mhz() { QList ret; diff --git a/app/telemetry/settings/frequencyhelper.h b/app/telemetry/settings/frequencyhelper.h index ce30d5f28..d8ac694be 100644 --- a/app/telemetry/settings/frequencyhelper.h +++ b/app/telemetry/settings/frequencyhelper.h @@ -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 get_frequencies(int filter); + Q_INVOKABLE QList filter_frequencies_40mhz_ht40plus_only(QList); + Q_INVOKABLE QList get_frequencies_all_40Mhz(); Q_INVOKABLE bool get_frequency_radar(int frequency_mhz); diff --git a/app/telemetry/settings/pollutionhelper.cpp b/app/telemetry/settings/pollutionhelper.cpp index d2b46fedb..4769abd48 100644 --- a/app/telemetry/settings/pollutionhelper.cpp +++ b/app/telemetry/settings/pollutionhelper.cpp @@ -59,7 +59,19 @@ QStringList PollutionHelper::pollution_frequencies_int_to_qstringlist(QList for(auto& freq:frequencies){ std::stringstream ss; ss< if(normalize){ ret.push_back(static_cast(pollution.value().n_foreign_packets_normalized)); }else{ + /*if(pollution.value().n_foreign_packets<1){ + ret.push_back(static_cast(0)); + }else{ + ret.push_back(static_cast(100)); + }*/ ret.push_back(static_cast(pollution.value().n_foreign_packets)); } diff --git a/app/telemetry/settings/wblinksettingshelper.cpp b/app/telemetry/settings/wblinksettingshelper.cpp index ec14ac3e0..a0acdcefb 100644 --- a/app/telemetry/settings/wblinksettingshelper.cpp +++ b/app/telemetry/settings/wblinksettingshelper.cpp @@ -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; } diff --git a/app/telemetry/settings/wblinksettingshelper.h b/app/telemetry/settings/wblinksettingshelper.h index ee865e275..e99d7d5f9 100644 --- a/app/telemetry/settings/wblinksettingshelper.h +++ b/app/telemetry/settings/wblinksettingshelper.h @@ -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 diff --git a/qml/ui/configpopup/openhd_settings/PopupAnalyzeChannels.qml b/qml/ui/configpopup/openhd_settings/PopupAnalyzeChannels.qml index 23837c8bb..1f938ffbb 100644 --- a/qml/ui/configpopup/openhd_settings/PopupAnalyzeChannels.qml +++ b/qml/ui/configpopup/openhd_settings/PopupAnalyzeChannels.qml @@ -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; @@ -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"+ @@ -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{ @@ -117,7 +117,7 @@ Rectangle{ ComboBox { Layout.preferredWidth: 150 Layout.minimumWidth: 50 - id: comboBoxFilter + id: comboBoxWhichFrequencyToAnalyze model: model_filter textRole: "title" onCurrentIndexChanged: { @@ -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{ @@ -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 @@ -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 { @@ -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 @@ -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 } } }