EFeru / DbcParser

.NET CAN bus dbc file parser
MIT License
75 stars 26 forks source link

Custom properties and default value association #93

Open Adhara3 opened 1 month ago

Adhara3 commented 1 month ago

Hello,

I have a question regarding .CustomProperties property. From what I can tell, it is meant to store custom properties individually for a message/signal/node based on names/IDs, but when printing out these values, for example: foreach (var message in dbc.Messages) { foreach (var kvp in message.CustomProperties) { var key = kvp.Key; Console.WriteLine(key); } Console.WriteLine(string.Empty); }, I would get all of the attribute names existent in the dbc file for each message, repeatedly. It does not appear that the custom properties they store are unique to them, but just generally present in the dbc. I have checked the dbc file I am parsing, and it does not have all of these properties assigned to every message. The same problem appears with signals and nodes.

I am trying to avoid opening a new issue on this because it might just be my misunderstanding. Could somebody explain please? Thank you in advance

Originally posted by @sToman967 in https://github.com/EFeru/DbcParser/issues/91#issuecomment-2363355678

Adhara3 commented 1 month ago

Originally written by @Whitehouse112

Hi, I think it all depends on how this sentences (from documentation) are interpreted:

"User defined attributes are a means to extend the object properties of the DBC file. These additional attributes have to be defined using an attribute definition with an attribute default value. For each object having a value defined for the attribute an attribute value entry has to be defined. If no attribute value entry is defined for an object the value of the object's attribute is the attribute's default."

In particular: "If no attribute value entry is defined for an object the value of the object's attribute is the attribute's default."_"

If a specific obejct could store a unique custom property this means we should have a DBC-Keyword that allows to assign a custom attribute definition to a specific object, but looking at BADEF and BA_ sintaxes:

So there is no a DBC-keyword that allows a specific object-attribute linking. I mean, the documentation is not clear about this points, these are my thoughts and reasoning about that but it's my own interpretation.

Adhara3 commented 1 month ago

So basically

BA_DEF_ SG_  "SPN" INT 0 524287;
BA_DEF_DEF_  "SPN" 100;
BA_ "SPN" SG_ 2364540158 EngineSpeed 190;

is interpreted the following way:

This looks fine and coherent to me. We could think of adding a property to indicate if the property was inherited or explicitly set by a specific object, i.e. all signals will have Inherited except EngineSpeed above that will have Set.

See also #43

Please note that the underlying implementation on how to propagate properties to items is going to change in version 2. No change in behaviour, just implementation detail.

Cheers A

sToman967 commented 4 weeks ago

Hi,

okay I understand. Thank you for taking the time to explain, appreciate it.

Adhara3 commented 4 weeks ago

Implémentation wise, the current one is a bit messy especially the FillWith* part when building the DBC. It became apparent during last refactoring that this is error prone. So the idea for upcoming releases is to do as follows:

The reading process will then be something like (psudocode)

// Imagine we are in a message
foreach(var globalProperty in m_globalProperties[Object type.Message])
{
  if(m_explicitProperties.Contains(globalProperty))
  {
    // The explicit wins, return it
  }
  else
  {
    // Return the global one with the default value
  }
}

This should help understand what's going on, be less error prone and be more efficient

sToman967 commented 3 weeks ago

Looks good. Will be looking forward to the updates.