Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1557550

Browse files
committed
Basic struct and unpack func in -c main source code.
1 parentbf0ed04 commit1557550

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

‎src/codegen/c-main-generator.cpp‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const Fs
4848
// Load income messages to sig printer
4949
sigprt->LoadMessages(msgs);
5050

51+
// save pointer to output file descriptor struct to
52+
// enable using this information inside class member functions
53+
fdesc = &fsd;
54+
5155
std::sort(sigprt->sigs_expr.begin(), sigprt->sigs_expr.end(),
5256
[](const CiExpr_t* a,const CiExpr_t* b) ->bool
5357
{
@@ -177,7 +181,59 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const Fs
177181
fwriter->Flush(fsd.core_h.fpath);
178182

179183
// 3 step is to print main source file
184+
// include main header file
185+
fwriter->AppendLine(PrintF("#include""%s""", fsd.core_h.fname.c_str()),3);
186+
187+
// put diagmonitor ifdef selection for including @drv-fmon header
188+
// with FMon_* signatures to call from unpack function
189+
fwriter->AppendLine(PrintF("#ifdef %s", fsd.usemon_def.c_str()));
190+
191+
fwriter->AppendText(
192+
"// This file must define:\n"
193+
"// base monitor struct\n"
194+
"// function signature for CRC calculation\n"
195+
"// function signature for getting system tick value (100 us step)\n");
196+
197+
fwriter->AppendLine(PrintF("#include""%s-fmon.h""", fsd.drvname.c_str()),2);
198+
199+
fwriter->AppendLine(PrintF("#endif // %s", fsd.usemon_def.c_str()),3);
180200

201+
// for each message 3 functions must be defined - 1 unpack function,
202+
// 2: pack with raw signature
203+
// 3: pack with canstruct
204+
for (size_t num =0; num < sigprt->sigs_expr.size(); num++)
205+
{
206+
// write message typedef s and additional expressions
207+
MessageDescriptor_t& m = sigprt->sigs_expr[num]->msg;
208+
209+
// first function
210+
fwriter->AppendLine(
211+
PrintF("uint32_t Unpack_%s_%s(%s_t* _m, const uint8_t* _d, uint8_t dlc_)\n{",
212+
m.Name.c_str(), fsd.DrvName_orig.c_str(), m.Name.c_str()));
213+
214+
WriteUnpackBody(sigprt->sigs_expr[num]);
215+
216+
fwriter->AppendLine("}",2);
217+
218+
219+
fwriter->AppendLine(PrintF("#ifdef %s", fsd.usesruct_def.c_str()));
220+
221+
// second function
222+
fwriter->AppendLine(
223+
PrintF("uint32_t Pack_%s_%s(const %s_t* _m, __CoderDbcCanFrame_t__* cframe);",
224+
m.Name.c_str(), fsd.DrvName_orig.c_str(), m.Name.c_str()));
225+
226+
fwriter->AppendLine("#else");
227+
228+
// third function
229+
fwriter->AppendLine(
230+
PrintF("uint32_t Pack_%s_%s(const %s_t* _m, uint8_t* _d, uint8_t* _len, uint8_t* _ide);",
231+
m.Name.c_str(), fsd.DrvName_orig.c_str(), m.Name.c_str()));
232+
233+
fwriter->AppendLine(PrintF("#endif // %s", fsd.usesruct_def.c_str()),2);
234+
}
235+
236+
fwriter->Flush(fsd.core_c.fpath);
181237
// 4 step is to pring fmon head file
182238

183239
// 5 step is to print fmon source file
@@ -237,3 +293,36 @@ void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bi
237293
fwriter->AppendLine("",2);
238294
}
239295

296+
voidCiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
297+
{
298+
for (size_t num =0; num < sgs->to_signals.size(); num++)
299+
{
300+
auto expr = sgs->to_signals[num];
301+
302+
fwriter->AppendLine(PrintF(" _m->%s = %s;", sgs->msg.Signals[num].Name.c_str(), expr.c_str()));
303+
}
304+
305+
fwriter->AppendLine("");
306+
307+
fwriter->AppendLine(PrintF("#ifdef %s", fdesc->usemon_def.c_str()));
308+
309+
fwriter->AppendLine(" // check DLC correctness");
310+
fwriter->AppendLine(PrintF(" _m->mon1.dlc_error = (dlc_ < %s_DLC);", sgs->msg.Name.c_str()));
311+
312+
313+
// TODO: put CRC and ROLLING COUNTER tests here
314+
// 1
315+
// 2
316+
317+
318+
fwriter->AppendLine(" _m->mon1.last_cycle = GetSysTick();");
319+
fwriter->AppendLine(" _m->mon1.frame_cnt++;",2);
320+
321+
auto Fmon_func ="FMon_" + sgs->msg.Name +"_" + fdesc->drvname;
322+
323+
fwriter->AppendLine(PrintF(" %s(&_m->mon1);", Fmon_func.c_str()));
324+
325+
fwriter->AppendLine(PrintF("#endif // %s", fdesc->usemon_def.c_str()),2);
326+
327+
fwriter->AppendLine(PrintF(" return %s_CANID;", sgs->msg.Name.c_str()));
328+
}

‎src/codegen/c-main-generator.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ class CiMainGenerator {
1717

1818
voidWriteSigStructField(const SignalDescriptor_t& sig,bool bitfield,size_t pad);
1919

20+
voidWriteUnpackBody(const CiExpr_t* sgs);
21+
2022
private:
2123
std::vector<std::string> tmpvect;
2224

2325
CSigPrinter* sigprt;
2426

2527
FileWriter* fwriter;
28+
29+
const FsDescriptor_t* fdesc;
2630
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp