Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 776a05a

Browse files
committed
Added DBC version info parsing.
1 parent e06f777 commit 776a05a

File tree

12 files changed

+101
-16
lines changed

12 files changed

+101
-16
lines changed

docs/RELEASES.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
## v1.0 - 2021-05-15
5+
### Added
6+
- Added DBC file version ("VERSION "x.x"") tag parsing
7+
- Added dbc version info in: fmon, main and util drivers
8+
- Added codegen lib version file
9+
10+
### Changed
11+
- Generate interface takes DbcMessageList instance which has version info
12+
13+
### Fixed
14+
- Fixed some warnings

src/codegen/c-main-generator.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ CiMainGenerator::CiMainGenerator()
1717
fwriter = new FileWriter;
1818
}
1919

20-
void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const FsDescriptor_t& fsd)
20+
void CiMainGenerator::Generate(DbcMessageList_t& dlist, const FsDescriptor_t& fsd)
2121
{
22+
p_dlist = &dlist;
2223
// Load income messages to sig printer
23-
sigprt->LoadMessages(msgs);
24+
sigprt->LoadMessages(dlist.msgs);
2425

2526
// save pointer to output file descriptor struct to
2627
// enable using this information inside class member functions
@@ -61,6 +62,10 @@ void CiMainGenerator::Gen_MainHeader()
6162
fwriter->AppendLine("#ifdef __cplusplus\nextern \"C\" {\n#endif", 2);
6263
fwriter->AppendLine("#include <stdint.h>", 2);
6364

65+
fwriter->AppendLine("// DBC file version");
66+
fwriter->AppendLine(StrPrint("#define %s (%uU)", fdesc->verhigh_def.c_str(), p_dlist->ver.hi));
67+
fwriter->AppendLine(StrPrint("#define %s (%uU)", fdesc->verlow_def.c_str(), p_dlist->ver.low), 2);
68+
6469
fwriter->AppendLine("// include current dbc-driver compilation config");
6570
fwriter->AppendLine(StrPrint("#include \"%s-config.h\"", fdesc->drvname.c_str()), 2);
6671

@@ -360,6 +365,10 @@ void CiMainGenerator::Gen_FMonHeader()
360365

361366
fwriter->AppendLine("#ifdef __cplusplus\nextern \"C\" {\n#endif", 2);
362367

368+
fwriter->AppendLine("// DBC file version");
369+
fwriter->AppendLine(StrPrint("#define %s_FMON (%uU)", fdesc->verhigh_def.c_str(), p_dlist->ver.hi));
370+
fwriter->AppendLine(StrPrint("#define %s_FMON (%uU)", fdesc->verlow_def.c_str(), p_dlist->ver.low), 2);
371+
363372
fwriter->AppendLine(StrPrint("#include \"%s-config.h\"", fdesc->drvname.c_str()), 2);
364373

365374
// put diagmonitor ifdef selection for including @drv-fmon header

src/codegen/c-main-generator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CiMainGenerator {
1111
public:
1212
CiMainGenerator();
1313

14-
void Generate(std::vector<MessageDescriptor_t*>& msgs, const FsDescriptor_t& fsd);
14+
void Generate(DbcMessageList_t& dlist, const FsDescriptor_t& fsd);
1515

1616
private:
1717

@@ -36,4 +36,6 @@ class CiMainGenerator {
3636
FileWriter* fwriter;
3737

3838
const FsDescriptor_t* fdesc;
39+
40+
const DbcMessageList_t* p_dlist;
3941
};

src/codegen/c-sigprinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ std::string CSigPrinter::PrintSignalExpr(const SignalDescriptor_t* sig, std::vec
185185
if (startb > 63)
186186
startb = 63;
187187

188-
int32_t bn = startb / 8;
188+
uint32_t bn = (startb / 8);
189189

190190
if (to_bytes.size() < bn)
191191
{

src/codegen/c-util-generator.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ void CiUtilGenerator::Clear()
2727
}
2828

2929

30-
void CiUtilGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const FsDescriptor_t& fsd,
30+
void CiUtilGenerator::Generate(DbcMessageList_t& dlist, const FsDescriptor_t& fsd,
3131
const MsgsClassification& groups, const std::string& drvname)
3232
{
3333
Clear();
3434

35+
p_dlist = &dlist;
36+
3537
code_drvname = drvname;
3638
file_drvname = str_tolower(drvname);
3739

3840
// 1 step is to prepare vectors of message's groups
39-
for (auto m : msgs)
41+
for (auto m : dlist.msgs)
4042
{
4143
auto v = std::find_if(groups.Both.begin(), groups.Both.end(), [&](const uint32_t& msgid)
4244
{
@@ -108,9 +110,16 @@ void CiUtilGenerator::PrintHeader()
108110

109111
// include common dbc code config header
110112
tof->AppendLine("#include \"dbccodeconf.h\"", 2);
113+
111114
// include c-main driver header
112115
tof->AppendLine(StrPrint("#include \"%s.h\"", file_drvname.c_str()), 2);
113116

117+
// put version info macros
118+
tof->AppendLine("// This version definition comes from main driver version and");
119+
tof->AppendLine("// can be compared in user code space for strict compatibility test");
120+
tof->AppendLine(StrPrint("#define %s (%uU)", fdesc->verhigh_def.c_str(), p_dlist->ver.hi));
121+
tof->AppendLine(StrPrint("#define %s (%uU)", fdesc->verlow_def.c_str(), p_dlist->ver.low), 2);
122+
114123
if (rx.size() == 0)
115124
{
116125
tof->AppendLine("// There is no any RX mapped massage.", 2);
@@ -238,7 +247,6 @@ ConditionalTree_t* CiUtilGenerator::FillTreeLevel(std::vector<MessageDescriptor_
238247
{
239248
int32_t span = h - l;
240249
int32_t lowhalf = span / 2;
241-
int32_t highhalf = span - lowhalf;
242250

243251
treestarted = started;
244252

src/codegen/c-util-generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CiUtilGenerator {
2020
// - function to Unpack incoming frame to dedicated RX message struct field
2121
// - optional (through define in global "dbccodeconf.h") variable allocation in source files
2222
//
23-
void Generate(std::vector<MessageDescriptor_t*>& msgs, const FsDescriptor_t& fsd,
23+
void Generate(DbcMessageList_t& dlist, const FsDescriptor_t& fsd,
2424
const MsgsClassification& groups, const std::string& drvname);
2525

2626
private:
@@ -43,6 +43,7 @@ class CiUtilGenerator {
4343

4444
const FsDescriptor_t* fdesc;
4545
ConditionalTree* condtree;
46+
const DbcMessageList_t* p_dlist;
4647

4748
bool treestarted;
4849
};

src/codegen/fs-creator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
9797
snprintf(_tmpb, kTmpLen, "%s_AUTO_CSM", FS.DRVNAME.c_str());
9898
FS.usecsm_def = _tmpb;
9999

100+
snprintf(_tmpb, kTmpLen, "VER_%s_MAJ", FS.DRVNAME.c_str());
101+
FS.verhigh_def = _tmpb;
102+
103+
snprintf(_tmpb, kTmpLen, "VER_%s_MIN", FS.DRVNAME.c_str());
104+
FS.verlow_def = _tmpb;
105+
100106
// load start info to fdescriptor
101107
FS.start_info.clear();
102108

src/codegen/fs-creator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ typedef struct
2828
std::string usesigfloat_def;
2929
std::string useroll_def;
3030
std::string usecsm_def;
31+
32+
// for dbc version info
33+
std::string verhigh_def;
34+
std::string verlow_def;
35+
3136
// inforamtion to be placed at the start of each source file
3237
std::string start_info;
3338

src/codegen/version.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
#include <stdint.h>
4+
5+
#define CODEGEN_LIB_VERSION_MAJ (1)
6+
#define CODEGEN_LIB_VERSION_MIN (0)

src/parser/dbcscanner.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "dbcscanner.h"
2+
#include <cstring>
23
#include <algorithm>
34
#include <math.h>
45
#include "../helpers/formatter.h"
@@ -36,7 +37,8 @@ DbcScanner::~DbcScanner()
3637

3738
int32_t DbcScanner::TrimDbcText(istream& readstrm)
3839
{
39-
msgs.clear();
40+
dblist.msgs.clear();
41+
dblist.ver.hi = dblist.ver.low = 0;
4042

4143
readstrm.clear();
4244
readstrm.seekg(0);
@@ -70,6 +72,8 @@ void DbcScanner::ParseMessageInfo(istream& readstrm)
7072

7173
sline = str_trim(line);
7274

75+
FindVersion(sline);
76+
7377
// New message line has been found
7478
if (lparser.IsMessageLine(sline))
7579
{
@@ -127,7 +131,7 @@ void DbcScanner::ParseOtherInfo(istream& readstrm)
127131
if (lparser.ParseCommentLine(&cmmnt, sline))
128132
{
129133
// update message comment field
130-
auto msg = find_message(msgs, cmmnt.MsgId);
134+
auto msg = find_message(dblist.msgs, cmmnt.MsgId);
131135

132136
if (msg != nullptr)
133137
{
@@ -194,7 +198,7 @@ void DbcScanner::ParseOtherInfo(istream& readstrm)
194198
if (lparser.ParseValTableLine(&cmmnt, sline))
195199
{
196200
// update message comment field
197-
auto msg = find_message(msgs, cmmnt.MsgId);
201+
auto msg = find_message(dblist.msgs, cmmnt.MsgId);
198202

199203
if (msg != nullptr)
200204
{
@@ -220,7 +224,7 @@ void DbcScanner::ParseOtherInfo(istream& readstrm)
220224

221225
if (lparser.ParseAttributeLine(&attr, sline))
222226
{
223-
auto msg = find_message(msgs, attr.MsgId);
227+
auto msg = find_message(dblist.msgs, attr.MsgId);
224228

225229
if (msg != nullptr)
226230
{
@@ -264,7 +268,7 @@ void DbcScanner::AddMessage(MessageDescriptor_t* message)
264268
}
265269

266270
// save pointer on message
267-
msgs.push_back(message);
271+
dblist.msgs.push_back(message);
268272
}
269273
}
270274

@@ -287,3 +291,23 @@ void DbcScanner::SetDefualtMessage(MessageDescriptor_t* message)
287291
message->CsmOp = 0;
288292
message->CsmToByteExpr = "";
289293
}
294+
295+
296+
void DbcScanner::FindVersion(const std::string& instr)
297+
{
298+
// try to find version string which looks like: VERSION "x.x"
299+
uint32_t h = 0, l = 0;
300+
char marker[8];
301+
302+
if (instr[0] != 'V' && instr[1] != 'E')
303+
return;
304+
305+
int32_t ret = std::sscanf(instr.c_str(), "%8s \"%u.%u\"", marker, &h, &l);
306+
307+
if ((ret == 3) && (std::strcmp(marker, "VERSION") == 0))
308+
{
309+
// versions have been found, save numeric values
310+
dblist.ver.hi = h;
311+
dblist.ver.low = l;
312+
}
313+
}

0 commit comments

Comments
 (0)