Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup: detailed error messages #27429

Merged
merged 13 commits into from
Feb 24, 2023
96 changes: 83 additions & 13 deletions selfdrive/ui/qt/setup/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool is_elf(char *fname) {
void Setup::download(QString url) {
CURL *curl = curl_easy_init();
if (!curl) {
emit finished(false);
emit finished(DownloadResult::error, url);
return;
}

Expand All @@ -57,16 +57,19 @@ void Setup::download(QString url) {
int ret = curl_easy_perform(curl);
long res_status = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res_status);
if (ret == CURLE_OK && res_status == 200 && is_elf(tmpfile)) {

if (ret != CURLE_OK || res_status != 200) {
emit finished(DownloadResult::error, url);
} else if (!is_elf(tmpfile)) {
emit finished(DownloadResult::notExecutable, url);
} else {
rename(tmpfile, "/tmp/installer");

FILE *fp_url = fopen("/tmp/installer_url", "w");
fprintf(fp_url, "%s", url.toStdString().c_str());
fclose(fp_url);

emit finished(true);
} else {
emit finished(false);
emit finished(DownloadResult::ok, url);
}

curl_slist_free_all(list);
Expand Down Expand Up @@ -276,7 +279,7 @@ QWidget * Setup::download_failed() {
restart->setProperty("primary", true);
blayout->addWidget(restart);
QObject::connect(restart, &QPushButton::clicked, this, [=]() {
setCurrentIndex(2);
setCurrentIndex(1);
});

widget->setStyleSheet(R"(
Expand All @@ -287,6 +290,61 @@ QWidget * Setup::download_failed() {
return widget;
}

QWidget * Setup::download_invalid_url(QLabel *url) {
QWidget *widget = new QWidget();
QVBoxLayout *main_layout = new QVBoxLayout(widget);
main_layout->setContentsMargins(55, 225, 55, 55);
main_layout->setSpacing(0);

QLabel *title = new QLabel(tr("Invalid Custom Software URL"));
title->setStyleSheet("font-size: 90px; font-weight: 500;");
main_layout->addWidget(title, 0, Qt::AlignTop | Qt::AlignLeft);

main_layout->addSpacing(67);

url->setWordWrap(true);
url->setAlignment(Qt::AlignTop | Qt::AlignLeft);
url->setStyleSheet("font-family: \"JetBrains Mono\"; font-size: 64px; font-weight: 400; margin-right: 100px;");
main_layout->addWidget(url);

main_layout->addSpacing(60);

QLabel *body = new QLabel(tr("No custom software found at this URL."));
body->setWordWrap(true);
body->setAlignment(Qt::AlignTop | Qt::AlignLeft);
body->setStyleSheet("font-size: 80px; font-weight: 300; margin-right: 100px;");
main_layout->addWidget(body);

main_layout->addStretch();

// reboot + start over buttons
QHBoxLayout *blayout = new QHBoxLayout();
blayout->setSpacing(50);
main_layout->addLayout(blayout, 0);

QPushButton *reboot = new QPushButton(tr("Reboot device"));
reboot->setObjectName("navBtn");
blayout->addWidget(reboot);
QObject::connect(reboot, &QPushButton::clicked, this, [=]() {
Hardware::reboot();
});

QPushButton *restart = new QPushButton(tr("Start over"));
restart->setObjectName("navBtn");
restart->setProperty("primary", true);
blayout->addWidget(restart);
QObject::connect(restart, &QPushButton::clicked, this, [=]() {
setCurrentIndex(1);
});

widget->setStyleSheet(R"(
QLabel {
margin-left: 117px;
}
)");
return widget;
}

void Setup::prevPage() {
setCurrentIndex(currentIndex() - 1);
}
Expand All @@ -312,13 +370,25 @@ Setup::Setup(QWidget *parent) : QStackedWidget(parent) {
failed_widget = download_failed();
addWidget(failed_widget);

QObject::connect(this, &Setup::finished, [=](bool success) {
// hide setup on success
qDebug() << "finished" << success;
if (success) {
QTimer::singleShot(3000, this, &QWidget::hide);
} else {
setCurrentWidget(failed_widget);
QLabel *url_label = new QLabel();
invalid_url_widget = download_invalid_url(url_label);
addWidget(invalid_url_widget);

QObject::connect(this, &Setup::finished, [=](const DownloadResult &result, const QString &url) {
qDebug() << "finished" << result << url;
switch (result) {
case DownloadResult::ok:
// hide setup on success
QTimer::singleShot(3000, this, &QWidget::hide);
break;
case DownloadResult::notExecutable:
url_label->setText(url);
setCurrentWidget(invalid_url_widget);
break;
case DownloadResult::error:
default:
setCurrentWidget(failed_widget);
break;
}
});

Expand Down
11 changes: 10 additions & 1 deletion selfdrive/ui/qt/setup/setup.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#pragma once

#include <QLabel>
#include <QStackedWidget>
#include <QString>
#include <QWidget>

enum DownloadResult {
ok,
notExecutable,
error,
};

class Setup : public QStackedWidget {
Q_OBJECT

Expand All @@ -16,12 +23,14 @@ class Setup : public QStackedWidget {
QWidget *network_setup();
QWidget *downloading();
QWidget *download_failed();
QWidget *download_invalid_url(QLabel *url);

QWidget *failed_widget;
QWidget *invalid_url_widget;
QWidget *downloading_widget;

signals:
void finished(bool success);
void finished(const DownloadResult &result, const QString &url);

public slots:
void nextPage();
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>Von neuem beginnen</translation>
</message>
<message>
<source>Invalid Custom Software URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>最初からやり直す</translation>
</message>
<message>
<source>Invalid Custom Software URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>다시 시작</translation>
</message>
<message>
<source>Invalid Custom Software URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>Inicializar</translation>
</message>
<message>
<source>Invalid Custom Software URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>重来</translation>
</message>
<message>
<source>Invalid Custom Software URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>重新開始</translation>
</message>
<message>
<source>Invalid Custom Software URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down