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

implement de- and encoding of environment data descriptions #321

Merged
merged 4 commits into from
Jul 17, 2024

Conversation

andlaus
Copy link
Member

@andlaus andlaus commented Jul 15, 2024

This PR implements en- and decoding of environment data descriptions, the fourth multiplexer mechanism specified by the ODX standard besides tables, NRC-CONSTs and multiplexers. This requires to keep track of the de-/encoded parameters because the environment data that ought to be used by a given environment data description depends on the value used for one of the preceding parameters.

Andreas Lauser <andreas.lauser@mercedes-benz.com>, on behalf of MBition GmbH.
Provider Information

this requires to keep track of the de-/encoded parameters because the
environment data that ought to be used by a given environment data
description depends on the value used for the preceeding parameter.

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Florian Jost <florian.jost@mbition.io>
@andlaus andlaus requested a review from kayoub5 July 15, 2024 08:52
#: List of parameters that have been decoded so far. The journal
#: is used by some types of parameters which depend on the values of
#: other parameters; i.e., environment data description parameters
journal: List[Tuple["Parameter", Optional[ParameterValue]]] = field(default_factory=list)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a dict would be faster for lookup

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the sequence in which the parameters were processed, i.e. that would require at least OrderedDict. That said, I'm not sure how such a lookup would be realized and also parameters frequently appear more than once, e.g., for fields (which are repeated structure objects)...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using the journal with reversed, meaning only the last value is actually needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but then a different name than .journal is also required IMO. (I think that conceptually, the concept of a "change log" for en-/decoding is quite nice.) Performance-wise I don't think that it will matter much because responses containing environment data descriptions are probable quite rare (e.g., I don't have any files which use them and so far we have not gotten any bug reports about missing en-/decoding support.)

if isinstance(physical_value, DiagnosticTroubleCode):
trouble_code = physical_value.trouble_code
elif isinstance(physical_value, int):
def numerical_trouble_code(self, dtc_value: ParameterValue) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function names usually start with a verb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you prefer get_numerical_trouble_code(), convert_to_numerical_trouble_code() or something else?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either would be fine

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I renamed it to convert_to_numerical_trouble_code()

odxassert(len(dtcs) == 1)
trouble_code = dtcs[0].trouble_code
dtcs = [dtc for dtc in self.dtcs if dtc.short_name == dtc_value]
if len(dtcs) != 1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it happen that length > 1 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so: in this case, it would be impossible to decide which of the environment datas that apply for the DTC ought to be used. (I suppose that this constitutes an incorrect PDX file?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the specs say anything about that?

Copy link
Member Author

@andlaus andlaus Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware that it explicitly mentions multiple "normal" environment datas matching the same DTC, but it says that there can only be a single ALL-DATA environment data. Since multiple ALL-DATA environment datas is exactly the same problem as multiple "normal" ones for a given DTC, I infer that this is forbidden. (in which order shall these environment datas be processed anyway?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sorry: I was in the wrong mental context for my previous two comments (interestingly they are still applicable to some extend): more than one DTC with the same short name cannot happen in valid ODX datasets because short names are required to be unique in their respective context. (if they were not, SNREFs would not work...)

andlaus added 2 commits July 15, 2024 11:46
the unit tests deal provide this themselves...

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Florian Jost <florian.jost@mbition.io>
…ouble_code()'

as [at]kayoub5 rightfully noted, method names should start with a verb...

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Florian Jost <florian.jost@mbition.io>
@andlaus
Copy link
Member Author

andlaus commented Jul 16, 2024

@kayoub5: do you see any further issues here?

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Florian Jost <florian.jost@mbition.io>
@andlaus andlaus merged commit 9623e2e into mercedes-benz:main Jul 17, 2024
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants