Update mapd to v2

This commit is contained in:
James
2026-01-06 17:12:51 -07:00
parent dc9a91e201
commit 5758e61a6d
17 changed files with 281 additions and 322 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ FrogPilotUIState::FrogPilotUIState(QObject *parent) : QObject(parent) {
sm = std::make_unique<SubMaster, const std::initializer_list<const char *>>({
"carControl", "deviceState", "frogpilotCarState", "frogpilotDeviceState",
"frogpilotPlan", "frogpilotRadarState", "frogpilotSelfdriveState", "liveDelay",
"liveParameters", "liveTorqueParameters", "liveTracks", "selfdriveState"
"liveParameters", "liveTorqueParameters", "liveTracks", "mapdExtendedOut", "mapdOut", "selfdriveState"
});
wifi = new WifiManager(this);
+55 -89
View File
@@ -1,5 +1,3 @@
#include <regex>
#include <QtConcurrent>
#include "frogpilot/ui/qt/offroad/maps_settings.h"
@@ -64,34 +62,6 @@ FrogPilotMapsPanel::FrogPilotMapsPanel(FrogPilotSettingsWindow *parent, bool for
});
settingsList->addItem(removeMapsButton);
resetMapdButton = new ButtonControl(tr("Reset Downloader"), tr("RESET"),
tr("<b>Reset the map downloader.</b> Use this if downloads are stuck or failing."));
QObject::connect(resetMapdButton, &ButtonControl::clicked, [parent, this]() {
if (ConfirmationDialog::confirm(tr("Reset the map downloader? Your device will reboot afterward."), tr("Reset"), this)) {
std::thread([parent, this]() {
parent->keepScreenOn = true;
resetMapdButton->setEnabled(false);
resetMapdButton->setValue(tr("Resetting..."));
std::system("pkill mapd");
QDir("/data/media/0/osm").removeRecursively();
resetMapdButton->setValue(tr("Reset!"));
util::sleep_for(2500);
resetMapdButton->setValue(tr("Rebooting..."));
util::sleep_for(2500);
Hardware::reboot();
}).detach();
}
});
settingsList->addItem(resetMapdButton);
settingsList->addItem(mapsSize = new LabelControl(tr("Storage Used"), calculateDirectorySize(mapsFolderPath)));
ScrollView *settingsPanel = new ScrollView(settingsList, this);
@@ -138,13 +108,10 @@ FrogPilotMapsPanel::FrogPilotMapsPanel(FrogPilotSettingsWindow *parent, bool for
downloadMapsButton->showDescription();
preferredSchedule->showDescription();
removeMapsButton->showDescription();
resetMapdButton->showDescription();
selectMaps->showDescription();
}
std::string mapsSelected = params.get("MapsSelected");
hasMapsSelected = !QJsonDocument::fromJson(QByteArray::fromStdString(mapsSelected)).object().value("nations").toArray().isEmpty();
hasMapsSelected |= !QJsonDocument::fromJson(QByteArray::fromStdString(mapsSelected)).object().value("states").toArray().isEmpty();
hasMapsSelected = !params.get("MapsSelected").empty();
mapsLayout->setCurrentWidget(settingsPanel);
});
@@ -156,7 +123,6 @@ void FrogPilotMapsPanel::showEvent(QShowEvent *event) {
downloadMapsButton->showDescription();
preferredSchedule->showDescription();
removeMapsButton->showDescription();
resetMapdButton->showDescription();
selectMaps->showDescription();
}
@@ -165,17 +131,23 @@ void FrogPilotMapsPanel::showEvent(QShowEvent *event) {
FrogPilotUIState &fs = *frogpilotUIState();
FrogPilotUIScene &frogpilot_scene = fs.frogpilot_scene;
SubMaster &fpsm = *(fs.sm);
std::string mapsSelected = params.get("MapsSelected");
hasMapsSelected = !QJsonDocument::fromJson(QByteArray::fromStdString(mapsSelected)).object().value("nations").toArray().isEmpty();
hasMapsSelected |= !QJsonDocument::fromJson(QByteArray::fromStdString(mapsSelected)).object().value("states").toArray().isEmpty();
const cereal::MapdExtendedOut::Reader &mapdExtendedOut = fpsm["mapdExtendedOut"].getMapdExtendedOut();
const cereal::MapdDownloadProgress::Reader &downloadProgress = mapdExtendedOut.getDownloadProgress();
bool mapDownloadActive = downloadProgress.getActive();
int mapDownloadDownloaded = downloadProgress.getDownloadedFiles();
int mapDownloadTotal = downloadProgress.getTotalFiles();
hasMapsSelected = !params.get("MapsSelected").empty();
bool parked = !scene.started || frogpilot_scene.parked || parent->isFrogsGoMoo;
removeMapsButton->setVisible(mapsFolderPath.exists());
std::string osmDownloadProgress = params.get("OSMDownloadProgress");
if (!osmDownloadProgress.empty()) {
if (mapDownloadActive) {
downloadMapsButton->setText(tr("CANCEL"));
downloadStatus->setText(tr("Calculating..."));
@@ -183,9 +155,8 @@ void FrogPilotMapsPanel::showEvent(QShowEvent *event) {
lastMapsDownload->setVisible(false);
removeMapsButton->setVisible(false);
resetMapdButton->setVisible(false);
updateDownloadLabels(osmDownloadProgress);
updateDownloadLabels(mapDownloadDownloaded, mapDownloadTotal);
} else {
downloadMapsButton->setEnabled(!cancellingDownload && hasMapsSelected && frogpilot_scene.online && parked);
downloadMapsButton->setValue(frogpilot_scene.online ? (parked ? "" : tr("Not parked")) : tr("Offline..."));
@@ -194,24 +165,33 @@ void FrogPilotMapsPanel::showEvent(QShowEvent *event) {
void FrogPilotMapsPanel::updateState(const UIState &s, const FrogPilotUIState &fs) {
if (!isVisible() || s.sm->frame % (UI_FREQ / 2) != 0) {
if (!isVisible()) {
return;
}
const FrogPilotUIScene &frogpilot_scene = fs.frogpilot_scene;
const UIScene &scene = s.scene;
const SubMaster &fpsm = *(fs.sm);
const cereal::MapdExtendedOut::Reader &mapdExtendedOut = fpsm["mapdExtendedOut"].getMapdExtendedOut();
const cereal::MapdDownloadProgress::Reader &downloadProgress = mapdExtendedOut.getDownloadProgress();
bool mapDownloadActive = downloadProgress.getActive();
bool parked = !scene.started || frogpilot_scene.parked || parent->isFrogsGoMoo;
std::string osmDownloadProgress = params.get("OSMDownloadProgress");
if (!osmDownloadProgress.empty() && !cancellingDownload) {
updateDownloadLabels(osmDownloadProgress);
int mapDownloadDownloaded = downloadProgress.getDownloadedFiles();
int mapDownloadTotal = downloadProgress.getTotalFiles();
if (mapDownloadActive && !cancellingDownload) {
updateDownloadLabels(mapDownloadDownloaded, mapDownloadTotal);
} else if (downloadMapsButton->text() == tr("CANCEL")) {
updateDownloadLabels(mapDownloadDownloaded, mapDownloadTotal);
} else {
downloadMapsButton->setEnabled(!cancellingDownload && hasMapsSelected && frogpilot_scene.online && parked);
downloadMapsButton->setValue(frogpilot_scene.online ? (parked ? "" : tr("Not parked")) : tr("Offline..."));
}
parent->keepScreenOn = !osmDownloadProgress.empty();
parent->keepScreenOn = mapDownloadActive;
}
void FrogPilotMapsPanel::cancelDownload() {
@@ -224,10 +204,8 @@ void FrogPilotMapsPanel::cancelDownload() {
downloadStatus->setText(tr("Calculating..."));
downloadTimeElapsed->setText(tr("Calculating..."));
params.remove("OSMDownloadProgress");
params_memory.remove("OSMDownloadLocations");
std::system("pkill mapd");
params_memory.putBool("CancelDownloadMaps", true);
params_memory.remove("DownloadMaps");
QTimer::singleShot(2500, [this]() {
cancellingDownload = false;
@@ -242,7 +220,6 @@ void FrogPilotMapsPanel::cancelDownload() {
lastMapsDownload->setVisible(true);
removeMapsButton->setVisible(mapsFolderPath.exists());
resetMapdButton->setVisible(true);
update();
});
@@ -260,53 +237,42 @@ void FrogPilotMapsPanel::startDownload() {
lastMapsDownload->setVisible(false);
removeMapsButton->setVisible(false);
resetMapdButton->setVisible(false);
elapsedTime.start();
startTime = QDateTime::currentDateTime();
params_memory.put("OSMDownloadLocations", params.get("MapsSelected"));
params_memory.putBool("DownloadMaps", true);
}
void FrogPilotMapsPanel::updateDownloadLabels(std::string &osmDownloadProgress) {
static std::regex fileStatusRegex(R"("total_files":(\d+),.*"downloaded_files":(\d+))");
void FrogPilotMapsPanel::updateDownloadLabels(int downloadedFiles, int totalFiles) {
if (downloadedFiles == totalFiles && totalFiles != 0) {
downloadMapsButton->setText(tr("DOWNLOAD"));
lastMapsDownload->setText(formatCurrentDate());
std::smatch match;
if (std::regex_search(osmDownloadProgress, match, fileStatusRegex)) {
int totalFiles = std::stoi(match[1].str());
int downloadedFiles = std::stoi(match[2].str());
downloadETA->setVisible(false);
downloadStatus->setVisible(false);
downloadTimeElapsed->setVisible(false);
if (downloadedFiles == totalFiles) {
downloadMapsButton->setText(tr("DOWNLOAD"));
lastMapsDownload->setText(formatCurrentDate());
lastMapsDownload->setVisible(true);
removeMapsButton->setVisible(true);
downloadETA->setVisible(false);
downloadStatus->setVisible(false);
downloadTimeElapsed->setVisible(false);
params.put("LastMapsUpdate", formatCurrentDate().toStdString());
lastMapsDownload->setVisible(true);
removeMapsButton->setVisible(true);
resetMapdButton->setVisible(true);
update();
params.put("LastMapsUpdate", formatCurrentDate().toStdString());
params.remove("OSMDownloadProgress");
update();
return;
}
static int previousDownloadedFiles = 0;
if (downloadedFiles != previousDownloadedFiles) {
std::thread([this]() {
mapsSize->setText(calculateDirectorySize(mapsFolderPath));
}).detach();
}
downloadETA->setText(QString("%1").arg(formatETA(elapsedTime.elapsed(), downloadedFiles, previousDownloadedFiles, totalFiles, startTime)));
downloadStatus->setText(QString("%1 / %2 (%3%)").arg(downloadedFiles).arg(totalFiles).arg((downloadedFiles * 100) / totalFiles));
downloadTimeElapsed->setText(formatElapsedTime(elapsedTime.elapsed()));
previousDownloadedFiles = downloadedFiles;
return;
}
static int previousDownloadedFiles = 0;
if (downloadedFiles != previousDownloadedFiles) {
std::thread([this]() {
mapsSize->setText(calculateDirectorySize(mapsFolderPath));
}).detach();
}
downloadETA->setText(QString("%1").arg(formatETA(elapsedTime.elapsed(), downloadedFiles, previousDownloadedFiles, totalFiles, startTime)));
downloadStatus->setText(QString("%1 / %2 (%3%)").arg(downloadedFiles).arg(totalFiles).arg((downloadedFiles * 100) / (totalFiles == 0 ? 1 : totalFiles)));
downloadTimeElapsed->setText(formatElapsedTime(elapsedTime.elapsed()));
previousDownloadedFiles = downloadedFiles;
}
+1 -2
View File
@@ -18,7 +18,7 @@ protected:
private:
void cancelDownload();
void startDownload();
void updateDownloadLabels(std::string &osmDownloadProgress);
void updateDownloadLabels(int downloadedFiles, int totalFiles);
void updateState(const UIState &s, const FrogPilotUIState &fs);
bool cancellingDownload;
@@ -27,7 +27,6 @@ private:
ButtonControl *downloadMapsButton;
ButtonControl *removeMapsButton;
ButtonControl *resetMapdButton;
ButtonParamControl *preferredSchedule;
@@ -134,6 +134,7 @@ void FrogPilotAnnotatedCameraWidget::updateState(const UIState &s, const FrogPil
const cereal::FrogPilotCarState::Reader &frogpilotCarState = fpsm["frogpilotCarState"].getFrogpilotCarState();
const cereal::FrogPilotPlan::Reader &frogpilotPlan = fpsm["frogpilotPlan"].getFrogpilotPlan();
const cereal::FrogPilotSelfdriveState::Reader &frogpilotSelfdriveState = fpsm["frogpilotSelfdriveState"].getFrogpilotSelfdriveState();
const cereal::MapdOut::Reader &mapdOut = fpsm["mapdOut"].getMapdOut();
const cereal::ModelDataV2::Reader &modelV2 = sm["modelV2"].getModelV2();
const cereal::SelfdriveState::Reader &selfdriveState = sm["selfdriveState"].getSelfdriveState();
@@ -177,7 +178,7 @@ void FrogPilotAnnotatedCameraWidget::updateState(const UIState &s, const FrogPil
nextSpeedLimit = frogpilotPlan.getSlcNextSpeedLimit();
redLight = frogpilotPlan.getRedLight();
roadCurvature = frogpilotPlan.getRoadCurvature();
roadName = QString::fromStdString(params_memory.get("RoadName"));
roadName = QString::fromStdString(mapdOut.getRoadName());
slcOverriddenSpeed = frogpilotPlan.getSlcOverriddenSpeed();
speedLimit = slcOverriddenSpeed != 0 ? slcOverriddenSpeed : frogpilotPlan.getSlcSpeedLimit();
speedLimitChanged = frogpilotPlan.getSpeedLimitChanged();
+22 -21
View File
@@ -1,7 +1,3 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include "frogpilot/ui/qt/widgets/navigation_functions.h"
MapSelectionControl::MapSelectionControl(const QMap<QString, QString> &map, bool isCountry) : selectionType(isCountry ? "nations" : "states") {
@@ -28,11 +24,15 @@ MapSelectionControl::MapSelectionControl(const QMap<QString, QString> &map, bool
}
void MapSelectionControl::loadSelectedMaps() {
QJsonObject existingMaps = QJsonDocument::fromJson(QByteArray::fromStdString(params.get("MapsSelected"))).object();
QString mapsSelected = QString::fromStdString(params.get("MapsSelected"));
QStringList mapList = mapsSelected.split(",", QString::SkipEmptyParts);
QString prefix = (selectionType == "nations") ? "nation." : "us_state.";
QSet<QString> selectedMaps;
for (const QJsonValue &value : existingMaps.value(selectionType).toArray()) {
selectedMaps.insert(value.toString());
for (const QString &map : mapList) {
if (map.startsWith(prefix)) {
selectedMaps.insert(map.mid(prefix.length()));
}
}
for (QAbstractButton *button : mapButtons->buttons()) {
@@ -41,22 +41,23 @@ void MapSelectionControl::loadSelectedMaps() {
}
void MapSelectionControl::updateSelectedMaps() {
QJsonObject existingMaps = QJsonDocument::fromJson(QByteArray::fromStdString(params.get("MapsSelected"))).object();
QString mapsSelected = QString::fromStdString(params.get("MapsSelected"));
QStringList mapList = mapsSelected.split(",", QString::SkipEmptyParts);
QString prefix = (selectionType == "nations") ? "nation." : "us_state.";
QSet<QString> selectedMaps;
for (const QJsonValue &value : existingMaps.value(selectionType).toArray()) {
selectedMaps.insert(value.toString());
}
for (QAbstractButton *button : mapButtons->buttons()) {
QString mapKey = button->property("mapKey").toString();
if (button->isChecked()) {
selectedMaps.insert(mapKey);
} else {
selectedMaps.remove(mapKey);
QStringList newMapList;
for (const QString &map : mapList) {
if (!map.startsWith(prefix)) {
newMapList.append(map);
}
}
existingMaps[selectionType] = QJsonArray::fromStringList(selectedMaps.values());
params.putNonBlocking("MapsSelected", QJsonDocument(existingMaps).toJson(QJsonDocument::Compact).toStdString());
for (QAbstractButton *button : mapButtons->buttons()) {
if (button->isChecked()) {
newMapList.append(prefix + button->property("mapKey").toString());
}
}
newMapList.sort();
params.putNonBlocking("MapsSelected", newMapList.join(",").toStdString());
}