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

Fix VehicleEventFlaga Jackknife Event Extension #42

Merged
merged 5 commits into from
Feb 25, 2025

Conversation

iyourshaw
Copy link

@iyourshaw iyourshaw commented Feb 23, 2025

This PR fixes an issue with the "eventJackKnife" field that was added to the VehicleEventFlags BIT STRING in the 2024 revision of the J2735 specification.

The original issue was described here: usdot-asn1c Issue #2

The extension was removed in a previous PR #37 as a workaround to prevent incorrect UPER encoding/decoding code from being generated with the extension present. This PR restores the extension in the ASN.1, and instead edits the generated C code to ensure that the UPER encoding is correct with the extension present.

The correct encoding for BIT STRING extensions was determined by referring to the text of the UPER standard, and by experimenting with the encoding using the open source Erlang ASN.1 compiler as described in detail here:
asn1c-extensible-bitstring-example - the-erlang-asn1-compiler-produces-the-correct-uper-encoding.

Then the asn1c compiler was tested by compiling the VehicleEventFlags PDU by itself within a test rig, and comparing the UPER with the reference from the Erlang compiler. It was discovered that the asn1c-generated code already has the ability to generate UPER for BIT STRINGs with extensions with a simple adjustment to the PER-visible size constraint, meaning that there is just a bug in how asn1c translates size constraint extensions to it's internal representation. The bug was worked around by editing the generated code, VehicleEventFlags.c.

As a further test, the publicly available J2735 (2016) validation site here: https://webapp2.connectedvcs.com/validator/ which uses the commercial OSS ASN.1 compiler, was used to verify that UPER generated with the BIT STRING with the extension is backwards compatible with the 2016 specification, and that the OSS-generated codec understands the same UPER for BIT STRING extensions as the Erlang and asn1c compilers.

Details on the code changed.

The PER-visible size constraint struct in VehicleEventFlags.c was changed from:

{ 
    flags=APC_CONSTRAINED | APC_EXTENSIBLE,  
    range_bits=1,  
    effective_bits=1,  
    lower_bound=13,  
    upper_bound=14
 }

to:

{ 
    flags=APC_CONSTRAINED | APC_EXTENSIBLE,  
    range_bits=0,  
    effective_bits=0,  
    lower_bound=13,  
    upper_bound=13
 }

That struct represents the size constraint for the extension root only, and the original generated code erroneously includes the extension size constraint in it. That change was enough to cause the correct UPER to be encoded.

The VehicleEventFlags_constraint method was left as-is with this check:

if((size >= 13UL && size <= 14UL)) {
		/* Constraint check succeeded */
...

so that the extended size (14) will still be included in constraint checks.

Tests

Unit tests for encoding and decoding the VehicleEventFlags PDU were added, and a decode test for a BSM with the "jackKnife" event was added to tests.cpp. The tests were run in Docker.

@iyourshaw iyourshaw marked this pull request as ready for review February 24, 2025 17:56
Copy link
Member

@dmccoystephenson dmccoystephenson left a comment

Choose a reason for hiding this comment

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

This looks good to me!

Here’s what I did:

  • Verified that unit tests passed using the checked-in 2024.tar.gz file.
  • Generated a new 2024.tar.gz file using J2735 2024 files, and no errors appeared when applying patches.
  • Verified that unit tests passed with the newly generated 2024.tar.gz file.

However, I have one point of confusion: The description states,
"The PER-visible size constraint struct in VehicleEventFlags.c was changed from [...] to [...]."

But I don’t see this constraint struct in the checked-in override file for VehicleEventFlags.c.

Is the description still accurate?

@iyourshaw
Copy link
Author

This looks good to me!

Here’s what I did:

  • Verified that unit tests passed using the checked-in 2024.tar.gz file.
  • Generated a new 2024.tar.gz file using J2735 2024 files, and no errors appeared when applying patches.
  • Verified that unit tests passed with the newly generated 2024.tar.gz file.

However, I have one point of confusion: The description states, "The PER-visible size constraint struct in VehicleEventFlags.c was changed from [...] to [...]."

But I don’t see this constraint struct in the checked-in override file for VehicleEventFlags.c.

Is the description still accurate?

Yes. I added the explicit labels for the struct members in the writeup to make it clearer, but in context the change is buried here on line 62:
image

@dmccoystephenson
Copy link
Member

This looks good to me!
Here’s what I did:

  • Verified that unit tests passed using the checked-in 2024.tar.gz file.
  • Generated a new 2024.tar.gz file using J2735 2024 files, and no errors appeared when applying patches.
  • Verified that unit tests passed with the newly generated 2024.tar.gz file.

However, I have one point of confusion: The description states, "The PER-visible size constraint struct in VehicleEventFlags.c was changed from [...] to [...]."
But I don’t see this constraint struct in the checked-in override file for VehicleEventFlags.c.
Is the description still accurate?

Yes. I added the explicit labels for the struct members in the writeup to make it clearer, but in context the change is buried here on line 62: image

Thanks for that clarification!

Copy link
Member

@dmccoystephenson dmccoystephenson left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Collaborator

@drewjj drewjj left a comment

Choose a reason for hiding this comment

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

Nice! Good to get better 2024 support.

@drewjj drewjj merged commit 0511993 into CDOT-CV:develop Feb 25, 2025
2 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.

3 participants