Skip to content

Commit

Permalink
merge,document
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Sep 22, 2023
1 parent ddc8ebc commit ea63198
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 52 deletions.
6 changes: 3 additions & 3 deletions app/telemetry/action/ohdaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../util/openhd_defines.hpp"
#include "impl/cmdsender.h"

#include "../models/aohdsystem.h"
//#include "../models/aohdsystem.h"

OHDAction::OHDAction(QObject *parent)
: QObject{parent}
Expand All @@ -18,7 +18,7 @@ OHDAction& OHDAction::instance()
return instance;
}

void OHDAction::request_openhd_version_async()
/*void OHDAction::request_openhd_version_async()
{
if(AOHDSystem::instanceAir().is_alive()){
auto cmd_air=cmd::helper::create_cmd_request_openhd_version(OHD_SYS_ID_AIR,0);
Expand All @@ -28,7 +28,7 @@ void OHDAction::request_openhd_version_async()
auto cmd_gnd=cmd::helper::create_cmd_request_openhd_version(OHD_SYS_ID_GROUND,0);
CmdSender::instance().send_command_long_async(cmd_gnd,nullptr);
}
}
}*/

bool OHDAction::send_command_reboot_air(bool reboot)
{
Expand Down
3 changes: 2 additions & 1 deletion app/telemetry/action/ohdaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class OHDAction : public QObject
static OHDAction& instance();
public:
// request the OpenHD version, both OpenHD air and ground unit will respond to that message.
Q_INVOKABLE void request_openhd_version_async();
// Deprecated, version is now broadcasted, too
//Q_INVOKABLE void request_openhd_version_async();
// send the reboot / shutdown command to openhd air or ground unit
// @param system_id: 0 for ground, 1 for air, 2 for FC
Q_INVOKABLE bool send_command_reboot_air(bool reboot);
Expand Down
1 change: 1 addition & 0 deletions app/telemetry/connection/tcp_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ bool TCPConnection::setup_socket()
return false;
}
#endif
return true;
}


Expand Down
49 changes: 42 additions & 7 deletions app/telemetry/models/wificard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,44 @@
#include <sstream>

#include "../../logging/hudlogmessagesmodel.h"
#include "util/qopenhdmavlinkhelper.hpp"


static QString card_driver_type_as_string(int type){
if(type==0)return "UNSUPPORTED";
if(type==1)return "RTL88X2AU";
if(type==2)return "RTL88X2BU";
return "N/A?";
static std::string wifi_card_type_to_string(const int card_type) {
switch (card_type) {
case 0:
return "RTL88X2AU_OHD";
case 1:
return "RTL88X2BU_OHD";
case 2:
return "RTL_88X2AU";
case 3:
return "RTL_88X2BU";
case 4:
return "ATHEROS";
case 5:
return "MT_7921u";
case 6:
return "RALINK";
case 7:
return "INTEL";
case 8:
return "BROADCOM";
case 9:
default:
return "UNKNOWN";
}
}


WiFiCard::WiFiCard(bool is_air,int card_idx,QObject *parent)
: QObject{parent},m_is_air_card(is_air),m_card_idx(card_idx)
{
if(!m_is_air_card){
m_alive_timer = std::make_unique<QTimer>(this);
QObject::connect(m_alive_timer.get(), &QTimer::timeout, this, &WiFiCard::update_alive);
m_alive_timer->start(1000);
}
}


Expand Down Expand Up @@ -44,6 +70,7 @@ WiFiCard &WiFiCard::instance_air()

void WiFiCard::process_mavlink(const mavlink_openhd_stats_monitor_mode_wifi_card_t &msg)
{
m_last_mavlink_message=QOpenHDMavlinkHelper::getTimeMilliseconds();
set_alive(true);
set_curr_rx_rssi_dbm(msg.rx_rssi);
set_curr_rx_rssi_dbm_antenna1(msg.rx_rssi_1);
Expand Down Expand Up @@ -93,10 +120,10 @@ void WiFiCard::process_mavlink(const mavlink_openhd_stats_monitor_mode_wifi_card
}
}
set_card_type(msg.card_type);
set_card_type_as_string(card_driver_type_as_string(msg.card_type));
set_card_type_as_string(wifi_card_type_to_string(msg.card_type).c_str());
const int card_type=msg.card_type;
bool supported = false;
if(card_type==1 || card_type==3)supported=true;
if(card_type==0 || card_type==1)supported=true;
set_card_type_supported(supported);
}

Expand All @@ -113,3 +140,11 @@ int WiFiCard::helper_get_gnd_curr_best_rssi()
return best_rssi;
}

void WiFiCard::update_alive()
{
const auto elapsed_since_last_message=QOpenHDMavlinkHelper::getTimeMilliseconds()-m_last_mavlink_message;
if(elapsed_since_last_message>5*1000){
set_alive(false);
}
}

6 changes: 6 additions & 0 deletions app/telemetry/models/wificard.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef WIFICARD_H
#define WIFICARD_H

#include <memory>
#include <qobject.h>
#include <qtimer.h>
#include "../../../lib/lqtutils_master/lqtutils_prop.h"

#include "../util/mavlink_include.h"
Expand Down Expand Up @@ -46,6 +48,10 @@ class WiFiCard : public QObject
// On the OSD, we show how many packets were received on each card in X seconds intervals
std::chrono::steady_clock::time_point m_last_packets_in_X_second_recalculation=std::chrono::steady_clock::now();
int64_t m_last_packets_in_X_second_value=-1;
// Card alive - ONLY USED FOR GROUND CARD(s)
std::unique_ptr<QTimer> m_alive_timer = nullptr;
std::atomic<int> m_last_mavlink_message=0;
void update_alive();
};

#endif // WIFICARD_H
18 changes: 18 additions & 0 deletions app/telemetry/settings/wblinksettingshelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
#include <qsettings.h>
#include <sstream>
#include "../action/ohdaction.h"
#include "../../util/qopenhd.h"

static void tmp_log_result(bool enable,const std::string message){
if(enable){
HUDLogMessagesModel::instance().add_message_info(message.c_str());
}else{
qDebug()<<"Not logged to HUD:"<<message.c_str();
}
}

WBLinkSettingsHelper::WBLinkSettingsHelper(QObject *parent)
: QObject{parent}
Expand Down Expand Up @@ -430,6 +439,15 @@ void WBLinkSettingsHelper::change_param_air_async(const int comp_id,const std::s
}
}

void WBLinkSettingsHelper::change_param_air_channel_width_async(int value, bool log_result)
{
if(!AOHDSystem::instanceAir().is_alive()){
tmp_log_result(true,"Cannot change BW, AIR not alive");
return;
}
change_param_air_async(OHD_COMP_ID_LINK_PARAM,PARAM_ID_WB_CHANNEL_WIDTH,static_cast<int32_t>(value),"BWIDTH");
}

QList<int> WBLinkSettingsHelper::get_supported_frequencies()
{
std::lock_guard<std::mutex> lock(m_supported_channels_mutex);
Expand Down
16 changes: 8 additions & 8 deletions app/telemetry/settings/wblinksettingshelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ class WBLinkSettingsHelper : public QObject
Q_INVOKABLE int change_param_air_and_ground_frequency(int value){
return change_param_air_and_ground_blocking(PARAM_ID_WB_FREQ,value);
}
Q_INVOKABLE int change_param_air_and_ground_channel_width(int value){
//return change_param_air_and_ground_blocking(PARAM_ID_WB_CHANNEL_WIDTH,value);
change_param_air_async(OHD_COMP_ID_LINK_PARAM,PARAM_ID_WB_CHANNEL_WIDTH,static_cast<int32_t>(value),"BWIDTH");
return 0;
}
//
// Changing the channel width (bandwidth) is a bit special - read the documentation in openhd
// wb_link for more info.
// This method won't return any success / error message, since we update the UI not depending on the result,
// but what channel width the ground reports via broadcast
//
Q_INVOKABLE void change_param_air_channel_width_async(int value,bool log_result);

Q_INVOKABLE bool change_param_ground_only_frequency(int value){
return change_param_ground_only_blocking(PARAM_ID_WB_FREQ,value);
}
Q_INVOKABLE bool change_param_ground_only_channel_width(int value){
return change_param_ground_only_blocking(PARAM_ID_WB_CHANNEL_WIDTH,value);
}
Q_INVOKABLE QList<int> get_supported_frequencies();
Q_INVOKABLE QString get_frequency_description(int frequency_mhz);
Q_INVOKABLE int get_frequency_pollution(int frequency_mhz);
Expand Down
4 changes: 2 additions & 2 deletions qml/ui/HUDOverlayGrid.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Item {
property bool m_keyboard_navigation_active: false
onM_keyboard_navigation_activeChanged: {
if(m_keyboard_navigation_active){
_hudLogMessagesModel.add_message_info("JOYSTICK NAVIGATION ENABLED");
_qopenhd.show_toast("JOYSTICK NAVIGATION ENABLED");
}else{
_hudLogMessagesModel.add_message_info("JOYSTICK NAVIGATION DISABLED");
_qopenhd.show_toast("JOYSTICK NAVIGATION DISABLED");
}
}

Expand Down
8 changes: 4 additions & 4 deletions qml/ui/configpopup/openhd_settings/DialoqueChangeTxPower.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ You can still use the RAW OpenHD AIR / GROUND Parameters to change your tx power
}else{
wifi_card_chip_type=_wifi_card_air.card_type;
}
if(wifi_card_chip_type<=0){
_messageBoxInstance.set_text_and_show("Card type unknown - please use a supported card. You can still change the tx power manually via the param set, but probably
if(!(wifi_card_chip_type==0 || wifi_card_chip_type==1)){
_messageBoxInstance.set_text_and_show("Card type unknown / unsupported - please use a supported card. You can still change the tx power manually via the param set, but probably
the card driver and/or the linux kernel doesn't support changing it.");
return;
}
// OpenHD has 0 for unknown, we do not allow 0
m_card_chip_type=wifi_card_chip_type-1;
// 0 is RTL8812AU, 1 is RTL8812BU
m_card_chip_type=wifi_card_chip_type;
//m_card_chip_type=0; // RTL8812AU
dialoqueTxPower.visible=true
}
Expand Down
14 changes: 10 additions & 4 deletions qml/ui/configpopup/openhd_settings/MavlinkExtraWBParamPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ Rectangle{
return ret;
}

function set_channel_width_async(channel_width_mhz){
if(!_ohdSystemAir.is_alive){
_qopenhd.show_toast("Cannot change BW:"+channel_width_mhz+"Mhz, AIR not alive")
return;
}
_wbLinkSettingsHelper.change_param_air_channel_width_async(channel_width_mhz,false);
}

property string m_text_warning_nosync_frequency: "WARNING: THIS CHANGES YOUR GROUND UNIT FREQUENCY WITHOUT CHANGING YOUR AIR UNIT FREQUENCY !
Only enable if you want to quickly change your ground unit's frequency to the already set frequency of a running air unit (And know both frequency and channel width on top of your head)";

Expand Down Expand Up @@ -472,26 +480,24 @@ the analyze channels feature or experience - [169] 5845Mhz is a good bet in Eur
_messageBoxInstance.set_text_and_show(m_info_text_change_channel_width)
}
}

/*FreqComboBoxRow{
m_main_text: _fcM
}*/

Text{
text: "Curr:"+get_text_current_frequency();
}
Button{
text: "20Mhz"
onClicked: {
set_channel_width(20)
set_channel_width_async(20);
}
highlighted: _wbLinkSettingsHelper.curr_channel_width_mhz==20
enabled: _wbLinkSettingsHelper.ui_rebuild_models>0 && _ohdSystemAir.is_alive
}
Button{
text: "40Mhz"
onClicked: {
set_channel_width(40)
set_channel_width_async(40);
}
highlighted: _wbLinkSettingsHelper.curr_channel_width_mhz==40
enabled: _wbLinkSettingsHelper.ui_rebuild_models>0 && _ohdSystemAir.is_alive
Expand Down
10 changes: 1 addition & 9 deletions qml/ui/configpopup/status/StatusCardBodyOpenHD.qml
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,9 @@ ColumnLayout {
Layout.preferredWidth: left_part_preferred_with
text: qsTr("OHD Version:")
}
Button{
text: "N/A"
onClicked: _ohdAction.request_openhd_version_async()
visible: (m_version==="N/A")
Layout.preferredHeight: text_minHeight
Layout.minimumHeight: text_minHeight
height: text_minHeight
}
Text {
text: m_version
visible: !(m_version==="N/A") && !b_version_warning.visible
visible: !b_version_warning.visible
}
ButtonYellow{
text: m_version
Expand Down
21 changes: 7 additions & 14 deletions qml/ui/widgets/WBLinkRateControlWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,12 @@ BaseWidget {
_wbLinkSettingsHelper.set_param_air_only_mcs_async(mcs_index)
}

function set_channel_width(channel_width_mhz){
if(!_ohdSystemGround.is_alive){
_hudLogMessagesModel.add_message_warning("GND not alive,cannot set "+channel_width_mhz+"Mhz Bandwidth")
return
}
function set_channel_width_async(channel_width_mhz){
if(!_ohdSystemAir.is_alive){
_hudLogMessagesModel.add_message_warning("AIR not alive,cannot set "+channel_width_mhz+"Mhz Bandwidth")
_hudLogMessagesModel.add_message_warning("Cannot change BW:"+channel_width_mhz+"Mhz, AIR not alive");
return;
}
var result = _wbLinkSettingsHelper.change_param_air_and_ground_channel_width(channel_width_mhz)
if(result !== 0){
_hudLogMessagesModel.add_message_warning("Cannot set "+channel_width_mhz+"Mhz Bandwidth")
}
_wbLinkSettingsHelper.change_param_air_channel_width_async(channel_width_mhz,true);
}

property string m_DESCRIPTION_CHANNEL_WIDTH: "
Expand Down Expand Up @@ -328,18 +321,18 @@ Make the video more stable (less microfreezes) on the cost of less image quality
Button{
text: "20Mhz"
onClicked: {
set_channel_width(20)
set_channel_width_async(20)
}
highlighted: m_curr_channel_width==20
enabled: !m_is_armed
//enabled: _ohdSystemAir.is_alive
}
Button{
text: "40Mhz"
onClicked: {
set_channel_width(40)
set_channel_width_async(40)
}
highlighted: m_curr_channel_width==40
enabled: !m_is_armed
//enabled: _ohdSystemAir.is_alive
}
}
}
Expand Down

0 comments on commit ea63198

Please sign in to comment.