Skip to content

Commit b5a687b

Browse files
committed
Fixed integer x = ***_toS(x) issue. Added postfix *_ro to non simple signals.
1 parent 43730ed commit b5a687b

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/codegen/c-main-generator.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -456,19 +456,26 @@ void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bi
456456

457457
fwriter->AppendLine("", 2);
458458

459-
if (sig.IsDoubleSig)
459+
if (!sig.IsSimpleSig)
460460
{
461461
// this code only required be d-signals (floating point values based)
462462
// it placed additional signals to struct for conversion
463463
// to/from physical values. For non-simple and non-double signal
464464
// there is no necessity to create addition fields
465465
// @sigfloat_t must be typedefed by user (e.g. double / float)
466+
467+
// UPD: from this commit, all non-Simple signals has it's
468+
// own 'shadow' (_phys) copies, the problem with intermediate type (not simpe and
469+
// not double) is that the x = ***_toS(x) takes place in each Pack_* call
470+
// the signals which are not changing from Pack_* to Pack_* will change its values (!)
466471
fwriter->AppendLine(StrPrint("#ifdef %s", fdesc->usesigfloat_def.c_str()));
467472

468-
fwriter->AppendLine(StrPrint(" sigfloat_t %s_phys;", sig.Name.c_str()));
473+
if (sig.IsDoubleSig)
474+
fwriter->AppendLine(StrPrint(" sigfloat_t %s;", sig.NameFloat.c_str()));
475+
else
476+
fwriter->AppendLine(StrPrint(" %s %s;", PrintType((int)sig.Type).c_str(), sig.NameFloat.c_str()));
469477

470478
fwriter->AppendLine(StrPrint("#endif // %s", fdesc->usesigfloat_def.c_str()), 2);
471-
472479
}
473480
}
474481

@@ -484,23 +491,14 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
484491
fwriter->AppendLine(StrPrint(" _m->%s = %s;", sname, expr.c_str()));
485492

486493
// print sigfloat conversion
487-
if (sgs->msg.Signals[num].IsDoubleSig)
494+
if (!sgs->msg.Signals[num].IsSimpleSig)
488495
{
489496
fwriter->AppendLine(StrPrint("#ifdef %s", fdesc->usesigfloat_def.c_str()));
490-
fwriter->AppendLine(StrPrint(" _m->%s_phys = (sigfloat_t)(%s_%s_fromS(_m->%s));", sname, fdesc->DRVNAME.c_str(), sname,
491-
sname));
497+
fwriter->AppendLine(StrPrint(" _m->%s = (sigfloat_t)(%s_%s_fromS(_m->%s));",
498+
sgs->msg.Signals[num].NameFloat.c_str(), fdesc->DRVNAME.c_str(), sname, sname));
492499
fwriter->AppendLine(StrPrint("#endif // %s", fdesc->usesigfloat_def.c_str()), 2);
493500
}
494501

495-
else if (!sgs->msg.Signals[num].IsSimpleSig)
496-
{
497-
// print unpack conversion for non-simple and non-double signals
498-
// for this case conversion fromS is performed to signal itself
499-
// without (sigfloat_t) type casting
500-
fwriter->AppendLine(StrPrint("#ifdef %s", fdesc->usesigfloat_def.c_str()));
501-
fwriter->AppendLine(StrPrint(" _m->%s = (%s_%s_fromS(_m->%s));", sname, fdesc->DRVNAME.c_str(), sname, sname));
502-
fwriter->AppendLine(StrPrint("#endif // %s", fdesc->usesigfloat_def.c_str()), 2);
503-
}
504502
else if (num + 1 == sgs->to_signals.size())
505503
{
506504
// last signal without phys part, put \n manually
@@ -604,9 +602,9 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp
604602
if (sgs->msg.Signals[n].IsDoubleSig)
605603
{
606604
// print toS from *_phys to original named sigint (integer duplicate of signal)
607-
fwriter->AppendLine(StrPrint(" _m->%s = %s_%s_toS(_m->%s_phys);",
605+
fwriter->AppendLine(StrPrint(" _m->%s = %s_%s_toS(_m->%s);",
608606
sgs->msg.Signals[n].Name.c_str(), fdesc->DRVNAME.c_str(),
609-
sgs->msg.Signals[n].Name.c_str(), sgs->msg.Signals[n].Name.c_str()));
607+
sgs->msg.Signals[n].Name.c_str(), sgs->msg.Signals[n].NameFloat.c_str()));
610608
}
611609
else
612610
{

src/parser/dbclineparser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ bool DbcLineParser::ParseSignalLine(SignalDescriptor_t* sig, const std::string&
231231
{
232232
sig->IsSimpleSig = true;
233233
}
234+
235+
if (!sig->IsSimpleSig)
236+
{
237+
// For this case the name of signal must be marked specially
238+
// to pay attention that if SIGFLOAT is enabled, this signal
239+
// must behave as ReadOnly (_ro)
240+
sig->NameFloat = sig->Name + "_phys";
241+
sig->Name += "_ro";
242+
}
234243
}
235244

236245
if (tailpart.size() == 3)

src/types/message.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ typedef struct
3737
{
3838
// Signal name
3939
std::string Name;
40-
40+
// Signal float name
41+
std::string NameFloat;
4142
// Unit
4243
std::string Unit;
4344

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy