Skip to content

Commit ab769a9

Browse files
committed
Added value table parsing.
1 parent 7bd24c5 commit ab769a9

File tree

3 files changed

+95
-4
lines changed

3 files changed

+95
-4
lines changed

src/dbclineparser.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static const std::string kRegCommMeta = "[ ]+";
1818
// This reg splits line to parts (for attributes)
1919
static const std::string kRegAttrMain = "[^A-Za-z0-9_\.]+";
2020

21+
static const std::string kRegValTable = "\"";
2122

2223
static uint64_t __maxvalues[] =
2324
{
@@ -363,3 +364,57 @@ bool DbcLineParser::ParseAttributeLine(AttributeDescriptor_t* attr, const std::s
363364

364365
return ret;
365366
}
367+
368+
bool DbcLineParser::ParseValTableLine(Comment_t* comm, const std::string& line)
369+
{
370+
bool ret = false;
371+
372+
if (line.size() > 0)
373+
{
374+
if (line.find("VAL_ ") == 0)
375+
{
376+
valueline.clear();
377+
valueline = line;
378+
}
379+
else if (valueline.size() > 0)
380+
{
381+
valueline += line;
382+
}
383+
384+
// check if the current line is last
385+
if (valueline.size() > 0 && line.back() == ';')
386+
{
387+
// split all line by quote char
388+
auto items = resplit(valueline, kRegValTable);
389+
390+
if (items.size() >= 2)
391+
{
392+
// split first part by spaces, the last item will have first value key
393+
auto meta = resplit(items[0], kRegCommMeta);
394+
395+
if (meta.size() == 4)
396+
{
397+
// ok, set items[0] -> meta[3] (set value key as first @items element)
398+
items[0] = meta[3];
399+
400+
comm->MsgId = (clear_msgid(atoi(meta[1].c_str())));
401+
402+
comm->SigName = meta[2];
403+
// Load value table params to container
404+
comm->Text = "";
405+
406+
for (size_t valpair = 0; valpair < (items.size() / 2); valpair++)
407+
{
408+
comm->Text += items[valpair * 2 + 0] + " : ";
409+
comm->Text += items[valpair * 2 + 1] + "\n";
410+
}
411+
412+
// value table params were parse successfully
413+
ret = true;
414+
}
415+
}
416+
}
417+
}
418+
419+
return ret;
420+
}

src/dbclineparser.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class DbcLineParser {
6464
// and loads result to cm struct, return @true if parsed ok
6565
bool ParseCommentLine(Comment_t* cm, const std::string& line);
6666

67+
// tries to parse value table string in line
68+
// and load result to attr ValueStr, return true if parsed ok
69+
bool ParseValTableLine(Comment_t* cm, const std::string& line);
70+
6771
private:
6872
// defines the type for the message struct member
6973
SigType GetSigType(SignalDescriptor_t* sig);
@@ -73,5 +77,8 @@ class DbcLineParser {
7377

7478
// string to collect attribute dbc line
7579
std::string attribline;
80+
81+
// strign to collect value line
82+
std::string valueline;
7683
};
7784

src/dbcscanner.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,35 @@ void DbcScanner::ParseOtherInfo(istream& readstrm)
145145
}
146146
}
147147

148+
if (lparser.ParseValTableLine(&cmmnt, sline))
149+
{
150+
uint32_t found_msg_id = cmmnt.MsgId;
151+
152+
// update message comment field
153+
auto msg = find_message(msgs, cmmnt.MsgId);
154+
155+
if (msg != nullptr)
156+
{
157+
// comment line was found
158+
if (cmmnt.ca_target == CommentTarget::Message)
159+
{
160+
// put comment to message descriptor
161+
msg->CommentText = cmmnt.Text;
162+
}
163+
else if (cmmnt.ca_target == CommentTarget::Signal)
164+
{
165+
for (size_t i = 0; i < msg->Signals.size(); i++)
166+
{
167+
if (cmmnt.SigName == msg->Signals[i].Name)
168+
{
169+
// signal has been found, update commnet text
170+
msg->Signals[i].ValueText = cmmnt.Text;
171+
}
172+
}
173+
}
174+
}
175+
}
176+
148177
if (lparser.ParseAttributeLine(&attr, sline))
149178
{
150179
auto msg = find_message(msgs, attr.MsgId);
@@ -170,10 +199,10 @@ void DbcScanner::AddMessage(MessageDescriptor_t* message)
170199
{
171200
// sort signals by start bit
172201
std::sort(message->Signals.begin(), message->Signals.end(),
173-
[](const SignalDescriptor_t& a, const SignalDescriptor_t& b) -> bool
174-
{
175-
return a.StartBit < b.StartBit;
176-
});
202+
[](const SignalDescriptor_t& a, const SignalDescriptor_t& b) -> bool
203+
{
204+
return a.StartBit < b.StartBit;
205+
});
177206

178207
for (size_t i = 0; i < message->Signals.size(); i++)
179208
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy