@@ -37,25 +37,13 @@ char* PrintF(const char* format, ...)
3737return wbuff;
3838}
3939
40- std::stringstr_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-
5040CiMainGenerator::CiMainGenerator ()
5141{
5242 sigprt =new CSigPrinter;
5343 fwriter =new FileWriter;
5444}
5545
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)
5947{
6048// Load income messages to sig printer
6149 sigprt->LoadMessages (msgs);
@@ -66,21 +54,6 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs,
6654return a->msg .MsgID < b->msg .MsgID ;
6755 });
6856
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-
8457// 2 step is to print main head file
8558 fwriter->AppendLine (" #pragma once" ,2 );
8659 fwriter->AppendLine (" #ifdef __cplusplus\n extern\" C\" {\n #endif" ,2 );
@@ -180,28 +153,28 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs,
180153 {
181154// write message typedef s and additional expressions
182155 MessageDescriptor_t& m = sigprt->sigs_expr [num]->msg ;
183-
156+
184157 fwriter->AppendLine (
185158PrintF (" 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 ()));
187160
188161 fwriter->AppendLine (PrintF (" #ifdef %s" , usestruct_str.c_str ()));
189-
162+
190163 fwriter->AppendLine (
191164PrintF (" 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+
194167 fwriter->AppendLine (" #else" );
195-
168+
196169 fwriter->AppendLine (
197170PrintF (" 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 ()));
199172
200173 fwriter->AppendLine (PrintF (" #endif // %s" , usestruct_str.c_str ()),2 );
201174 }
202175
203176 fwriter->AppendLine (" #ifdef __cplusplus\n }\n #endif" );
204- fwriter->Flush (mhead .fpath );
177+ fwriter->Flush (fsd. core_h .fpath );
205178
206179// 3 step is to print main source file
207180
@@ -269,48 +242,3 @@ void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bi
269242 fwriter->AppendLine (" " ,2 );
270243}
271244
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- }