Skip to content

Commit b787230

Browse files
committed
Files generated are now .cpp, .hpp in a flat folder structure
_CYC defines are generated even if cycle time is 0 f suffix is used in number constants to specify float
1 parent a58dfbe commit b787230

File tree

9 files changed

+49
-72
lines changed

9 files changed

+49
-72
lines changed

src/app.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ void CoderApp::GenerateCode()
130130
fscreator.FS.file.util_c.dir = fscreator.FS.file.utildir;
131131
fscreator.FS.file.util_h.dir = fscreator.FS.file.utildir;
132132

133-
fscreator.FS.file.util_h.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.h");
133+
fscreator.FS.file.util_h.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.hpp");
134134
fscreator.FS.file.util_h.fpath = fscreator.FS.file.utildir + "/" + fscreator.FS.file.util_h.fname;
135135

136-
fscreator.FS.file.util_c.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.c");
136+
fscreator.FS.file.util_c.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.cpp");
137137
fscreator.FS.file.util_c.fpath = fscreator.FS.file.utildir + "/" + fscreator.FS.file.util_c.fname;
138138

139139
MsgsClassification groups;
@@ -207,8 +207,8 @@ void CoderApp::PrintHelp()
207207
std::cout << " \t\t '-rw' option enables rewriting: all source files previously generated" << std::endl;
208208
std::cout << " \t\t will be replaced by new ones" << std::endl;
209209
std::cout << " -noconfig:\t no {drivername}-config and dbccodeconfig generation" << std::endl;
210-
std::cout << " -noinc:\t no canmonitorutil.h generation" << std::endl;
211-
std::cout << " -nofmon:\t no ***-fmon.c generation" << std::endl;
210+
std::cout << " -noinc:\t no canmonitorutil.hpp generation" << std::endl;
211+
std::cout << " -nofmon:\t no ***-fmon.cpp generation" << std::endl;
212212
std::cout << std::endl;
213213

214214
std::cout << "examples:" << std::endl;

src/codegen/c-main-generator.cpp

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const char* extend_func_body =
2424
"// n+1 bits where n is the largest signed signal width. For example if\n"
2525
"// the most wide signed signal has a width of 31 bits you need to set\n"
2626
"// bitext_t as int32_t and ubitext_t as uint32_t\n"
27-
"// Defined these typedefs in @dbccodeconf.h or locally in 'dbcdrvname'-config.h\n"
27+
"// Defined these typedefs in @dbccodeconf.hpp or locally in 'dbcdrvname'-config.hpp\n"
2828
"static bitext_t %s(ubitext_t val, uint8_t bits)\n"
2929
"{\n"
3030
" ubitext_t const m = 1u << (bits - 1);\n"
@@ -66,10 +66,10 @@ void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd
6666

6767
if (!fsd.gen.no_config)
6868
{
69-
// 6 step is to print template for drv-config.h
69+
// 6 step is to print template for drv-config.hpp
7070
Gen_ConfigHeader();
7171

72-
// 8 step is to print dbccodeconf.h template
72+
// 8 step is to print dbccodeconf.hpp template
7373
Gen_DbcCodeConf();
7474
}
7575

@@ -93,8 +93,6 @@ void CiMainGenerator::Gen_MainHeader()
9393

9494
fwriter.Append("#pragma once");
9595
fwriter.Append();
96-
fwriter.Append("#ifdef __cplusplus\nextern \"C\" {\n#endif");
97-
fwriter.Append();
9896
fwriter.Append("#include <stdint.h>");
9997
fwriter.Append();
10098

@@ -104,15 +102,15 @@ void CiMainGenerator::Gen_MainHeader()
104102
fwriter.Append();
105103

106104
fwriter.Append("// include current dbc-driver compilation config");
107-
fwriter.Append("#include \"%s-config.h\"", fdesc->gen.drvname.c_str());
105+
fwriter.Append("#include \"%s-config.hpp\"", fdesc->gen.drvname.c_str());
108106
fwriter.Append();
109107

110108
fwriter.Append("#ifdef %s", fdesc->gen.usemon_def.c_str());
111109

112110
fwriter.Append(
113111
"// This file must define:\n"
114112
"// base monitor struct\n"
115-
"#include \"canmonitorutil.h\"\n"
113+
"#include \"canmonitorutil.hpp\"\n"
116114
"\n"
117115
);
118116

@@ -169,10 +167,7 @@ void CiMainGenerator::Gen_MainHeader()
169167
fwriter.Append("#define %s_DLC (%uU)", m.Name.c_str(), m.DLC);
170168
fwriter.Append("#define %s_CANID (%#xU)", m.Name.c_str(), m.MsgID);
171169

172-
if (m.Cycle > 0)
173-
{
174-
fwriter.Append("#define %s_CYC (%dU)", m.Name.c_str(), m.Cycle);
175-
}
170+
fwriter.Append("#define %s_CYC (%dU)", m.Name.c_str(), m.Cycle);
176171

177172
size_t max_sig_name_len = 27;
178173

@@ -328,8 +323,6 @@ void CiMainGenerator::Gen_MainHeader()
328323
fwriter.Append();
329324
}
330325

331-
fwriter.Append("#ifdef __cplusplus\n}\n#endif");
332-
333326
// save fwrite cached text to file
334327
fwriter.Flush(fdesc->file.core_h.fpath);
335328
}
@@ -362,15 +355,15 @@ void CiMainGenerator::Gen_MainSource()
362355
"// Function prototypes to be called each time CAN frame is unpacked\n"
363356
"// FMon function may detect RC, CRC or DLC violation\n");
364357

365-
fwriter.Append("#include \"%s-fmon.h\"", fdesc->gen.drvname.c_str());
358+
fwriter.Append("#include \"%s-fmon.hpp\"", fdesc->gen.drvname.c_str());
366359
fwriter.Append();
367360

368361
fwriter.Append("#endif // %s", fdesc->gen.usemon_def.c_str());
369362
fwriter.Append("");
370363
fwriter.Append("// This macro guard for the case when you need to enable");
371364
fwriter.Append("// using diag monitors but there is no necessity in proper");
372365
fwriter.Append("// SysTick provider. For providing one you need define macro");
373-
fwriter.Append("// before this line - in dbccodeconf.h");
366+
fwriter.Append("// before this line - in dbccodeconf.hpp");
374367
fwriter.Append("");
375368
fwriter.Append("#ifndef GetSystemTick");
376369
fwriter.Append("#define GetSystemTick() (0u)");
@@ -452,7 +445,7 @@ void CiMainGenerator::Gen_ConfigHeader()
452445
ConfigGenerator confgen;
453446
confgen.FillHeader(fwriter, fdesc->gen);
454447

455-
fwriter.Flush(fdesc->file.confdir + '/' + fdesc->gen.drvname + "-config.h");
448+
fwriter.Flush(fdesc->file.confdir + '/' + fdesc->gen.drvname + "-config.hpp");
456449
}
457450

458451
void CiMainGenerator::Gen_FMonHeader()
@@ -475,10 +468,6 @@ void CiMainGenerator::Gen_CanMonUtil()
475468
fwriter.Append("");
476469
fwriter.Append("#include <stdint.h>");
477470
fwriter.Append("");
478-
fwriter.Append("#ifdef __cplusplus");
479-
fwriter.Append("extern \"C\" {");
480-
fwriter.Append("#endif");
481-
fwriter.Append("");
482471
fwriter.Append("// declare here all availible checksum algorithms");
483472
fwriter.Append("typedef enum");
484473
fwriter.Append("{");
@@ -520,12 +509,8 @@ void CiMainGenerator::Gen_CanMonUtil()
520509
fwriter.Append("");
521510
fwriter.Append("} FrameMonitor_t;");
522511
fwriter.Append("");
523-
fwriter.Append("#ifdef __cplusplus");
524-
fwriter.Append("}");
525-
fwriter.Append("#endif");
526-
fwriter.Append("");
527512

528-
fwriter.Flush(fdesc->file.incdir + '/' + "canmonitorutil.h");
513+
fwriter.Flush(fdesc->file.incdir + '/' + "canmonitorutil.hpp");
529514
}
530515

531516
void CiMainGenerator::Gen_DbcCodeConf()
@@ -562,7 +547,7 @@ void CiMainGenerator::Gen_DbcCodeConf()
562547
fwriter.Append("// #define GetFrameHash(a,b,c,d,e) __get_hash__(a,b,c,d,e)");
563548
fwriter.Append("");
564549

565-
fwriter.Flush(fdesc->file.confdir + '/' + "dbccodeconf.h");
550+
fwriter.Flush(fdesc->file.confdir + '/' + "dbccodeconf.hpp");
566551
}
567552

568553
void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bits, size_t padwidth)

src/codegen/c-util-generator.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,12 @@ void CiUtilGenerator::PrintHeader()
110110
tof.Append("#pragma once");
111111
tof.Append();
112112

113-
tof.Append(openguard);
114-
tof.Append();
115-
116113
// include common dbc code config header
117-
tof.Append("#include \"dbccodeconf.h\"");
114+
tof.Append("#include <nv1_can_gen/src/dbccodeconf.hpp>");
118115
tof.Append();
119116

120117
// include c-main driver header
121-
tof.Append("#include \"%s.h\"", file_drvname.c_str());
118+
tof.Append("#include \"%s.hpp\"", file_drvname.c_str());
122119
tof.Append();
123120

124121

@@ -190,8 +187,6 @@ void CiUtilGenerator::PrintHeader()
190187
tof.Append();
191188
}
192189

193-
tof.Append(closeguard);
194-
195190
tof.Flush(fdesc->util_h.fpath);
196191
}
197192

src/codegen/c-util-generator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CiUtilGenerator {
1919
// the output of this function source files which contain:
2020
// - global TX and RX typedefs message struct
2121
// - function to Unpack incoming frame to dedicated RX message struct field
22-
// - optional (through define in global "dbccodeconf.h") variable allocation in source files
22+
// - optional (through define in global "dbccodeconf.hpp") variable allocation in source files
2323
//
2424
void Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd,
2525
const MsgsClassification& groups, const std::string& drvname);

src/codegen/config-generator.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett)
55
wr.Append("#pragma once");
66
wr.Append("");
77
wr.Append("/* include common dbccode configurations */");
8-
wr.Append("#include \"dbccodeconf.h\"");
8+
wr.Append("#include <nv1_can_gen/src/dbccodeconf.hpp>");
99
wr.Append("");
1010
wr.Append("");
1111
wr.Append("/* ------------------------------------------------------------------------- *");
@@ -28,7 +28,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett)
2828
wr.Append(" u8 Data[8] (CAN Frame payload data)");
2929
wr.Append(" u8 IDE (CAN Frame Extended (1) / Standard (0) ID type)");
3030
wr.Append("");
31-
wr.Append(" This struct definition have to be placed (or be included) in dbccodeconf.h */");
31+
wr.Append(" This struct definition have to be placed (or be included) in dbccodeconf.hpp */");
3232
wr.Append("");
3333
wr.Append("/* #define %s */", gsett.usesruct_def.c_str());
3434
wr.Append(2);
@@ -43,7 +43,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett)
4343
wr.Append(" 1. All the '_ro' fields will have a pair field with '_phys' postfix.");
4444
wr.Append(" If only offset != 0 is true then the type of '_phys' signal is the same");
4545
wr.Append(" as '_ro' signal. In other case the type will be @sigfloat_t which");
46-
wr.Append(" have to be defined in user dbccodeconf.h");
46+
wr.Append(" have to be defined in user dbccodeconf.hpp");
4747
wr.Append("");
4848
wr.Append(" 2. In pack function '_ro' signal will be rewritten by '_phys' signal, which");
4949
wr.Append(" requires from user to use ONLY '_phys' signal for packing frame");
@@ -55,15 +55,15 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett)
5555
wr.Append(2);
5656

5757
wr.Append("/* ------------------------------------------------------------------------- *");
58-
wr.Append(" Note(!) that the \"canmonitorutil.h\" must be accessed in include path:");
58+
wr.Append(" Note(!) that the \"canmonitorutil.hpp\" must be accessed in include path:");
5959
wr.Append("");
6060
wr.Append(" This macro adds:");
6161
wr.Append("");
6262
wr.Append(" - monitor field @mon1 to message struct");
6363
wr.Append("");
6464
wr.Append(" - capture system tick in unpack function and save value to mon1 field");
6565
wr.Append(" to provide to user better missing frame detection code. For this case");
66-
wr.Append(" user must provide function declared in canmonitorutil.h - GetSysTick()");
66+
wr.Append(" user must provide function declared in canmonitorutil.hpp - GetSysTick()");
6767
wr.Append(" which may return 1ms uptime.");
6868
wr.Append("");
6969
wr.Append(" - calling function FMon_*** (from 'fmon' driver) inside unpack function");
@@ -95,8 +95,8 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett)
9595
wr.Append(" - \"Checksum\": constant marker word");
9696
wr.Append("");
9797
wr.Append(" - \"XOR8\": type of method, this text will be passed to GetFrameHash");
98-
wr.Append(" (canmonitorutil.h) function as is, the best use case is to define 'enum");
99-
wr.Append(" DbcCanCrcMethods' in canmonitorutil.h file with all possible");
98+
wr.Append(" (canmonitorutil.hpp) function as is, the best use case is to define 'enum");
99+
wr.Append(" DbcCanCrcMethods' in canmonitorutil.hpp file with all possible");
100100
wr.Append(" checksum algorithms (e.g. XOR8, XOR4 etc)");
101101
wr.Append("");
102102
wr.Append(" - \"3\": optional value that will be passed to GetFrameHash as integer value");

src/codegen/fs-creator.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ static const int32_t kTmpLen = 1024;
88

99
static char _tmpb[kTmpLen];
1010

11-
static const char* kLibDir = "/lib";
12-
static const char* kUsrDir = "/usr";
13-
static const char* kIncDir = "/inc";
14-
static const char* kConfDir = "/conf";
15-
static const char* kUtilDir = "/butl";
11+
static const char* kLibDir = "/";
12+
static const char* kUsrDir = "/";
13+
static const char* kIncDir = "/";
14+
static const char* kConfDir = "/";
15+
static const char* kUtilDir = "/";
1616

1717
FsCreator::FsCreator()
1818
{
@@ -50,27 +50,27 @@ void FsCreator::Configure(const std::string& drvname, const std::string& outpath
5050
FS.gen.drvname = str_tolower(drvname);
5151

5252
FS.file.core_h.dir = outpath;
53-
FS.file.core_h.fname = FS.gen.drvname + ".h";
53+
FS.file.core_h.fname = FS.gen.drvname + ".hpp";
5454
FS.file.core_h.fpath = FS.file.libdir + "/" + FS.file.core_h.fname;
5555

5656
FS.file.core_c.dir = outpath;
57-
FS.file.core_c.fname = FS.gen.drvname + ".c";
57+
FS.file.core_c.fname = FS.gen.drvname + ".cpp";
5858
FS.file.core_c.fpath = FS.file.libdir + "/" + FS.file.core_c.fname;
5959

6060
FS.file.util_h.dir = outpath;
61-
FS.file.util_h.fname = FS.gen.drvname + "-binutil" + ".h";
61+
FS.file.util_h.fname = FS.gen.drvname + "-binutil" + ".hpp";
6262
FS.file.util_h.fpath = FS.file.utildir + "/" + FS.file.util_h.fname;
6363

6464
FS.file.util_c.dir = outpath;
65-
FS.file.util_c.fname = FS.gen.drvname + "-binutil" + ".c";
65+
FS.file.util_c.fname = FS.gen.drvname + "-binutil" + ".cpp";
6666
FS.file.util_c.fpath = FS.file.utildir + "/" + FS.file.util_c.fname;
6767

6868
FS.file.fmon_h.dir = outpath;
69-
FS.file.fmon_h.fname = FS.gen.drvname + "-fmon.h";
69+
FS.file.fmon_h.fname = FS.gen.drvname + "-fmon.hpp";
7070
FS.file.fmon_h.fpath = FS.file.libdir + "/" + FS.file.fmon_h.fname;
7171

7272
FS.file.fmon_c.dir = outpath;
73-
FS.file.fmon_c.fname = FS.gen.drvname + "-fmon.c";
73+
FS.file.fmon_c.fname = FS.gen.drvname + "-fmon.cpp";
7474
FS.file.fmon_c.fpath = FS.file.usrdir + "/" + FS.file.fmon_c.fname;
7575

7676
snprintf(_tmpb, kTmpLen, "%s_USE_BITS_SIGNAL", FS.gen.DRVNAME.c_str());

src/codegen/mon-generator.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,24 @@ uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
1212
wr.Append("#pragma once");
1313
wr.Append();
1414

15-
wr.Append("#ifdef __cplusplus\nextern \"C\" {\n#endif");
16-
wr.Append();
17-
1815
wr.Append("// DBC file version");
1916
wr.Append("#define %s_FMON (%uU)", aset.gen.verhigh_def.c_str(), aset.gen.hiver);
2017
wr.Append("#define %s_FMON (%uU)", aset.gen.verlow_def.c_str(), aset.gen.lowver);
2118
wr.Append();
2219

23-
wr.Append("#include \"%s-config.h\"", aset.gen.drvname.c_str());
20+
wr.Append("#include \"%s-config.hpp\"", aset.gen.drvname.c_str());
2421
wr.Append();
2522

2623
// put diagmonitor ifdef selection for including @drv-fmon header
2724
// with FMon_* signatures to call from unpack function
2825
wr.Append("#ifdef %s", aset.gen.usemon_def.c_str());
2926
wr.Append();
30-
wr.Append("#include \"canmonitorutil.h\"");
27+
wr.Append("#include \"canmonitorutil.hpp\"");
3128
wr.Append("/*\n\
3229
This file contains the prototypes of all the functions that will be called\n\
3330
from each Unpack_*name* function to detect DBC related errors\n\
3431
It is the user responsibility to defined these functions in the\n\
35-
separated .c file. If it won't be done the linkage error will happen\n*/");
32+
separated .cpp file. If it won't be done the linkage error will happen\n*/");
3633
wr.Append();
3734

3835
wr.Append("#ifdef %s_USE_MONO_FMON", aset.gen.DRVNAME.c_str());
@@ -78,8 +75,6 @@ separated .c file. If it won't be done the linkage error will happen\n*/");
7875
wr.Append("#endif // %s", aset.gen.usemon_def.c_str());
7976
wr.Append();
8077

81-
wr.Append("#ifdef __cplusplus\n}\n#endif");
82-
8378
return 0;
8479
}
8580

src/helpers/formatter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ std::string prt_double(double value, size_t precision, bool usedot)
164164
{
165165
s += ".0";
166166
}
167+
s += "f";
167168

168169
return s;
169170
}
@@ -197,6 +198,7 @@ std::string prt_double(double value, size_t precision, bool usedot)
197198
// xxx.x(x)
198199
s.resize(dotpos + addtail + 1);
199200
}
201+
s += "f";
200202

201203
return s;
202204
}

0 commit comments

Comments
 (0)