22#include " helpers/formatter.h"
33
44uint32_t MonGenerator::FillHeader (FileWriter& wr, std::vector<CiExpr_t*>& sigs,
5- const GenDescriptor_t& gsett )
5+ const AppSettings_t& aset )
66{
7- wr.Append (" #ifdef %s_USE_MONO_FMON" , gsett.DRVNAME .c_str ());
7+ if (aset.gen .start_info .size () >0 )
8+ {
9+ wr.Append (aset.gen .start_info );
10+ }
11+
12+ wr.Append (" #pragma once" );
13+ wr.Append ();
14+
15+ wr.Append (" #ifdef __cplusplus\n extern\" C\" {\n #endif" );
16+ wr.Append ();
17+
18+ wr.Append (" // DBC file version" );
19+ wr.Append (" #define %s_FMON (%uU)" , aset.gen .verhigh_def .c_str (), aset.gen .hiver );
20+ wr.Append (" #define %s_FMON (%uU)" , aset.gen .verlow_def .c_str (), aset.gen .lowver );
821 wr.Append ();
922
10- wr.Append (" void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid);" , gsett.drvname .c_str ());
23+ wr.Append (" #include <%s-config.h>" , aset.gen .drvname .c_str ());
24+ wr.Append ();
25+
26+ // put diagmonitor ifdef selection for including @drv-fmon header
27+ // with FMon_* signatures to call from unpack function
28+ wr.Append (" #ifdef %s" , aset.gen .usemon_def .c_str ());
29+ wr.Append ();
30+ wr.Append (" #include <canmonitorutil.h>" );
31+ wr.Append (" /*\n \
32+ This file contains the prototypes of all the functions that will be called\n \
33+ from each Unpack_*name* function to detect DBC related errors\n \
34+ 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 */" );
36+ wr.Append ();
37+
38+ wr.Append (" #ifdef %s_USE_MONO_FMON" , aset.gen .DRVNAME .c_str ());
39+ wr.Append ();
40+
41+ wr.Append (" void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid);" , aset.gen .drvname .c_str ());
1142 wr.Append ();
1243
1344for (auto it = sigs.begin (); it != sigs.end (); ++it)
1445 {
1546
1647auto msg = &((*it)->msg );
1748 wr.Append (" #define FMon_%s_%s(x, y) _FMon_MONO_%s((x), (y))" , msg->Name .c_str (),
18- gsett .drvname .c_str (),
19- gsett .drvname .c_str ());
49+ aset. gen .drvname .c_str (),
50+ aset. gen .drvname .c_str ());
2051 }
2152
2253 wr.Append ();
@@ -27,7 +58,7 @@ uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
2758 {
2859auto msg = &((*it)->msg );
2960 wr.Append (" void _FMon_%s_%s(FrameMonitor_t* _mon, uint32_t msgid);" ,
30- msg->Name .c_str (),gsett .drvname .c_str ());
61+ msg->Name .c_str (),aset. gen .drvname .c_str ());
3162 }
3263
3364 wr.Append ();
@@ -36,23 +67,45 @@ uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
3667 {
3768auto msg = &((*it)->msg );
3869 wr.Append (" #define FMon_%s_%s(x, y) _FMon_%s_%s((x), (y))" ,
39- msg->Name .c_str (),gsett .drvname .c_str (),
40- msg->Name .c_str (),gsett .drvname .c_str ());
70+ msg->Name .c_str (),aset. gen .drvname .c_str (),
71+ msg->Name .c_str (),aset. gen .drvname .c_str ());
4172 }
4273
4374 wr.Append ();
4475 wr.Append (" #endif" );
4576 wr.Append ();
4677
78+ wr.Append (" #endif // %s" , aset.gen .usemon_def .c_str ());
79+ wr.Append ();
80+
81+ wr.Append (" #ifdef __cplusplus\n }\n #endif" );
82+
4783return 0 ;
4884}
4985
5086uint32_t MonGenerator::FillSource (FileWriter& wr, std::vector<CiExpr_t*>& sigs,
51- const GenDescriptor_t& gsett )
87+ const AppSettings_t& aset )
5288{
53- wr.Append (" #ifdef %s_USE_MONO_FMON" , gsett.DRVNAME .c_str ());
89+ if (aset.gen .start_info .size () >0 )
90+ {
91+ wr.Append (aset.gen .start_info );
92+ }
93+
94+ wr.Append (" #include <%s>" , aset.file .fmon_h .fname .c_str ());
95+ wr.Append ();
96+ // put diagmonitor ifdef selection for including @drv-fmon header
97+ // with FMon_* signatures to call from unpack function
98+ wr.Append (" #ifdef %s" , aset.gen .usemon_def .c_str ());
99+ wr.Append ();
100+
101+ wr.Append (" /*\n \
102+ Put the monitor function content here, keep in mind -\n \
103+ next generation will completely clear all manually added code (!)\n \
104+ */\n\n " );
105+
106+ wr.Append (" #ifdef %s_USE_MONO_FMON" , aset.gen .DRVNAME .c_str ());
54107 wr.Append ();
55- wr.Append (" void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid)" ,gsett .drvname .c_str ());
108+ wr.Append (" void _FMon_MONO_%s(FrameMonitor_t* _mon, uint32_t msgid)" ,aset. gen .drvname .c_str ());
56109 wr.Append (" {" );
57110 wr.Append (" (void)_mon;" );
58111 wr.Append (" (void)msgid;" );
@@ -65,11 +118,13 @@ uint32_t MonGenerator::FillSource(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
65118 {
66119auto msg = &((*it)->msg );
67120 wr.Append (" void _FMon_%s_%s(FrameMonitor_t* _mon, uint32_t msgid)\n {\n (void)_mon;\n (void)msgid;\n }\n\n " ,
68- msg->Name .c_str (),gsett .drvname .c_str ());
121+ msg->Name .c_str (),aset. gen .drvname .c_str ());
69122 }
70123
71- wr.Append (" #endif // %s_USE_MONO_FMON" ,gsett .DRVNAME .c_str ());
124+ wr.Append (" #endif // %s_USE_MONO_FMON" ,aset. gen .DRVNAME .c_str ());
72125 wr.Append ();
73126
127+ wr.Append (" #endif // %s" , aset.gen .usemon_def .c_str ());
128+
74129return 0 ;
75130}