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

Commit2cd8af4

Browse files
committed
Added "*_phys" sigs and auto toS/fromS conversion.
1 parente95d50a commit2cd8af4

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

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

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const Fs
9191
{
9292
SignalDescriptor_t& s = m.Signals[signum];
9393

94-
// TODO: print signal to_S and from_S definitions if necessary
95-
if (s.IsDoubleSig ==true || ((s.Factor !=1) || (s.Offset !=0)))
94+
if (!s.IsSimpleSig)
9695
{
9796
fwriter->AppendLine(sigprt->PrintPhysicalToRaw(&s, fsd.DRVNAME));
9897
}
@@ -282,6 +281,21 @@ void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bi
282281
}
283282

284283
fwriter->AppendLine("",2);
284+
285+
if (sig.IsDoubleSig)
286+
{
287+
// this code only required be d-signals (floating point values based)
288+
// it placed additional signals to struct for conversion
289+
// to/from physical values. For non-simple and non-double signal
290+
// there is no necessity to create addition fields
291+
// @sigfloat_t must be typedefed by user (e.g. double / float)
292+
fwriter->AppendLine(PrintF("#ifdef %s", fdesc->usesigfloat_def.c_str()));
293+
294+
fwriter->AppendLine(PrintF(" sigfloat_t %s_phys;", sig.Name.c_str()));
295+
296+
fwriter->AppendLine(PrintF("#endif // %s", fdesc->usesigfloat_def.c_str()),2);
297+
298+
}
285299
}
286300

287301
voidCiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
@@ -291,6 +305,28 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
291305
auto expr = sgs->to_signals[num];
292306

293307
fwriter->AppendLine(PrintF(" _m->%s = %s;", sgs->msg.Signals[num].Name.c_str(), expr.c_str()));
308+
309+
// print sigfloat conversion
310+
if (sgs->msg.Signals[num].IsDoubleSig)
311+
{
312+
fwriter->AppendLine(PrintF("\n#ifdef %s", fdesc->usesigfloat_def.c_str()));
313+
fwriter->AppendLine(PrintF(" _m->%s_phys = (sigfloat_t)(%s_%s_fromS(_m->%s));",
314+
sgs->msg.Signals[num].Name.c_str(), fdesc->DRVNAME.c_str(),
315+
sgs->msg.Signals[num].Name.c_str(), sgs->msg.Signals[num].Name.c_str()));
316+
fwriter->AppendLine(PrintF("#endif // %s", fdesc->usesigfloat_def.c_str()),2);
317+
}
318+
319+
elseif (!sgs->msg.Signals[num].IsSimpleSig)
320+
{
321+
// print unpack conversion for non-simple and non-double signals
322+
// for this case conversion fromS is performed to signal itself
323+
// without (sigfloat_t) type casting
324+
fwriter->AppendLine(PrintF("\n#ifdef %s", fdesc->usesigfloat_def.c_str()));
325+
fwriter->AppendLine(PrintF(" _m->%s = (%s_%s_fromS(_m->%s));",
326+
sgs->msg.Signals[num].Name.c_str(), fdesc->DRVNAME.c_str(),
327+
sgs->msg.Signals[num].Name.c_str(), sgs->msg.Signals[num].Name.c_str()));
328+
fwriter->AppendLine(PrintF("#endif // %s", fdesc->usesigfloat_def.c_str()),2);
329+
}
294330
}
295331

296332
fwriter->AppendLine("");
@@ -323,9 +359,36 @@ void CiMainGenerator::WritePackStructBody(const CiExpr_t* sgs)
323359
fwriter->AppendLine("{");
324360

325361
// pring array content clearin loop
326-
fwriter->AppendLine(
327-
PrintF(" uint8_t i; for (i = 0; (i < %s_DLC) && (i < 8); cframe->Data[i++] = 0);",
328-
sgs->msg.Name.c_str()),2);
362+
fwriter->AppendLine(PrintF(" uint8_t i; for (i = 0; (i < %s_DLC) && (i < 8); cframe->Data[i++] = 0);",
363+
sgs->msg.Name.c_str()),2);
364+
365+
// first step is to put code for sigfloat conversion, before
366+
// sigint packing to bytes.
367+
fwriter->AppendLine(PrintF("#ifdef %s", fdesc->usesigfloat_def.c_str()),2);
368+
369+
for (size_t n =0; n < sgs->to_signals.size(); n++)
370+
{
371+
if (sgs->msg.Signals[n].IsSimpleSig ==false)
372+
{
373+
if (sgs->msg.Signals[n].IsDoubleSig)
374+
{
375+
// print toS from *_phys to original named sigint (integer duplicate of signal)
376+
fwriter->AppendLine(PrintF(" _m->%s = %s_%s_fromS(_m->%s_phys);",
377+
sgs->msg.Signals[n].Name.c_str(), fdesc->DRVNAME.c_str(),
378+
sgs->msg.Signals[n].Name.c_str(), sgs->msg.Signals[n].Name.c_str()));
379+
}
380+
else
381+
{
382+
// print toS from original named signal to itself (because this signal
383+
// has enough space for scaling by factor and proper sign
384+
fwriter->AppendLine(PrintF(" _m->%s = %s_%s_fromS(_m->%s);",
385+
sgs->msg.Signals[n].Name.c_str(), fdesc->DRVNAME.c_str(),
386+
sgs->msg.Signals[n].Name.c_str(), sgs->msg.Signals[n].Name.c_str()));
387+
}
388+
}
389+
}
390+
391+
fwriter->AppendLine(PrintF("\n#endif // %s", fdesc->usesigfloat_def.c_str()),2);
329392

330393
for (size_t i =0; i < sgs->to_bytes.size(); i++)
331394
{
@@ -352,6 +415,34 @@ void CiMainGenerator::WritePackArrayBody(const CiExpr_t* sgs)
352415
fwriter->AppendLine(PrintF(" uint8_t i; for (i = 0; (i < %s_DLC) && (i < 8); _d[i++] = 0);",
353416
sgs->msg.Name.c_str()),2);
354417

418+
// first step is to put code for sigfloat conversion, before
419+
// sigint packing to bytes.
420+
fwriter->AppendLine(PrintF("#ifdef %s", fdesc->usesigfloat_def.c_str()),2);
421+
422+
for (size_t n =0; n < sgs->to_signals.size(); n++)
423+
{
424+
if (sgs->msg.Signals[n].IsSimpleSig ==false)
425+
{
426+
if (sgs->msg.Signals[n].IsDoubleSig)
427+
{
428+
// print toS from *_phys to original named sigint (integer duplicate of signal)
429+
fwriter->AppendLine(PrintF(" _m->%s = %s_%s_fromS(_m->%s_phys);",
430+
sgs->msg.Signals[n].Name.c_str(), fdesc->DRVNAME.c_str(),
431+
sgs->msg.Signals[n].Name.c_str(), sgs->msg.Signals[n].Name.c_str()));
432+
}
433+
else
434+
{
435+
// print toS from original named signal to itself (because this signal
436+
// has enough space for scaling by factor and proper sign
437+
fwriter->AppendLine(PrintF(" _m->%s = %s_%s_fromS(_m->%s);",
438+
sgs->msg.Signals[n].Name.c_str(), fdesc->DRVNAME.c_str(),
439+
sgs->msg.Signals[n].Name.c_str(), sgs->msg.Signals[n].Name.c_str()));
440+
}
441+
}
442+
}
443+
444+
fwriter->AppendLine(PrintF("\n#endif // %s", fdesc->usesigfloat_def.c_str()),2);
445+
355446
for (size_t i =0; i < sgs->to_bytes.size(); i++)
356447
{
357448
if (sgs->to_bytes[i].size() <2)

‎src/codegen/fs-creator.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
102102
snprintf(_tmpb,kTmpLen,"%s_USE_DIAG_MONITORS", FS.DRVNAME.c_str());
103103
FS.usemon_def = _tmpb;
104104

105+
snprintf(_tmpb,kTmpLen,"%s_USE_SIGFLOAT", FS.DRVNAME.c_str());
106+
FS.usesigfloat_def = _tmpb;
107+
105108
snprintf(_tmpb,kTmpLen,"%s_USE_CANSTRUCT", FS.DRVNAME.c_str());
106109
FS.usesruct_def = _tmpb;
107110
}

‎src/codegen/fs-creator.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct
2222
std::string usebits_def;
2323
std::string usesruct_def;
2424
std::string usemon_def;
25+
std::string usesigfloat_def;
2526

2627
} FsDescriptor_t;
2728

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp