@@ -37,25 +37,13 @@ char* PrintF(const char* format, ...)
37
37
return wbuff;
38
38
}
39
39
40
- std::string str_toupper (std::string s)
41
- {
42
- std::transform (s.begin (), s.end (), s.begin (),
43
- [](unsigned char c)
44
- {
45
- return std::toupper (c);
46
- });
47
- return s;
48
- }
49
-
50
40
CiMainGenerator::CiMainGenerator ()
51
41
{
52
42
sigprt = new CSigPrinter;
53
43
fwriter = new FileWriter;
54
44
}
55
45
56
- void CiMainGenerator::Generate (std::vector<MessageDescriptor_t*>& msgs,
57
- std::string drvname,
58
- std::string dirpath)
46
+ void CiMainGenerator::Generate (std::vector<MessageDescriptor_t*>& msgs, const FsDescriptor_t& fsd)
59
47
{
60
48
// Load income messages to sig printer
61
49
sigprt->LoadMessages (msgs);
@@ -66,21 +54,6 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs,
66
54
return a->msg .MsgID < b->msg .MsgID ;
67
55
});
68
56
69
- auto dirok = SetFinalPath (dirpath);
70
-
71
- if (!dirok)
72
- {
73
- // TODO: handle error if directory cannot be used
74
- }
75
-
76
- SetCommonValues (drvname);
77
-
78
- // work_dir_path has the base dir path to gen files
79
- // 1 step is to define final directory for source code bunch
80
- mhead.dir = work_dir_path;
81
- mhead.fname = drvname + " .h" ;
82
- mhead.fpath = mhead.dir + " /" + mhead.fname ;
83
-
84
57
// 2 step is to print main head file
85
58
fwriter->AppendLine (" #pragma once" , 2 );
86
59
fwriter->AppendLine (" #ifdef __cplusplus\n extern \" C\" {\n #endif" , 2 );
@@ -180,28 +153,28 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs,
180
153
{
181
154
// write message typedef s and additional expressions
182
155
MessageDescriptor_t& m = sigprt->sigs_expr [num]->msg ;
183
-
156
+
184
157
fwriter->AppendLine (
185
158
PrintF (" uint32_t Unpack_%s_%s(%s_t* _m, const uint8_t* _d, uint8_t dlc_);" ,
186
- m.Name .c_str (), drvname.c_str (), m.Name .c_str ()));
159
+ m.Name .c_str (), fsd. drvname .c_str (), m.Name .c_str ()));
187
160
188
161
fwriter->AppendLine (PrintF (" #ifdef %s" , usestruct_str.c_str ()));
189
-
162
+
190
163
fwriter->AppendLine (
191
164
PrintF (" uint32_t Pack_%s_%s(const %s_t* _m, __CoderDbcCanFrame_t__* cframe);" ,
192
- m.Name .c_str (), drvname.c_str (), m.Name .c_str ()));
193
-
165
+ m.Name .c_str (), fsd. drvname .c_str (), m.Name .c_str ()));
166
+
194
167
fwriter->AppendLine (" #else" );
195
-
168
+
196
169
fwriter->AppendLine (
197
170
PrintF (" uint32_t Pack_%s_%s(const %s_t* _m, uint8_t* _d, uint8_t* _len, uint8_t* _ide);" ,
198
- m.Name .c_str (), drvname.c_str (), m.Name .c_str ()));
171
+ m.Name .c_str (), fsd. drvname .c_str (), m.Name .c_str ()));
199
172
200
173
fwriter->AppendLine (PrintF (" #endif // %s" , usestruct_str.c_str ()), 2 );
201
174
}
202
175
203
176
fwriter->AppendLine (" #ifdef __cplusplus\n }\n #endif" );
204
- fwriter->Flush (mhead .fpath );
177
+ fwriter->Flush (fsd. core_h .fpath );
205
178
206
179
// 3 step is to print main source file
207
180
@@ -269,48 +242,3 @@ void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bi
269
242
fwriter->AppendLine (" " , 2 );
270
243
}
271
244
272
- bool CiMainGenerator::SetFinalPath (std::string dirpath)
273
- {
274
- // find free directory
275
- struct stat info;
276
-
277
- for (int32_t dirnum = 0 ; dirnum < 1000 ; dirnum++)
278
- {
279
- snprintf (wbuff, kWBUFF_len , " %03d" , dirnum);
280
- work_dir_path = dirpath + " /" + wbuff;
281
-
282
- if (stat (work_dir_path.c_str (), &info) != 0 )
283
- {
284
- if (std::filesystem::create_directory (work_dir_path))
285
- return true ;
286
- else
287
- return false ;
288
- }
289
- else if (info.st_mode & S_IFDIR)
290
- {
291
- // directory exists, try next num
292
- continue ;
293
- }
294
- else
295
- {
296
- if (std::filesystem::create_directory (work_dir_path) != 0 )
297
- return false ;
298
- }
299
- }
300
-
301
- return true ;
302
- }
303
-
304
- void CiMainGenerator::SetCommonValues (const std::string& drvname)
305
- {
306
- DRVNAME = str_toupper (drvname);
307
-
308
- snprintf (wbuff, kWBUFF_len , " %s_USE_BITS_SIGNAL" , DRVNAME.c_str ());
309
- usebits_str = wbuff;
310
-
311
- snprintf (wbuff, kWBUFF_len , " %s_USE_DIAG_MONITORS" , DRVNAME.c_str ());
312
- usediag_str = wbuff;
313
-
314
- snprintf (wbuff, kWBUFF_len , " %s_USE_CANSTRUCT" , DRVNAME.c_str ());
315
- usestruct_str = wbuff;
316
- }
0 commit comments