Skip to content

Commit e634227

Browse files
committed
Added fmon-header file generation.
1 parent 25ba556 commit e634227

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

src/codegen/c-main-generator.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const Fs
5454
Gen_MainSource();
5555

5656
// 4 step is to pring fmon head file
57+
Gen_FMonHeader();
5758

5859
// 5 step is to print fmon source file
5960
}
@@ -242,6 +243,38 @@ void CiMainGenerator::Gen_MainSource()
242243
fwriter->Flush(fdesc->core_c.fpath);
243244
}
244245

246+
void CiMainGenerator::Gen_FMonHeader()
247+
{
248+
fwriter->AppendLine("#pragma once", 2);
249+
250+
fwriter->AppendLine("#ifdef __cplusplus\nextern \"C\" {\n#endif", 2);
251+
252+
fwriter->AppendLine(PrintF("#include \"%s-config.h\"", fdesc->drvname.c_str()), 2);
253+
254+
// put diagmonitor ifdef selection for including @drv-fmon header
255+
// with FMon_* signatures to call from unpack function
256+
fwriter->AppendLine(PrintF("#ifdef %s", fdesc->usemon_def.c_str()), 2);
257+
fwriter->AppendLine("#include \"canmonitorutil.h\"");
258+
fwriter->AppendLine("/*\n\
259+
This file contains the prototypes of all the functions that will be called\n\
260+
from each Unpack_*name* function to detect DBC related errors\n\
261+
It is the user responsibility to defined these functions in the\n\
262+
separated .c file. If it won't be done the linkage error will happen\n*/", 2);
263+
264+
for (size_t num = 0; num < sigprt->sigs_expr.size(); num++)
265+
{
266+
auto msg = &(sigprt->sigs_expr[num]->msg);
267+
fwriter->AppendLine(PrintF("void FMon_%s_%s(FrameMonitor_t* _mon);",
268+
msg->Name.c_str(), fdesc->drvname.c_str()));
269+
}
270+
271+
fwriter->AppendLine(PrintF("\n#endif // %s", fdesc->usemon_def.c_str()), 2);
272+
273+
fwriter->AppendLine("#ifdef __cplusplus\n}\n#endif");
274+
275+
fwriter->Flush(fdesc->fmon_h.fpath);
276+
}
277+
245278
void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bits, size_t padwidth)
246279
{
247280
if (sig.CommentText.size() > 0)

src/codegen/c-main-generator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class CiMainGenerator {
1717

1818
void Gen_MainHeader();
1919
void Gen_MainSource();
20+
void Gen_FMonHeader();
2021

2122
void WriteSigStructField(const SignalDescriptor_t& sig, bool bitfield, size_t pad);
2223

src/codegen/fs-creator.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ static char _tmpb[kTmpLen];
1313
std::string str_toupper(std::string s)
1414
{
1515
std::transform(s.begin(), s.end(), s.begin(),
16-
[](unsigned char c)
17-
{
18-
return std::toupper(c);
19-
});
16+
[](unsigned char c)
17+
{
18+
return std::toupper(c);
19+
});
2020
return s;
2121
}
2222

2323

2424
std::string str_tolower(std::string s)
2525
{
2626
std::transform(s.begin(), s.end(), s.begin(),
27-
[](unsigned char c)
28-
{
29-
return std::tolower(c);
30-
});
27+
[](unsigned char c)
28+
{
29+
return std::tolower(c);
30+
});
3131
return s;
3232
}
3333

@@ -89,13 +89,21 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
8989
FS.core_c.fpath = work_dir_path + "/" + FS.core_c.fname;
9090

9191
FS.util_h.dir = work_dir_path;
92-
FS.util_h.fname = FS.drvname + "_binutil" + ".h";
92+
FS.util_h.fname = FS.drvname + "-binutil" + ".h";
9393
FS.util_h.fpath = work_dir_path + "/" + FS.util_h.fname;
9494

9595
FS.util_c.dir = work_dir_path;
96-
FS.util_c.fname = FS.drvname + "_binutil" + ".c";
96+
FS.util_c.fname = FS.drvname + "-binutil" + ".c";
9797
FS.util_c.fpath = work_dir_path + "/" + FS.util_c.fname;
9898

99+
FS.fmon_h.dir = work_dir_path;
100+
FS.fmon_h.fname = FS.drvname + "-fmon.h";
101+
FS.fmon_h.fpath = work_dir_path + "/" + FS.fmon_h.fname;
102+
103+
FS.fmon_c.dir = work_dir_path;
104+
FS.fmon_c.fname = FS.drvname + "-fmon.c";
105+
FS.fmon_c.fpath = work_dir_path + "/" + FS.fmon_h.fname;
106+
99107
snprintf(_tmpb, kTmpLen, "%s_USE_BITS_SIGNAL", FS.DRVNAME.c_str());
100108
FS.usebits_def = _tmpb;
101109

src/codegen/fs-creator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ typedef struct
1919
OutFileDescriptor_t util_h;
2020
OutFileDescriptor_t util_c;
2121

22+
OutFileDescriptor_t fmon_h;
23+
OutFileDescriptor_t fmon_c;
24+
2225
std::string usebits_def;
2326
std::string usesruct_def;
2427
std::string usemon_def;

0 commit comments

Comments
 (0)