Force fingerprint function
Added function to automatically detect the vehicle's fingerprint if it exists, or an option to force the vehicle's fingerprint if it doesn't.
This commit is contained in:
@@ -222,6 +222,8 @@ std::unordered_map<std::string, uint32_t> keys = {
|
|||||||
{"ApiCache_DriveStats", PERSISTENT},
|
{"ApiCache_DriveStats", PERSISTENT},
|
||||||
{"BlindSpotPath", PERSISTENT},
|
{"BlindSpotPath", PERSISTENT},
|
||||||
{"CameraView", PERSISTENT},
|
{"CameraView", PERSISTENT},
|
||||||
|
{"CarMake", PERSISTENT},
|
||||||
|
{"CarModel", PERSISTENT},
|
||||||
{"CECurves", PERSISTENT},
|
{"CECurves", PERSISTENT},
|
||||||
{"CECurvesLead", PERSISTENT},
|
{"CECurvesLead", PERSISTENT},
|
||||||
{"CENavigation", PERSISTENT},
|
{"CENavigation", PERSISTENT},
|
||||||
@@ -261,6 +263,7 @@ std::unordered_map<std::string, uint32_t> keys = {
|
|||||||
{"ExperimentalModeViaScreen", PERSISTENT},
|
{"ExperimentalModeViaScreen", PERSISTENT},
|
||||||
{"FireTheBabysitter", PERSISTENT},
|
{"FireTheBabysitter", PERSISTENT},
|
||||||
{"ForceAutoTune", PERSISTENT},
|
{"ForceAutoTune", PERSISTENT},
|
||||||
|
{"ForceFingerprint", PERSISTENT},
|
||||||
{"FrogPilotTogglesUpdated", PERSISTENT},
|
{"FrogPilotTogglesUpdated", PERSISTENT},
|
||||||
{"FrogsGoMoo", PERSISTENT},
|
{"FrogsGoMoo", PERSISTENT},
|
||||||
{"GoatScream", PERSISTENT},
|
{"GoatScream", PERSISTENT},
|
||||||
|
|||||||
@@ -194,13 +194,23 @@ def fingerprint(logcan, sendcan, num_pandas):
|
|||||||
|
|
||||||
def get_car(logcan, sendcan, experimental_long_allowed, num_pandas=1):
|
def get_car(logcan, sendcan, experimental_long_allowed, num_pandas=1):
|
||||||
params = Params()
|
params = Params()
|
||||||
|
car_brand = params.get("CarMake", encoding='utf-8')
|
||||||
|
car_model = params.get("CarModel", encoding='utf-8')
|
||||||
dongle_id = params.get("DongleId", encoding='utf-8')
|
dongle_id = params.get("DongleId", encoding='utf-8')
|
||||||
|
|
||||||
|
force_fingerprint = params.get_bool("ForceFingerprint")
|
||||||
|
|
||||||
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(logcan, sendcan, num_pandas)
|
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(logcan, sendcan, num_pandas)
|
||||||
|
|
||||||
if candidate is None:
|
if candidate is None or force_fingerprint:
|
||||||
cloudlog.event("car doesn't match any fingerprints", fingerprints=repr(fingerprints), error=True)
|
if car_model is not None:
|
||||||
candidate = "mock"
|
candidate = car_model
|
||||||
|
else:
|
||||||
|
cloudlog.event("car doesn't match any fingerprints", fingerprints=repr(fingerprints), error=True)
|
||||||
|
candidate = "mock"
|
||||||
|
elif car_model is None:
|
||||||
|
params.put("CarMake", candidate.split(' ')[0].title())
|
||||||
|
params.put("CarModel", candidate)
|
||||||
|
|
||||||
if get_short_branch() == "FrogPilot-Development" and not Params("/persist/comma/params").get_bool("FrogsGoMoo"):
|
if get_short_branch() == "FrogPilot-Development" and not Params("/persist/comma/params").get_bool("FrogsGoMoo"):
|
||||||
candidate = "mock"
|
candidate = "mock"
|
||||||
|
|||||||
@@ -1,6 +1,103 @@
|
|||||||
|
#include <QDir>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
#include "selfdrive/frogpilot/ui/vehicle_settings.h"
|
#include "selfdrive/frogpilot/ui/vehicle_settings.h"
|
||||||
|
|
||||||
|
QStringList getCarNames(const QString &carMake) {
|
||||||
|
QMap<QString, QString> makeMap;
|
||||||
|
makeMap["acura"] = "honda";
|
||||||
|
makeMap["audi"] = "volkswagen";
|
||||||
|
makeMap["buick"] = "gm";
|
||||||
|
makeMap["cadillac"] = "gm";
|
||||||
|
makeMap["chevrolet"] = "gm";
|
||||||
|
makeMap["chrysler"] = "chrysler";
|
||||||
|
makeMap["dodge"] = "chrysler";
|
||||||
|
makeMap["ford"] = "ford";
|
||||||
|
makeMap["gm"] = "gm";
|
||||||
|
makeMap["gmc"] = "gm";
|
||||||
|
makeMap["genesis"] = "hyundai";
|
||||||
|
makeMap["honda"] = "honda";
|
||||||
|
makeMap["hyundai"] = "hyundai";
|
||||||
|
makeMap["infiniti"] = "nissan";
|
||||||
|
makeMap["jeep"] = "chrysler";
|
||||||
|
makeMap["kia"] = "hyundai";
|
||||||
|
makeMap["lexus"] = "toyota";
|
||||||
|
makeMap["lincoln"] = "ford";
|
||||||
|
makeMap["man"] = "volkswagen";
|
||||||
|
makeMap["mazda"] = "mazda";
|
||||||
|
makeMap["nissan"] = "nissan";
|
||||||
|
makeMap["ram"] = "chrysler";
|
||||||
|
makeMap["seat"] = "volkswagen";
|
||||||
|
makeMap["subaru"] = "subaru";
|
||||||
|
makeMap["tesla"] = "tesla";
|
||||||
|
makeMap["toyota"] = "toyota";
|
||||||
|
makeMap["volkswagen"] = "volkswagen";
|
||||||
|
makeMap["skoda"] = "volkswagen";
|
||||||
|
|
||||||
|
QString dirPath = "../../selfdrive/car";
|
||||||
|
QDir dir(dirPath);
|
||||||
|
QString targetFolder = makeMap.value(carMake, carMake);
|
||||||
|
QStringList names;
|
||||||
|
|
||||||
|
foreach (const QString &folder, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||||
|
if (folder == targetFolder) {
|
||||||
|
QFile file(dirPath + "/" + folder + "/values.py");
|
||||||
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QRegularExpression regex("class CAR\\(StrEnum\\):([\\s\\S]*?)(?=^\\w)", QRegularExpression::MultilineOption);
|
||||||
|
QRegularExpressionMatch match = regex.match(QTextStream(&file).readAll());
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
QRegularExpression nameRegex("=\\s*\"([^\"]+)\"");
|
||||||
|
QRegularExpressionMatchIterator it = nameRegex.globalMatch(match.captured(1));
|
||||||
|
while (it.hasNext()) {
|
||||||
|
names << it.next().captured(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(names.begin(), names.end());
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
FrogPilotVehiclesPanel::FrogPilotVehiclesPanel(SettingsWindow *parent) : FrogPilotListWidget(parent) {
|
FrogPilotVehiclesPanel::FrogPilotVehiclesPanel(SettingsWindow *parent) : FrogPilotListWidget(parent) {
|
||||||
|
selectMakeButton = new ButtonControl(tr("Select Make"), tr("SELECT"));
|
||||||
|
QObject::connect(selectMakeButton, &ButtonControl::clicked, [this]() {
|
||||||
|
QStringList makes = {
|
||||||
|
"Acura", "Audi", "BMW", "Buick", "Cadillac", "Chevrolet", "Chrysler", "Dodge", "Ford", "GM", "GMC",
|
||||||
|
"Genesis", "Honda", "Hyundai", "Infiniti", "Jeep", "Kia", "Lexus", "Lincoln", "MAN", "Mazda",
|
||||||
|
"Mercedes", "Nissan", "Ram", "SEAT", "Subaru", "Tesla", "Toyota", "Volkswagen", "Volvo", "Škoda",
|
||||||
|
};
|
||||||
|
|
||||||
|
QString newMakeSelection = MultiOptionDialog::getSelection(tr("Select a Make"), makes, "", this);
|
||||||
|
if (!newMakeSelection.isEmpty()) {
|
||||||
|
carMake = newMakeSelection;
|
||||||
|
params.putNonBlocking("CarMake", carMake.toStdString());
|
||||||
|
selectMakeButton->setValue(newMakeSelection);
|
||||||
|
setModels();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addItem(selectMakeButton);
|
||||||
|
|
||||||
|
selectModelButton = new ButtonControl(tr("Select Model"), tr("SELECT"));
|
||||||
|
QString modelSelection = QString::fromStdString(params.get("CarModel"));
|
||||||
|
QObject::connect(selectModelButton, &ButtonControl::clicked, [this]() {
|
||||||
|
QString newModelSelection = MultiOptionDialog::getSelection(tr("Select a Model"), models, "", this);
|
||||||
|
if (!newModelSelection.isEmpty()) {
|
||||||
|
params.putNonBlocking("CarModel", newModelSelection.toStdString());
|
||||||
|
selectModelButton->setValue(newModelSelection);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
selectModelButton->setValue(modelSelection);
|
||||||
|
addItem(selectModelButton);
|
||||||
|
selectModelButton->setVisible(false);
|
||||||
|
|
||||||
|
ParamControl *forceFingerprint = new ParamControl("ForceFingerprint", "Disable Automatic Fingerprint Detection", "Forces the selected fingerprint and prevents it from ever changing.", "", this);
|
||||||
|
addItem(forceFingerprint);
|
||||||
|
|
||||||
ParamControl *disableOpenpilotLong = new ParamControl("DisableOpenpilotLongitudinal", "Disable Openpilot Longitudinal Control", "Disables openpilot longitudinal control to use stock ACC.", "", this);
|
ParamControl *disableOpenpilotLong = new ParamControl("DisableOpenpilotLongitudinal", "Disable Openpilot Longitudinal Control", "Disables openpilot longitudinal control to use stock ACC.", "", this);
|
||||||
addItem(disableOpenpilotLong);
|
addItem(disableOpenpilotLong);
|
||||||
|
|
||||||
@@ -63,7 +160,24 @@ FrogPilotVehiclesPanel::FrogPilotVehiclesPanel(SettingsWindow *parent) : FrogPil
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject::connect(uiState(), &UIState::offroadTransition, this, [this](bool offroad) {
|
||||||
|
if (!offroad) {
|
||||||
|
std::thread([this]() {
|
||||||
|
while (carMake.isEmpty()) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
carMake = QString::fromStdString(params.get("CarMake"));
|
||||||
|
}
|
||||||
|
setModels();
|
||||||
|
}).detach();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
QObject::connect(uiState(), &UIState::uiUpdate, this, &FrogPilotVehiclesPanel::updateState);
|
QObject::connect(uiState(), &UIState::uiUpdate, this, &FrogPilotVehiclesPanel::updateState);
|
||||||
|
|
||||||
|
carMake = QString::fromStdString(params.get("CarMake"));
|
||||||
|
if (!carMake.isEmpty()) {
|
||||||
|
setModels();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrogPilotVehiclesPanel::updateState(const UIState &s) {
|
void FrogPilotVehiclesPanel::updateState(const UIState &s) {
|
||||||
@@ -78,10 +192,18 @@ void FrogPilotVehiclesPanel::updateToggles() {
|
|||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrogPilotVehiclesPanel::setModels() {
|
||||||
|
models = getCarNames(carMake.toLower());
|
||||||
|
setToggles();
|
||||||
|
}
|
||||||
|
|
||||||
void FrogPilotVehiclesPanel::setToggles() {
|
void FrogPilotVehiclesPanel::setToggles() {
|
||||||
bool gm = false;
|
selectMakeButton->setValue(carMake);
|
||||||
bool subaru false;
|
selectModelButton->setVisible(!carMake.isEmpty());
|
||||||
bool toyota = false;
|
|
||||||
|
bool gm = carMake == "Buick" || carMake == "Cadillac" || carMake == "Chevrolet" || carMake == "GM" || carMake == "GMC";
|
||||||
|
bool subaru = carMake == "Subaru";
|
||||||
|
bool toyota = carMake == "Lexus" || carMake == "Toyota";
|
||||||
|
|
||||||
for (auto &[key, toggle] : toggles) {
|
for (auto &[key, toggle] : toggles) {
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
|
|||||||
@@ -15,10 +15,17 @@ public:
|
|||||||
explicit FrogPilotVehiclesPanel(SettingsWindow *parent);
|
explicit FrogPilotVehiclesPanel(SettingsWindow *parent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setModels();
|
||||||
void setToggles();
|
void setToggles();
|
||||||
void updateState(const UIState &s);
|
void updateState(const UIState &s);
|
||||||
void updateToggles();
|
void updateToggles();
|
||||||
|
|
||||||
|
ButtonControl *selectMakeButton;
|
||||||
|
ButtonControl *selectModelButton;
|
||||||
|
|
||||||
|
QString carMake;
|
||||||
|
QStringList models;
|
||||||
|
|
||||||
std::map<std::string, ParamControl*> toggles;
|
std::map<std::string, ParamControl*> toggles;
|
||||||
|
|
||||||
std::set<QString> gmKeys = {};
|
std::set<QString> gmKeys = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user