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

Properly support decoding NRC-CONST parameters #314

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

andlaus
Copy link
Collaborator

@andlaus andlaus commented Jun 12, 2024

if a negative response contains an NRC-CONST parameter, where the parameter's value is not in the list of expected values, the response is not applicable and decoding should be stopped at this point. (Thus, NRC-CONST parameters are a multiplexer mechanism which filters responses based on the value of some other parameter.)

This patch implements this by introducing a new DecodeMismatch exception which is raised whenever a NRC-CONST parameter which exhibits an unexpected value is encountered. The higher-level routines for decoding responses then ignore these exceptions when appropriate. IMO, this solution is a bit sub-optimal because it uses exceptions for flow control in normal operation, but alternative implementations would be far more complex.

Andreas Lauser <[email protected]>, on behalf of MBition GmbH.
Provider Information

if a negative response contains an NRC-CONST parameter, where the
parameter's value is not in the list of expected parameters, the
response is not applicable and decoding should be stopped at this
point. (Thus, NRC-CONST parameters are a multiplexer mechanism which
filters response objects based on the value of some other parameter.)

This patch implements this by introducing a new `DecodeMismatch`
exception which is raised whenever a NRC-CONST parameter which
exhibits an unexpected value is encountered. The higher level decoding
routines for decoding responses in `DiagLayer` then ignore these
exceptions. (IMO, this solution is a bit sub-optimal because it uses
exceptions for flow control in normal operation, but alternative
implmentations would be far more complex.)

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Katja Köhler <[email protected]>
odxtools/exceptions.py Outdated Show resolved Hide resolved
DecodeError,
stacklevel=1,
)
raise DecodeMismatch(f"NRC-CONST parameter {self.short_name} does not apply")
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: change to warning, use a warning filter in odxtools/diagservice.py to force that warning as error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is not really possible: we want to abort the decoding process for the whole response even regardless of whether we are in strict mode or not. This is because if this happens, the response is not applicable. Since this is IMO normal processing and not really exceptional circumstances, I'm not really happy about using exceptions for flow control. That said, any other solution I can think of is at least one order of magnitude more invasive and error-prone...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(I have to correct myself: actually, going the warnings route and making warnings raise would be possible, but it would be very convoluted and IMO it also would defeat the purpose. In particular, because these conditions can happen during normal operation, i.e. it is not a circumstance which one needs/wants be warned about.)

thanks to [at]kayoub5 for the catch!

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Katja Köhler <[email protected]>
this is a drive-by fix, but it is pretty trivial...

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Katja Köhler <[email protected]>
@andlaus
Copy link
Collaborator Author

andlaus commented Jun 13, 2024

@kayoub5: do you consider this to be merge-ready with the latest modifications?

@andlaus
Copy link
Collaborator Author

andlaus commented Jun 24, 2024

@kayoub5: barring objections or approvals, I will merge this PR this Thursday or Friday...

@andlaus andlaus merged commit 5f887db into mercedes-benz:main Jul 1, 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