Skip to content

Commit

Permalink
C2: display ip address in network panel (commaai#23215)
Browse files Browse the repository at this point in the history
* display ipv4 address

* refactor to class

* only display ip address
  • Loading branch information
deanlee authored Dec 14, 2021
1 parent c5dbee4 commit 084ef39
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
38 changes: 31 additions & 7 deletions selfdrive/ui/qt/offroad/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,33 +286,57 @@ void SoftwarePanel::updateLabels() {
osVersionLbl->setText(QString::fromStdString(Hardware::get_os_version()).trimmed());
}

QWidget * network_panel(QWidget * parent) {
#ifdef QCOM
QWidget *w = new QWidget(parent);
QVBoxLayout *layout = new QVBoxLayout(w);
C2NetworkPanel::C2NetworkPanel(QWidget *parent) : QWidget(parent) {
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(50, 0, 50, 0);

ListWidget *list = new ListWidget();
list->setSpacing(30);
// wifi + tethering buttons
#ifdef QCOM
auto wifiBtn = new ButtonControl("Wi-Fi Settings", "OPEN");
QObject::connect(wifiBtn, &ButtonControl::clicked, [=]() { HardwareEon::launch_wifi(); });
list->addItem(wifiBtn);

auto tetheringBtn = new ButtonControl("Tethering Settings", "OPEN");
QObject::connect(tetheringBtn, &ButtonControl::clicked, [=]() { HardwareEon::launch_tethering(); });
list->addItem(tetheringBtn);
#endif
ipaddress = new LabelControl("IP Address", "");
list->addItem(ipaddress);

// SSH key management
list->addItem(new SshToggle());
list->addItem(new SshControl());

layout->addWidget(list);
layout->addStretch(1);
}

void C2NetworkPanel::showEvent(QShowEvent *event) {
ipaddress->setText(getIPAddress());
}

QString C2NetworkPanel::getIPAddress() {
std::string result = util::check_output("ifconfig wlan0");
if (result.empty()) return "";

const std::string inetaddrr = "inet addr:";
std::string::size_type begin = result.find(inetaddrr);
if (begin == std::string::npos) return "";

begin += inetaddrr.length();
std::string::size_type end = result.find(' ', begin);
if (end == std::string::npos) return "";

return result.substr(begin, end - begin).c_str();
}

QWidget *network_panel(QWidget *parent) {
#ifdef QCOM
return new C2NetworkPanel(parent);
#else
Networking *w = new Networking(parent);
return new Networking(parent);
#endif
return w;
}

void SettingsWindow::showEvent(QShowEvent *event) {
Expand Down
11 changes: 11 additions & 0 deletions selfdrive/ui/qt/offroad/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ class SoftwarePanel : public ListWidget {
Params params;
QFileSystemWatcher *fs_watch;
};

class C2NetworkPanel: public QWidget {
Q_OBJECT
public:
explicit C2NetworkPanel(QWidget* parent = nullptr);

private:
void showEvent(QShowEvent *event) override;
QString getIPAddress();
LabelControl *ipaddress;
};

0 comments on commit 084ef39

Please sign in to comment.