mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-25 20:42:10 +08:00
cabana(DBCFile): preserve original header (#31900)
* cabana(DBCFile): preserve original header
* add trailing space
old-commit-hash: 5a805df340
This commit is contained in:
@@ -98,10 +98,13 @@ void DBCFile::parse(const QString &content) {
|
||||
QTextStream stream((QString *)&content);
|
||||
cabana::Msg *current_msg = nullptr;
|
||||
int multiplexor_cnt = 0;
|
||||
bool seen_first = false;
|
||||
while (!stream.atEnd()) {
|
||||
++line_num;
|
||||
QString raw_line = stream.readLine();
|
||||
line = raw_line.trimmed();
|
||||
|
||||
bool seen = true;
|
||||
if (line.startsWith("BO_ ")) {
|
||||
multiplexor_cnt = 0;
|
||||
auto match = bo_regexp.match(line);
|
||||
@@ -182,6 +185,14 @@ void DBCFile::parse(const QString &content) {
|
||||
if (auto s = get_sig(match.captured(1).toUInt(), match.captured(2))) {
|
||||
s->comment = match.captured(3).trimmed();
|
||||
}
|
||||
} else {
|
||||
seen = false;
|
||||
}
|
||||
|
||||
if (seen) {
|
||||
seen_first = true;
|
||||
} else if (!seen_first) {
|
||||
header += raw_line + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,5 +242,5 @@ QString DBCFile::generateDBC() {
|
||||
}
|
||||
dbc_string += "\n";
|
||||
}
|
||||
return dbc_string + comment + val_desc;
|
||||
return header + dbc_string + comment + val_desc;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
|
||||
private:
|
||||
void parse(const QString &content);
|
||||
QString header;
|
||||
std::map<uint32_t, cabana::Msg> msgs;
|
||||
QString name_;
|
||||
};
|
||||
|
||||
@@ -45,6 +45,26 @@ CM_ SG_ 162 signal_2 "signal comment";
|
||||
REQUIRE(dbc.generateDBC() == content);
|
||||
}
|
||||
|
||||
TEST_CASE("DBCFile::generateDBC -- preserve original header") {
|
||||
QString content = R"(VERSION "1.0"
|
||||
|
||||
NS_ :
|
||||
CM_
|
||||
|
||||
BS_:
|
||||
|
||||
BU_: EON
|
||||
|
||||
BO_ 160 message_1: 8 EON
|
||||
SG_ signal_1 : 0|12@1+ (1,0) [0|4095] "unit" XXX
|
||||
|
||||
CM_ BO_ 160 "message comment";
|
||||
CM_ SG_ 160 signal_1 "signal comment";
|
||||
)";
|
||||
DBCFile dbc("", content);
|
||||
REQUIRE(dbc.generateDBC() == content);
|
||||
}
|
||||
|
||||
TEST_CASE("parse_dbc") {
|
||||
QString content = R"(
|
||||
BO_ 160 message_1: 8 EON
|
||||
|
||||
Reference in New Issue
Block a user