DbcParser icon indicating copy to clipboard operation
DbcParser copied to clipboard

Problems in parsing CycleTime in a file when CycleTime is defined as FLOAT

Open Starkxim opened this issue 2 years ago • 0 comments

Hello, I wanted to parse dbc messages from a .dbc file using DbcParser. In my file CycleTime is defined as: BA_DEF_ BO_ "GenMsgCycleTime" FLOAT 0 300000; // [ms]

But the function in

DbcParser-1.7.0\DbcParserLib\ExtensionsAndHelpers.cs

public static bool CycleTime(this Message message, out int cycleTime)
        {
            cycleTime = 0;

            if (message.CustomProperties.TryGetValue("GenMsgCycleTime", out var property))
            {
                cycleTime = property.IntegerCustomProperty.Value;
                return true;
            }
            else
                return false;
        }

It doesn't take into account that it could be defined as a FLOAT, so in parsing as: BA_ "GenMsgCycleTime" BO_ 298 20.000. It will report an error and will not run. image I modified the code a bit to make it able to read FLOAT type cycletime:

public static bool CycleTime(this Message message, out int cycleTime)
        {
            cycleTime = 0;

            if (message.CustomProperties.TryGetValue("GenMsgCycleTime", out var property))
            {
                if (property.IntegerCustomProperty != null)
                {
                    cycleTime = property.IntegerCustomProperty.Value;
                    return true;
                }
                else if (property.FloatCustomProperty != null)
                {
                    cycleTime = (int)property.FloatCustomProperty.Value;
                    return true;
                }
            }
            return false;
        }

Finally, good luck with your work, and thank you.

Starkxim avatar Oct 21 '24 05:10 Starkxim