@@ -262,7 +262,7 @@ bool DbcLineParser::ParseSignalLine(SignalDescriptor_t* sig, const std::string&
262262// value_type = '+' | '-'; (*+= unsigned, -=signed*)
263263 sig->Signed = (valpart[2 ].find (' -' ) == std::string::npos) ?0 :1 ;
264264
265- sig-> Type = GetSigType (sig);
265+ GetSigType (sig);
266266
267267// mark all simple signals to make using them easier
268268if (!sig->IsDoubleSig && (sig->Factor ==1 ) && (sig->Offset ==0 ))
@@ -312,109 +312,101 @@ SigType DbcLineParser::GetSigType(SignalDescriptor_t* sig)
312312
313313uint64_t max_v =0 ;
314314
315- if (!sig->IsDoubleSig )
315+ // 1 step is to detect type of _ro
316+ int64_t max_abs, min_abs;
317+
318+ int64_t addon =0 ;
319+
320+ if (sig->Signed )
316321 {
317- int64_t i_offset = (int64_t )sig->Offset ;
318- int64_t i_factor = (int64_t )sig->Factor ;
322+ addon =1 ;
323+ max_abs =static_cast <int64_t >( (std::pow (2 , sig->LengthBit -1 ) -1 ) );
324+ min_abs = (max_abs +1 ) * -1 ;
319325
320- // for this case physical value needs to be allowed to
321- // fit inside field type
322- if (sig->Signed )
326+ for (size_t i =0 ; i <4 ; i++)
323327 {
324- // physical_value = raw_value * factor + offset
325- // 1 get the max value for the positive part
326- max_v = (uint64_t )(std::pow (2 , sig->LengthBit -1 ));
327- // 2 scale to max value
328- max_v *= i_factor;
329-
330- // 3 add offset
331- // factor affects on difference between min and max values
332- // abs(max_neg)-(max_pos) = sig->Factor;
333- // so if offset == Factor
334- if (sig->Offset > (int32_t )(sig->Factor -1 ))
335- {
336- // positive value less then
337- max_v = (max_v + i_offset - ((int64_t )sig->Factor ));
338- }
339- else
328+ sig->TypeRo = (SigType)(i);
329+
330+ if (max_abs <= __maxsignedvals[i])
340331 {
341- max_v = (max_v - i_offset) - 1 ;
332+ break ;
342333 }
334+ }
335+ }
336+ else
337+ {
338+ max_abs =static_cast <int64_t >( (std::pow (2 , sig->LengthBit ) -1 ) );
339+ min_abs =0 ;
343340
344- for (uint8_t i =0 ; i <4 ; i++)
341+ for (size_t i =0 ; i <4 ; i++)
342+ {
343+ sig->TypeRo = (SigType)(i +4 );
344+
345+ if (max_abs <= __maxunsigvalues[i])
345346 {
346- if (max_v <= (__maxsignedvals[i]))
347- {
348- ret = (SigType)(i + (is_unsigned *4 ));
349- break ;
350- }
347+ break ;
351348 }
352349 }
353- else
354- {
355- is_unsigned =1 ;
350+ }
356351
357- max_v = (uint64_t )(std::pow (2 , sig->LengthBit )) -1 ;
352+ if (sig->IsSimpleSig )
353+ {
354+ // the most simple case, TypePhys is the same as TypeRo
355+ sig->TypePhys = sig->TypeRo ;
356+ }
358357
359- max_v *= (int32_t )sig->Factor ;
358+ else if (sig->IsDoubleSig ==false )
359+ {
360+ int64_t i_offset = (int64_t )sig->Offset ;
361+ int64_t i_factor = (int64_t )sig->Factor ;
360362
361- if (sig->Offset >=0 )
363+ // get max and min values with applied factor and offset (physical values)
364+ max_abs = max_abs * i_factor + i_offset;
365+ min_abs = min_abs * i_factor + i_offset;
366+
367+ if (sig->Signed || max_abs <0 || min_abs <0 )
368+ {
369+ // phys value must be signed
370+ uint64_t max_v =std::abs (max_abs);
371+ uint64_t addon =0 ;
372+
373+ if ((max_v +1 ) <std::abs (min_abs))
362374 {
363- // when offset positive the max physical value isgot just
364- // adding roffset value
365- max_v+= roffset ;
375+ // low part ismain
376+ addon = 1 ;
377+ max_v= std::abs (min_abs) ;
366378 }
367- else
379+
380+ for (size_t i =0 ; i <4 ; i++)
368381 {
369- is_unsigned =0 ;
370- // this code must determmine which part of range is larger - positive or negative
371- // the largest part will define which sig type will be used for signal
372- // roffset here - negative value
373-
374- // max positive value fot the LenBits if it would have signed type
375- uint64_t maxpos = (uint64_t )(std::pow (2 , sig->LengthBit ) -1 );
376- // max negative value
377- uint64_t maxneg = (uint64_t )(std::abs (roffset));
378-
379- max_v =std::max (maxpos, maxneg);
380- // mul 2 for using unsinged compare levels (int8_t (127) like uint8_t (255))
381- max_v *=2 ;
382- }
382+ sig->TypePhys = (SigType)(i);
383383
384+ if (max_v <= __maxsignedvals[i] + addon)
385+ {
386+ break ;
387+ }
388+ }
389+ }
390+ else
391+ {
392+ // phys value must be unsigned
384393for (uint8_t i =0 ; i <4 ; i++)
385394 {
386- if (max_v <=( __maxunsigvalues[i]) )
395+ if (( uint64_t )max_abs <= __maxunsigvalues[i])
387396 {
388- ret = (SigType)(i +(is_unsigned * 4 ) );
397+ sig-> TypePhys = (SigType)(i +4 );
389398break ;
390399 }
391400 }
392401 }
393402 }
394403else
395404 {
396- // this type definition is simple (without
397- // additional type-expanded operations inside
398- // main driver, so to determine type simple
399- // operations is needed
400- max_v = (uint64_t )(std::pow (2 , sig->LengthBit ) -1 );
401-
402- if (!sig->Signed )
403- {
404- is_unsigned =1 ;
405- }
406-
407- for (uint8_t i =0 ; i <4 ; i++)
408- {
409- if (max_v <= __maxunsigvalues[i])
410- {
411- ret = (SigType)(i + (is_unsigned *4 ));
412- break ;
413- }
414- }
405+ // in this case TypePhys will be (sigfloat_t), so
406+ // there is no necessity to determine physical signal type
415407 }
416408
417- return ret ;
409+ return sig-> TypeRo ;
418410}
419411
420412bool DbcLineParser::ParseCommentLine (Comment_t* cm,const std::string& line)