Compare commits

...

23 Commits

Author SHA1 Message Date
Jason Wen 62254e411b invoke platform selector on show event 2025-02-01 00:26:35 -05:00
Jason Wen 40df537d7a missed header 2025-02-01 00:19:44 -05:00
Jason Wen 2d60a61d5e bros 2025-02-01 00:05:59 -05:00
Jason Wen 7afc72942c add year list to bundle 2025-02-01 00:03:59 -05:00
Jason Wen 23ec81d67a move loadPlatformList to sp util 2025-01-31 23:57:16 -05:00
Jason Wen 9500489695 split set platform 2025-01-31 23:51:56 -05:00
Jason Wen 29d39ffe71 it's a json now 2025-01-31 23:42:59 -05:00
Jason Wen 726b3774b6 bump opendbc 2025-01-31 23:40:27 -05:00
Jason Wen 3f9502ca6b slight cleanup 2025-01-31 23:38:13 -05:00
Jason Wen 3a9d27b610 do not include dashcamOnly yet 2025-01-30 23:16:20 -05:00
Jason Wen b9b7e8b556 Fix name 2025-01-30 22:37:10 -05:00
Jason Wen b1315797c5 extract platform from CarPlatformBundle directly 2025-01-30 22:35:31 -05:00
Jason Wen 158eaf4dda introduce getPlatformBundle 2025-01-30 22:20:58 -05:00
Jason Wen 59afe4df1a pass all fields to a platform in json 2025-01-30 22:14:46 -05:00
Jason Wen 33e06a86f9 include all dashcamOnly platforms 2025-01-30 08:34:11 -05:00
Jason Wen 84e3a6d0ed add brand to parser 2025-01-30 00:37:35 -05:00
Jason Wen 25fa50b42c generate no car docs platforms 2025-01-30 00:31:42 -05:00
Jason Wen 1a67ce35ff start cleanup 2025-01-29 23:22:37 -05:00
Jason Wen ad131fef49 generate car.CarParams.brand in json 2025-01-29 23:20:52 -05:00
Jason Wen be0e64ab45 Merge branch 'master-new' into fcr 2025-01-27 22:50:21 -05:00
Jason Wen 767880ffaf ui: Display default driving model name (#623)
* ui: Display default driving model if in use

* add ref commit and tests

* fix commit

* update msg

* update msg

* fix lint

* use sha256 hash instead
2025-01-27 22:49:28 -05:00
Jason Wen 77ea048865 Encoding 2025-01-26 17:49:54 -05:00
Jason Wen 2c5753940b Need to be str 2025-01-26 08:24:29 -05:00
25 changed files with 205 additions and 113 deletions
+1
View File
@@ -0,0 +1 @@
#define DEFAULT_MODEL "Notre Dame (Default)"
+1 -2
View File
@@ -206,8 +206,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"CarParamsSP", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION},
{"CarParamsSPCache", CLEAR_ON_MANAGER_START},
{"CarParamsSPPersistent", PERSISTENT},
{"CarPlatform", PERSISTENT},
{"CarPlatformName", PERSISTENT},
{"CarPlatformBundle", PERSISTENT},
{"EnableGithubRunner", PERSISTENT | BACKUP},
{"ModelRunnerTypeCache", CLEAR_ON_ONROAD_TRANSITION},
{"OffroadMode", CLEAR_ON_MANAGER_START},
+2 -1
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import json
import os
import time
import threading
@@ -104,7 +105,7 @@ class Car:
with car.CarParams.from_bytes(cached_params_raw) as _cached_params:
cached_params = _cached_params
fixed_fingerprint = self.params.get("CarPlatform")
fixed_fingerprint = json.loads(self.params.get("CarPlatformBundle", encoding='utf-8') or "{}").get("platform", None)
self.CI = get_car(*self.can_callbacks, obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params, fixed_fingerprint)
interfaces.setup_car_interface_sp(self.CI.CP, self.CI.CP_SP, self.params)
@@ -10,6 +10,8 @@
#include <algorithm>
#include <QJsonDocument>
#include "common/model.h"
/**
* @brief Constructs the software panel with model bundle selection functionality
* @param parent Parent widget
@@ -105,7 +107,7 @@ QString SoftwarePanelSP::GetActiveModelName() {
return QString::fromStdString(model_manager.getActiveBundle().getDisplayName());
}
return "";
return DEFAULT_MODEL;
}
void SoftwarePanelSP::updateModelManagerState() {
@@ -7,14 +7,27 @@
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h"
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QMap>
#include "selfdrive/ui/sunnypilot/qt/util.h"
QVariant PlatformSelector::getPlatformBundle(const QString &key) {
QString platform_bundle = QString::fromStdString(params.get("CarPlatformBundle"));
if (!platform_bundle.isEmpty()) {
QJsonDocument json = QJsonDocument::fromJson(platform_bundle.toUtf8());
if (!json.isNull() && json.isObject()) {
return json.object().value(key).toVariant();
}
}
return {};
}
PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") {
platforms = loadPlatformList();
QObject::connect(this, &ButtonControl::clicked, [=]() {
if (text() == tr("SEARCH")) {
QString query = InputDialog::getText(tr("Search your vehicle"), this, tr("Enter model year (e.g., 2021) and model name (Toyota Corolla):"), false);
@@ -25,8 +38,7 @@ PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") {
refresh(offroad);
}
} else {
params.remove("CarPlatform");
params.remove("CarPlatformName");
params.remove("CarPlatformBundle");
refresh(offroad);
}
});
@@ -35,57 +47,45 @@ PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") {
}
void PlatformSelector::refresh(bool _offroad) {
QString platform_param = QString::fromStdString(params.get("CarPlatform"));
if (platform_param.length()) {
setValue(QString::fromStdString(params.get("CarPlatformName")));
setText("REMOVE");
} else {
setValue("");
setText("SEARCH");
}
QString name = getPlatformBundle("name").toString();
setValue(name);
setText(name.isEmpty() ? tr("SEARCH") : tr("REMOVE"));
setEnabled(true);
offroad = _offroad;
}
QMap<QString, QVariantMap> PlatformSelector::loadPlatformList() {
QMap<QString, QVariantMap> platforms;
void PlatformSelector::setPlatform(const QString &platform) {
QVariantMap platform_data = platforms[platform];
std::string json_data = util::read_file("../../sunnypilot/selfdrive/car/car_list.json").c_str();
const QString offroad_msg = offroad ? tr("This setting will take effect immediately.") :
tr("This setting will take effect once the device enters offroad state.");
const QString msg = QString("<b>%1</b><br><br>%2")
.arg(platform, offroad_msg);
if (json_data.empty()) {
return platforms;
}
QString content("<body><h2 style=\"text-align: center;\">" + tr("Vehicle Selector") + "</h2><br>"
"<p style=\"text-align: center; margin: 0 128px; font-size: 50px;\">" + msg + "</p></body>");
QJsonParseError json_error;
QJsonDocument doc = QJsonDocument::fromJson(QString::fromStdString(json_data).toUtf8(), &json_error);
if (doc.isNull()) {
return platforms;
}
if (ConfirmationDialog(content, tr("Confirm"), tr("Cancel"), true, this).exec()) {
QJsonObject json_bundle;
json_bundle["platform"] = platform_data["platform"].toString();
json_bundle["name"] = platform;
json_bundle["make"] = platform_data["make"].toString();
json_bundle["brand"] = platform_data["brand"].toString();
json_bundle["model"] = platform_data["model"].toString();
json_bundle["package"] = platform_data["package"].toString();
if (doc.isObject()) {
QJsonObject obj = doc.object();
for (const QString &key : obj.keys()) {
QJsonObject attributes = obj.value(key).toObject();
QVariantMap platform_data;
QJsonArray yearArray = attributes.value("year").toArray();
QVariantList yearList;
for (const QJsonValue &year : yearArray) {
yearList.append(year.toString());
}
platform_data["year"] = yearList;
platform_data["make"] = attributes.value("make").toString();
platform_data["model"] = attributes.value("model").toString();
platform_data["platform"] = attributes.value("platform").toString();
platform_data["package"] = attributes.value("package").toString();
platforms[key] = platform_data;
QVariantList yearList = platform_data["year"].toList();
QJsonArray yearArray;
for (const QVariant &year : yearList) {
yearArray.append(year.toString());
}
}
json_bundle["year"] = yearArray;
return platforms;
QString json_bundle_str = QString::fromUtf8(QJsonDocument(json_bundle).toJson(QJsonDocument::Compact));
params.put("CarPlatformBundle", json_bundle_str.toStdString());
}
}
void PlatformSelector::searchPlatforms(const QString &query) {
@@ -93,7 +93,6 @@ void PlatformSelector::searchPlatforms(const QString &query) {
return;
}
QMap<QString, QVariantMap> platforms = loadPlatformList();
QSet<QString> matched_cars;
QString normalized_query = query.simplified().toLower();
@@ -183,20 +182,6 @@ void PlatformSelector::searchPlatforms(const QString &query) {
QString selected_platform = MultiOptionDialog::getSelection(tr("Select a vehicle"), results, "", this);
if (!selected_platform.isEmpty()) {
QVariantMap platform_data = platforms[selected_platform];
const QString offroad_msg = offroad ? tr("This setting will take effect immediately.") :
tr("This setting will take effect once the device enters offroad state.");
const QString msg = QString("<b>%1</b><br><br>%2")
.arg(selected_platform)
.arg(offroad_msg);
QString content("<body><h2 style=\"text-align: center;\">" + tr("Vehicle Selector") + "</h2><br>"
"<p style=\"text-align: center; margin: 0 128px; font-size: 50px;\">" + msg + "</p></body>");
if (ConfirmationDialog(content, tr("Confirm"), tr("Cancel"), true, this).exec()) {
params.put("CarPlatform", platform_data["platform"].toString().toStdString());
params.put("CarPlatformName", selected_platform.toStdString());
}
setPlatform(selected_platform);
}
}
@@ -14,13 +14,15 @@ class PlatformSelector : public ButtonControl {
public:
PlatformSelector();
QVariant getPlatformBundle(const QString &key);
public slots:
void refresh(bool _offroad);
private:
void searchPlatforms(const QString &query);
QMap<QString, QVariantMap> loadPlatformList();
void setPlatform(const QString &platform = "");
QMap<QString, QVariantMap> platforms;
Params params;
bool offroad;
@@ -23,8 +23,18 @@ VehiclePanel::VehiclePanel(QWidget *parent) : QFrame(parent) {
ScrollViewSP *scroller = new ScrollViewSP(list, this);
vlayout->addWidget(scroller);
QObject::connect(uiState(), &UIState::offroadTransition, platformSelector, &PlatformSelector::refresh);
QObject::connect(uiState(), &UIState::offroadTransition, this, &VehiclePanel::updatePanel);
main_layout->addWidget(vehicleScreen);
main_layout->setCurrentWidget(vehicleScreen);
}
void VehiclePanel::showEvent(QShowEvent *event) {
updatePanel(offroad);
}
void VehiclePanel::updatePanel(bool _offroad) {
platformSelector->refresh(_offroad);
offroad = _offroad;
}
@@ -16,9 +16,14 @@ class VehiclePanel : public QFrame {
public:
explicit VehiclePanel(QWidget *parent = nullptr);
void showEvent(QShowEvent *event) override;
public slots:
void updatePanel(bool _offroad);
private:
QStackedLayout* main_layout = nullptr;
QWidget* vehicleScreen = nullptr;
PlatformSelector *platformSelector = nullptr;
bool offroad;
};
+45
View File
@@ -12,8 +12,12 @@
#include <vector>
#include <QDir>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLayoutItem>
#include <QPainterPath>
#include <QVariant>
#include "system/hardware/hw.h"
@@ -33,3 +37,44 @@ QString getUserAgent(bool sunnylink) {
std::optional<QString> getSunnylinkDongleId() {
return getParamIgnoringDefault("SunnylinkDongleId", "UnregisteredDevice");
}
QMap<QString, QVariantMap> loadPlatformList() {
QMap<QString, QVariantMap> _platforms;
std::string json_data = util::read_file("../../sunnypilot/selfdrive/car/car_list.json");
if (json_data.empty()) {
return _platforms;
}
QJsonParseError json_error{};
QJsonDocument doc = QJsonDocument::fromJson(QString::fromStdString(json_data).toUtf8(), &json_error);
if (doc.isNull()) {
return _platforms;
}
if (doc.isObject()) {
QJsonObject obj = doc.object();
for (const QString &key : obj.keys()) {
QJsonObject attributes = obj.value(key).toObject();
QVariantMap platform_data;
QJsonArray yearArray = attributes.value("year").toArray();
QVariantList yearList;
for (const QJsonValue &year : yearArray) {
yearList.append(year.toString());
}
platform_data["year"] = yearList;
platform_data["make"] = attributes.value("make").toString();
platform_data["brand"] = attributes.value("brand").toString();
platform_data["model"] = attributes.value("model").toString();
platform_data["platform"] = attributes.value("platform").toString();
platform_data["package"] = attributes.value("package").toString();
_platforms[key] = platform_data;
}
}
return _platforms;
}
+2
View File
@@ -10,9 +10,11 @@
#include <optional>
#include <vector>
#include <QMap>
#include <QPainter>
#include <QWidget>
QString getUserAgent(bool sunnylink = false);
std::optional<QString> getSunnylinkDongleId();
std::optional<QString> getParamIgnoringDefault(const std::string &param_name, const std::string &default_value);
QMap<QString, QVariantMap> loadPlatformList();
+7 -2
View File
@@ -1,5 +1,6 @@
from collections import namedtuple
import capnp
import json
import pathlib
import shutil
import sys
@@ -220,8 +221,12 @@ def setup_settings_trips(click, pm: PubMaster, scroll=None):
time.sleep(UI_DELAY)
def setup_settings_vehicle(click, pm: PubMaster, scroll=None):
Params().put("CarPlatform", "HONDA_CIVIC_2022")
Params().put("CarPlatformName", "Honda Civic 2022-24")
Params().put("CarPlatformBundle", json.dumps(
{
"platform": "HONDA_CIVIC_2022",
"name": "Honda Civic 2022-24"
}
))
setup_settings_device(click, pm)
scroll(-400, 278, 862)
+4 -4
View File
@@ -716,10 +716,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete">موافق</translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished">تأكيد</translation>
@@ -728,6 +724,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished">إلغاء</translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished">إزالة</translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -711,10 +711,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete">Ok</translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished">Bestätigen</translation>
@@ -723,6 +719,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished">Abbrechen</translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished">LÖSCHEN</translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -712,10 +712,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete">OK</translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished">Confirmar</translation>
@@ -724,6 +720,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished">Cancelar</translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished">ELIMINAR</translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -712,10 +712,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete">Ok</translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished">Confirmer</translation>
@@ -724,6 +720,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished">Annuler</translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished">SUPPRIMER</translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -711,10 +711,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete">OK</translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished"></translation>
@@ -723,6 +719,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -711,10 +711,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished"></translation>
@@ -723,6 +719,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -712,10 +712,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete">OK</translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished">Confirmar</translation>
@@ -724,6 +720,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished">Cancelar</translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished">REMOVER</translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -711,10 +711,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished"></translation>
@@ -723,6 +719,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -710,10 +710,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete">Tamam</translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished">Onayla</translation>
@@ -722,6 +718,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished">KALDIR</translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -711,10 +711,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished"></translation>
@@ -723,6 +719,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+4 -4
View File
@@ -711,10 +711,6 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>This setting will take effect immediately.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ok</source>
<translation type="obsolete"></translation>
</message>
<message>
<source>Confirm</source>
<translation type="unfinished"></translation>
@@ -723,6 +719,10 @@ Pause Steering: ALC will be paused after the brake pedal is manually pressed.</s
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PrimeAdWidget</name>
+1
View File
@@ -0,0 +1 @@
39786068cae1ed8c0dc34ef80c281dfcc67ed18a50e06b90765c49bcfdbf7db4
@@ -0,0 +1,34 @@
import os
import hashlib
from openpilot.common.basedir import BASEDIR
MODEL_HASH_DIR = os.path.dirname(os.path.abspath(__file__))
class TestDefaultModel:
@classmethod
def setup_class(cls):
cls.onnx_path = os.path.join(BASEDIR, "selfdrive", "modeld", "models", "supercombo.onnx")
cls.current_hash_path = os.path.join(MODEL_HASH_DIR, "model_hash")
@staticmethod
def get_hash(path: str) -> str:
sha256_hash = hashlib.sha256()
with open(path, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
def test_compare_onnx_hashes(self):
new_hash = self.get_hash(str(self.onnx_path))
with open(self.current_hash_path) as f:
current_hash = f.read().strip()
assert new_hash == current_hash, (
"Driving model updated!\n" +
f"Current hash: {current_hash}\n" +
f"New hash: {new_hash}\n" +
"Please update common/model.h if the default driving model name has changed."
)