dont init wifi widget if there is no adapter

pull/2718/head
Willem Melching 5 years ago
parent 232cb25683
commit 3d2fec6c9a
  1. 9
      selfdrive/ui/qt/offroad/wifi.cc
  2. 2
      selfdrive/ui/qt/offroad/wifi.hpp
  3. 29
      selfdrive/ui/qt/offroad/wifiManager.cc
  4. 3
      selfdrive/ui/qt/offroad/wifiManager.hpp

@ -21,7 +21,12 @@ void clearLayout(QLayout* layout) {
} }
WifiUI::WifiUI(QWidget *parent, int page_length) : QWidget(parent), networks_per_page(page_length) { WifiUI::WifiUI(QWidget *parent, int page_length) : QWidget(parent), networks_per_page(page_length) {
wifi = new WifiManager; try {
wifi = new WifiManager;
} catch (std::exception &e) {
return;
}
QObject::connect(wifi, SIGNAL(wrongPassword(QString)), this, SLOT(wrongPassword(QString))); QObject::connect(wifi, SIGNAL(wrongPassword(QString)), this, SLOT(wrongPassword(QString)));
QVBoxLayout * top_layout = new QVBoxLayout; QVBoxLayout * top_layout = new QVBoxLayout;
@ -33,7 +38,7 @@ WifiUI::WifiUI(QWidget *parent, int page_length) : QWidget(parent), networks_per
QVBoxLayout* networkLayout = new QVBoxLayout; QVBoxLayout* networkLayout = new QVBoxLayout;
QHBoxLayout *tethering_field = new QHBoxLayout; QHBoxLayout *tethering_field = new QHBoxLayout;
tethering_field->addWidget(new QLabel("Enable Tethering")); tethering_field->addWidget(new QLabel("Enable Tethering"));
Toggle* toggle_switch = new Toggle(this); Toggle* toggle_switch = new Toggle(this);
toggle_switch->setFixedSize(150, 100); toggle_switch->setFixedSize(150, 100);
tethering_field->addWidget(toggle_switch); tethering_field->addWidget(toggle_switch);

@ -18,7 +18,7 @@ public:
explicit WifiUI(QWidget *parent = 0, int page_length = 5); explicit WifiUI(QWidget *parent = 0, int page_length = 5);
private: private:
WifiManager* wifi; WifiManager* wifi = nullptr;
const int networks_per_page; const int networks_per_page;
QStackedWidget *swidget; QStackedWidget *swidget;

@ -61,17 +61,20 @@ WifiManager::WifiManager() {
qDBusRegisterMetaType<IpConfig>(); qDBusRegisterMetaType<IpConfig>();
connecting_to_network = ""; connecting_to_network = "";
adapter = get_adapter(); adapter = get_adapter();
has_adapter = adapter != "";
if (has_adapter) { bool has_adapter = adapter != "";
QDBusInterface nm(nm_service, adapter, device_iface, bus); if (!has_adapter){
bus.connect(nm_service, adapter, device_iface, "StateChanged", this, SLOT(change(unsigned int, unsigned int, unsigned int))); throw std::runtime_error("Error connecting to panda");
QDBusInterface device_props(nm_service, adapter, props_iface, bus);
QDBusMessage response = device_props.call("Get", device_iface, "State");
raw_adapter_state = get_response<uint>(response);
change(raw_adapter_state, 0, 0);
} }
QDBusInterface nm(nm_service, adapter, device_iface, bus);
bus.connect(nm_service, adapter, device_iface, "StateChanged", this, SLOT(change(unsigned int, unsigned int, unsigned int)));
QDBusInterface device_props(nm_service, adapter, props_iface, bus);
QDBusMessage response = device_props.call("Get", device_iface, "State");
raw_adapter_state = get_response<uint>(response);
change(raw_adapter_state, 0, 0);
// Compute tethering ssid as "Weedle" + first 4 characters of a dongle id // Compute tethering ssid as "Weedle" + first 4 characters of a dongle id
tethering_ssid = "weedle"; tethering_ssid = "weedle";
std::string bytes = Params().get("DongleId"); std::string bytes = Params().get("DongleId");
@ -81,8 +84,6 @@ WifiManager::WifiManager() {
} }
void WifiManager::refreshNetworks() { void WifiManager::refreshNetworks() {
if (!has_adapter) return;
bus = QDBusConnection::systemBus(); bus = QDBusConnection::systemBus();
seen_networks.clear(); seen_networks.clear();
seen_ssids.clear(); seen_ssids.clear();
@ -142,7 +143,7 @@ SecurityType WifiManager::getSecurityType(QString path) {
// obtained by looking at flags of networks in the office as reported by an Android phone // obtained by looking at flags of networks in the office as reported by an Android phone
const int supports_wpa = NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104 | NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104 | NM_802_11_AP_SEC_KEY_MGMT_PSK; const int supports_wpa = NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104 | NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104 | NM_802_11_AP_SEC_KEY_MGMT_PSK;
if (sflag == 0) { if (sflag == 0) {
return SecurityType::OPEN; return SecurityType::OPEN;
} else if ((sflag & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_props & supports_wpa) && !(wpa_props & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { } else if ((sflag & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_props & supports_wpa) && !(wpa_props & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
@ -249,8 +250,6 @@ void WifiManager::clear_connections(QString ssid) {
} }
void WifiManager::request_scan() { void WifiManager::request_scan() {
if (!has_adapter) return;
QDBusInterface nm(nm_service, adapter, wireless_device_iface, bus); QDBusInterface nm(nm_service, adapter, wireless_device_iface, bus);
nm.call("RequestScan", QVariantMap()); nm.call("RequestScan", QVariantMap());
} }
@ -326,7 +325,7 @@ void WifiManager::disconnect() {
} }
} }
//Functions for tethering //Functions for tethering
void WifiManager::enableTethering() { void WifiManager::enableTethering() {
disconnect(); disconnect();

@ -30,7 +30,6 @@ class WifiManager : public QWidget {
public: public:
explicit WifiManager(); explicit WifiManager();
bool has_adapter;
void request_scan(); void request_scan();
QVector<Network> seen_networks; QVector<Network> seen_networks;
@ -39,7 +38,7 @@ public:
void connect(Network ssid, QString password); void connect(Network ssid, QString password);
void connect(Network ssid, QString username, QString password); void connect(Network ssid, QString username, QString password);
// Tethering functions // Tethering functions
void enableTethering(); void enableTethering();
void disableTethering(); void disableTethering();
bool tetheringEnabled(); bool tetheringEnabled();

Loading…
Cancel
Save