Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Starkxim opened this issue Oct 21, 2024 · 0 comments

Comments

@Starkxim
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant