From 919f3d1c745885c915d81f4601549dd91da64005 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sat, 6 Apr 2024 11:35:44 +0000 Subject: [PATCH 01/13] Lots of stabilization improvments for the model fetcher --- .../qt/offroad/sunnypilot/models_fetcher.cc | 26 +++++- .../sunnypilot/software_settings_sp.cc | 79 ++++++++++--------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/selfdrive/ui/qt/offroad/sunnypilot/models_fetcher.cc b/selfdrive/ui/qt/offroad/sunnypilot/models_fetcher.cc index 4f2aaf724f..f45aa55e5c 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot/models_fetcher.cc +++ b/selfdrive/ui/qt/offroad/sunnypilot/models_fetcher.cc @@ -1,4 +1,5 @@ #include "selfdrive/ui/qt/offroad/sunnypilot/models_fetcher.h" +#include ModelsFetcher::ModelsFetcher(QObject* parent) : QObject(parent) { manager = new QNetworkAccessManager(this); @@ -83,9 +84,30 @@ void ModelsFetcher::onFinished(QNetworkReply* reply, const QString& destinationP QString finalPath = QDir(destinationPath).filePath(finalFilename); // Save the downloaded file + + QFile file(finalPath); - if (!file.open(QIODevice::WriteOnly)) { - return; // Consider emitting a signal or logging an error here as well + //ensure if the path exists and if not create it + if(!QDir().mkpath(destinationPath)) + { + LOGE("Unable to create directory: %s", destinationPath.toStdString().c_str()); + emit downloadFailed(filename); + return; // Stop further processing + } + + //Retry the file open and write 3 times with a little delay between each retry + for (int i = 0; i < 3; i++) { + if (file.isOpen()) break; + + file.open(QIODevice::WriteOnly); + if (!file.isOpen()) QThread::msleep(100); + } + + // If the file is still not open, log an error and emit a failure signal + if (!file.isOpen()) { + LOGE("Unable to open file for writing: %s", finalPath.toStdString().c_str()); + emit downloadFailed(filename); + return; // Stop further processing } file.write(data); diff --git a/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc b/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc index f288170054..9727bcc2f3 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc +++ b/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc @@ -18,19 +18,41 @@ SoftwarePanelSP::SoftwarePanelSP(QWidget *parent) : SoftwarePanel(parent) { handleDownloadProgress(progress, "metadata"); }); - connect(&models_fetcher, &ModelsFetcher::downloadComplete, this, [this](const QByteArray&data, bool fromCache = false) { + connect(&models_fetcher, &ModelsFetcher::downloadComplete, this, [this](const QByteArray& data, bool fromCache) { modelFromCache = fromCache; - updateLabels(); + if (!isDownloadingModel() && modelDownloadProgress.has_value()) { + params.put("DrivingModelText", selectedModelToDownload->fullName.toStdString()); + params.put("DrivingModelName", selectedModelToDownload->displayName.toStdString()); + selectedModelToDownload.reset(); + modelDownloadProgress.reset(); + params.putBool("CustomDrivingModel", !model_download_failed); + } + nav_models_fetcher.download(selectedNavModelToDownload->downloadUriNav, selectedNavModelToDownload->fileNameNav); + HandleModelDownloadProgressReport(); }); connect(&nav_models_fetcher, &ModelsFetcher::downloadComplete, this, [this](const QByteArray&data, bool fromCache = false) { navModelFromCache = fromCache; - updateLabels(); + if (!isDownloadingNavModel() && navModelDownloadProgress.has_value()) { + params.put("DrivingModelGeneration", selectedNavModelToDownload->generation.toStdString()); + params.put("NavModelText", selectedNavModelToDownload->fullNameNav.toStdString()); + selectedNavModelToDownload.reset(); + navModelDownloadProgress.reset(); + } + metadata_fetcher.download(selectedMetadataToDownload->downloadUriMetadata, selectedMetadataToDownload->fileNameMetadata); + HandleModelDownloadProgressReport(); + // updateLabels(); }); connect(&metadata_fetcher, &ModelsFetcher::downloadComplete, this, [this](const QByteArray&data, bool fromCache = false) { metadataFromCache = fromCache; - updateLabels(); + if (!isDownloadingMetadata() && metadataDownloadProgress.has_value()) { + params.put("DrivingModelMetadataText", selectedMetadataToDownload->fullNameMetadata.toStdString()); + selectedMetadataToDownload.reset(); + metadataDownloadProgress.reset(); + } + HandleModelDownloadProgressReport(); + // updateLabels(); }); connect(&models_fetcher, &ModelsFetcher::downloadFailed, this, &SoftwarePanelSP::handleDownloadFailed); @@ -151,37 +173,6 @@ void SoftwarePanelSP::HandleModelDownloadProgressReport() { currentModelLblBtn->showDescription(); currentModelLblBtn->setEnabled( !(is_onroad || (isDownloadingModel() || isDownloadingMetadata() || isDownloadingNavModel()))); - - // If not downloading and there is a selected model, update parameters - if (!isDownloadingModel() && modelDownloadProgress.has_value()) { - params.put("DrivingModelText", selectedModelToDownload->fullName.toStdString()); - params.put("DrivingModelName", selectedModelToDownload->displayName.toStdString()); - //params.put("DrivingModelUrl", selectedModelToDownload->downloadUri.toStdString()); // TODO: Placeholder for future implementation - LOGD("Resetting selectedModelToDownload"); - selectedModelToDownload.reset(); - modelDownloadProgress.reset(); - modelFromCache = false; - params.putBool("CustomDrivingModel", !model_download_failed); - } - - // If not downloading and there is a selected model, update parameters - if (!isDownloadingNavModel() && navModelDownloadProgress.has_value()) { - params.put("DrivingModelGeneration", selectedNavModelToDownload->generation.toStdString()); - params.put("NavModelText", selectedNavModelToDownload->fullNameNav.toStdString()); - LOGD("Resetting selectedNavModelToDownload"); - selectedNavModelToDownload.reset(); - navModelDownloadProgress.reset(); - navModelFromCache = false; - } - - if (!isDownloadingMetadata() && metadataDownloadProgress.has_value()) { - params.put("DrivingModelMetadataText", selectedMetadataToDownload->fullNameMetadata.toStdString()); - LOGD("Resetting selectedMetadataToDownload"); - selectedMetadataToDownload.reset(); - metadataDownloadProgress.reset(); - metadataFromCache = false; - } - } void SoftwarePanelSP::handleCurrentModelLblBtnClicked() { @@ -240,14 +231,24 @@ void SoftwarePanelSP::handleCurrentModelLblBtnClicked() { model_download_failed = false; currentModelLblBtn->setValue(selectedModelToDownload->displayName); currentModelLblBtn->setDescription(selectedModelToDownload->displayName); + + // So we reset the cache status + modelFromCache = false; + navModelFromCache = false; + metadataFromCache = false; + + // So we can signal them as pending + navModelDownloadProgress = 0.01; + modelDownloadProgress = 0.01; + metadataDownloadProgress = 0.01; + + //Start the download, we download the other models on emit of downloadComplete + if(params.get("DrivingModelGeneration") != selectedModelToDownload->generation.toStdString()) + showResetParamsDialog(); models_fetcher.download(selectedModelToDownload->downloadUri, selectedModelToDownload->fileName); - nav_models_fetcher.download(selectedNavModelToDownload->downloadUriNav, selectedNavModelToDownload->fileNameNav); - metadata_fetcher.download(selectedMetadataToDownload->downloadUriMetadata, - selectedMetadataToDownload->fileNameMetadata); // Disable select button until download completes currentModelLblBtn->setEnabled(false); - showResetParamsDialog(); } updateLabels(); } From 2d73059d79d48b935ae120803045d78360c681e0 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 6 Apr 2024 13:23:34 +0000 Subject: [PATCH 02/13] sunnylink: Set User Agent to sunnypilot --- selfdrive/ui/qt/api.cc | 2 +- selfdrive/ui/qt/util.cc | 4 ++-- selfdrive/ui/qt/util.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/qt/api.cc b/selfdrive/ui/qt/api.cc index bcde113215..80049fca05 100644 --- a/selfdrive/ui/qt/api.cc +++ b/selfdrive/ui/qt/api.cc @@ -216,7 +216,7 @@ void HttpRequest::sendRequest(const QString &requestURL, const HttpRequest::Meth QNetworkRequest request; request.setUrl(QUrl(requestURL)); - request.setRawHeader("User-Agent", getUserAgent().toUtf8()); + request.setRawHeader("User-Agent", getUserAgent(sunnylink).toUtf8()); if (!payload.isEmpty()) { request.setRawHeader("Content-Type", "application/json"); } diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index 9f567a68d8..3e1c26c65f 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -29,8 +29,8 @@ QString getBrand() { return QObject::tr("sunnypilot"); } -QString getUserAgent() { - return "openpilot-" + getVersion(); +QString getUserAgent(bool sunnylink) { + return (sunnylink ? "sunnypilot-" : "openpilot-") + getVersion(); } std::optional getDongleId() { diff --git a/selfdrive/ui/qt/util.h b/selfdrive/ui/qt/util.h index 21507bfb1f..438b9677e7 100644 --- a/selfdrive/ui/qt/util.h +++ b/selfdrive/ui/qt/util.h @@ -15,7 +15,7 @@ QString getVersion(); QString getBrand(); -QString getUserAgent(); +QString getUserAgent(bool sunnylink = false); std::optional getDongleId(); std::optional getSunnylinkDongleId(); QMap getSupportedLanguages(); From 6a8f434627235d22a1b66d4fbbb78795cf91447a Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 6 Apr 2024 09:25:36 -0400 Subject: [PATCH 03/13] Map: Add back `enabled` for navigation path color change --- selfdrive/ui/qt/maps/map.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index 3d6e35f383..c00e38bc78 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -165,7 +165,7 @@ void MapWindow::updateState(const UIState &s) { // set path color on change, and show map on rising edge of navigate on openpilot auto car_control = sm["carControl"].getCarControl(); bool nav_enabled = sm["modelV2"].getModelV2().getNavEnabled() && - (car_control.getLatActive() || car_control.getLongActive()); + (sm["controlsState"].getControlsState().getEnabled() || car_control.getLatActive() || car_control.getLongActive()); if (nav_enabled != uiState()->scene.navigate_on_openpilot) { if (loaded_once) { m_map->setPaintProperty("navLayer", "line-color", getNavPathColor(nav_enabled)); From 7e3f8091c232717f5268a329e5356376dd55b000 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sat, 6 Apr 2024 16:17:21 +0000 Subject: [PATCH 04/13] ui: Network refresh button --- selfdrive/ui/qt/network/networking.cc | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/selfdrive/ui/qt/network/networking.cc b/selfdrive/ui/qt/network/networking.cc index 1924cbf0fe..e86d0c6a89 100644 --- a/selfdrive/ui/qt/network/networking.cc +++ b/selfdrive/ui/qt/network/networking.cc @@ -26,17 +26,29 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QFrame(parent) { wifiScreen = new QWidget(this); QVBoxLayout* vlayout = new QVBoxLayout(wifiScreen); vlayout->setContentsMargins(20, 20, 20, 20); + QHBoxLayout* hlayout = new QHBoxLayout(); + QPushButton* scanButton = new QPushButton(tr("Scan")); + scanButton->setObjectName("scan_btn"); + scanButton->setFixedSize(400, 100); + connect(wifi, &WifiManager::refreshSignal, this, [=]() { scanButton->setText(tr("Scan")); scanButton->setEnabled(true); }); + connect(scanButton, &QPushButton::clicked, [=]() { scanButton->setText(tr("Scanning...")); scanButton->setEnabled(false); wifi->requestScan(); }); + + hlayout->addWidget(scanButton); + hlayout->addStretch(1); // Pushes the button all the way to the left + if (show_advanced) { + hlayout->setSpacing(10); + QPushButton* advancedSettings = new QPushButton(tr("Advanced")); advancedSettings->setObjectName("advanced_btn"); - advancedSettings->setStyleSheet("margin-right: 30px;"); advancedSettings->setFixedSize(400, 100); connect(advancedSettings, &QPushButton::clicked, [=]() { main_layout->setCurrentWidget(an); }); - vlayout->addSpacing(10); - vlayout->addWidget(advancedSettings, 0, Qt::AlignRight); - vlayout->addSpacing(10); + hlayout->addWidget(advancedSettings); } + vlayout->addLayout(hlayout); + vlayout->addSpacing(10); + wifiWidget = new WifiUI(this, wifi); wifiWidget->setObjectName("wifiWidget"); connect(wifiWidget, &WifiUI::connectToNetwork, this, &Networking::connectToNetwork); @@ -57,7 +69,7 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QFrame(parent) { setPalette(pal); setStyleSheet(R"( - #wifiWidget > QPushButton, #back_btn, #advanced_btn { + #wifiWidget > QPushButton, #back_btn, #advanced_btn, #scan_btn{ font-size: 50px; margin: 0px; padding: 15px; @@ -66,7 +78,7 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QFrame(parent) { color: #dddddd; background-color: #393939; } - #back_btn:pressed, #advanced_btn:pressed { + #back_btn:pressed, #advanced_btn:pressed, #scan_btn:pressed { background-color: #4a4a4a; } )"); From 913f32a15c5b5f74bfa13dc238ee2bfd574b9cee Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sat, 6 Apr 2024 16:18:29 +0000 Subject: [PATCH 05/13] ui: Driving Model Selector description fixes --- .../offroad/sunnypilot/software_settings_sp.cc | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc b/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc index 9727bcc2f3..ec72e71a78 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc +++ b/selfdrive/ui/qt/offroad/sunnypilot/software_settings_sp.cc @@ -129,38 +129,32 @@ void SoftwarePanelSP::HandleModelDownloadProgressReport() { // Driving model status if (isDownloadingModel()) { description += QString(tr("Downloading Driving model") + " [%1]... (%2%)") - .arg(drivingModelName) - .arg(QString::number(modelDownloadProgress.value_or(0.0), 'f', 2)); + .arg(drivingModelName, QString::number(modelDownloadProgress.value_or(0.0), 'f', 2)); } else { if (modelFromCache) drivingModelName += QString(" " + tr("(CACHED)")); - description += QString(tr("Driving model") + " [%1] " + tr("downloaded") - .arg(drivingModelName)); + description += QString(tr("Driving model") + " [%1] " + tr("downloaded")).arg(drivingModelName); } // Navigation model status if (isDownloadingNavModel()) { if (!description.isEmpty()) description += "\n"; // Add newline if driving model status is already appended description += QString(tr("Downloading Navigation model") + " [%1]... (%2%)") - .arg(navModelName) - .arg(QString::number(navModelDownloadProgress.value_or(0.0), 'f', 2)); + .arg(navModelName, QString::number(navModelDownloadProgress.value_or(0.0), 'f', 2)); } else { if (navModelFromCache) navModelName += QString(" " + tr("(CACHED)")); if (!description.isEmpty()) description += "\n"; // Ensure newline separation - description += QString(tr("Navigation model") + " [%1] " + tr("downloaded") - .arg(navModelName)); + description += QString(tr("Navigation model") + " [%1] " + tr("downloaded")).arg(navModelName); } // Metadata status if (isDownloadingMetadata()) { if (!description.isEmpty()) description += "\n"; description += QString(tr("Downloading Metadata model") + " [%1]... (%2%)") - .arg(metadataName) - .arg(QString::number(metadataDownloadProgress.value_or(0.0), 'f', 2)); + .arg(metadataName, QString::number(metadataDownloadProgress.value_or(0.0), 'f', 2)); } else { if (metadataFromCache) metadataName += QString(" " + tr("(CACHED)")); if (!description.isEmpty()) description += "\n"; - description += QString(tr("Metadata model") + " [%1] " + tr("downloaded") - .arg(metadataName)); + description += QString(tr("Metadata model") + " [%1] " + tr("downloaded")).arg(metadataName); } if (model_download_failed) { From 271968e76339f53aea5cc510809e365e575e7a47 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 8 Apr 2024 14:15:16 -0400 Subject: [PATCH 06/13] ui: Only build installers on comma devices --- selfdrive/ui/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index fe1831f505..4c4d3e2dab 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -102,7 +102,7 @@ if GetOption('extras'): qt_env.Program('tests/ui_snapshot', [asset_obj, "tests/ui_snapshot.cc"] + qt_src, LIBS=qt_libs) -if GetOption('extras') and arch != "Darwin": +if GetOption('extras') and arch in ['larch64']: # setup and factory resetter qt_env.Program("qt/setup/reset", ["qt/setup/reset.cc"], LIBS=qt_libs) qt_env.Program("qt/setup/setup", ["qt/setup/setup.cc", asset_obj], From e1c4ab01a96ce973ddcdcce8036fc4d64dc35b2d Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 8 Apr 2024 14:18:57 -0400 Subject: [PATCH 07/13] Clion: Some updates --- .idea/tools/External Tools.xml | 14 ++++++++++++++ .run/Build Debug.run.xml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.idea/tools/External Tools.xml b/.idea/tools/External Tools.xml index 75b33a6fd7..92f206447d 100644 --- a/.idea/tools/External Tools.xml +++ b/.idea/tools/External Tools.xml @@ -20,4 +20,18 @@