mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 12:02:09 +08:00
cabana: catch exceptions thrown from opendbc (#27242)
* catch exceptions thrown from opendbc * Update tools/cabana/mainwin.cc Co-authored-by: Cameron Clough <cameronjclough@gmail.com> * Update tools/cabana/mainwin.cc Co-authored-by: Cameron Clough <cameronjclough@gmail.com> * show error line in detailed text --------- Co-authored-by: Cameron Clough <cameronjclough@gmail.com> old-commit-hash: 95fc84e0b78843a7c8b1a3c42a751d072378960d
This commit is contained in:
@@ -13,10 +13,16 @@ void DBCManager::open(const QString &dbc_file_name) {
|
||||
initMsgMap();
|
||||
}
|
||||
|
||||
void DBCManager::open(const QString &name, const QString &content) {
|
||||
std::istringstream stream(content.toStdString());
|
||||
dbc = const_cast<DBC *>(dbc_parse_from_stream(name.toStdString(), stream));
|
||||
initMsgMap();
|
||||
bool DBCManager::open(const QString &name, const QString &content, QString *error) {
|
||||
try {
|
||||
std::istringstream stream(content.toStdString());
|
||||
dbc = const_cast<DBC *>(dbc_parse_from_stream(name.toStdString(), stream));
|
||||
initMsgMap();
|
||||
return true;
|
||||
} catch (std::exception &e) {
|
||||
if (error) *error = e.what();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DBCManager::initMsgMap() {
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
~DBCManager();
|
||||
|
||||
void open(const QString &dbc_file_name);
|
||||
void open(const QString &name, const QString &content);
|
||||
bool open(const QString &name, const QString &content, QString *error = nullptr);
|
||||
QString generateDBC();
|
||||
void addSignal(const QString &id, const Signal &sig);
|
||||
void updateSignal(const QString &id, const QString &sig_name, const Signal &sig);
|
||||
|
||||
+18
-6
@@ -220,9 +220,16 @@ void MainWindow::loadFile(const QString &fn) {
|
||||
QFile file(fn);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
auto dbc_name = QFileInfo(fn).baseName();
|
||||
dbc()->open(dbc_name, file.readAll());
|
||||
setCurrentFile(fn);
|
||||
statusBar()->showMessage(tr("DBC File %1 loaded").arg(fn), 2000);
|
||||
QString error;
|
||||
bool ret = dbc()->open(dbc_name, file.readAll(), &error);
|
||||
if (ret) {
|
||||
setCurrentFile(fn);
|
||||
statusBar()->showMessage(tr("DBC File %1 loaded").arg(fn), 2000);
|
||||
} else {
|
||||
QMessageBox msg_box(QMessageBox::Warning, tr("Failed to load DBC file"), tr("Failed to parse DBC file %1").arg(fn));
|
||||
msg_box.setDetailedText(error);
|
||||
msg_box.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,11 +258,16 @@ void MainWindow::loadDBCFromOpendbc(const QString &name) {
|
||||
void MainWindow::loadDBCFromClipboard() {
|
||||
remindSaveChanges();
|
||||
QString dbc_str = QGuiApplication::clipboard()->text();
|
||||
dbc()->open("from_clipboard.dbc", dbc_str);
|
||||
if (dbc()->messages().size() > 0) {
|
||||
QString error;
|
||||
bool ret = dbc()->open("clipboard", dbc_str, &error);
|
||||
if (ret && dbc()->messages().size() > 0) {
|
||||
QMessageBox::information(this, tr("Load From Clipboard"), tr("DBC Successfully Loaded!"));
|
||||
} else {
|
||||
QMessageBox::warning(this, tr("Load From Clipboard"), tr("Failed to parse dbc from clipboard!\nMake sure that you paste the text with correct format."));
|
||||
QMessageBox msg_box(QMessageBox::Warning, tr("Failed to load DBC from clipboard"), tr("Make sure that you paste the text with correct format."));
|
||||
if (!error.isEmpty()) {
|
||||
msg_box.setDetailedText(error);
|
||||
}
|
||||
msg_box.exec();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user