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

Add a JSON spec check on build #85

Merged
merged 10 commits into from
Dec 21, 2024
Merged

Add a JSON spec check on build #85

merged 10 commits into from
Dec 21, 2024

Conversation

harrison-e
Copy link
Contributor

Changes

  • CAN types (Message, NetField, Point) can no longer be deserialized with unspecified members (ones not listed in the spec or in libs/calypso-cangen/can_types.rs). For example, if a field foo: 1 were added somewhere in one of the JSON files, and it was not listed in can_types.rs, Calypso would fail to build.
  • build.rs now contains a CAN spec validation check, which scans Embedded-Base/cangen/can-messages/* to validate that the spec is obeyed properly. The following checks are performed:
    • Message descriptions only contain letters, whitespaces, and underscores
    • Message totals are byte-aligned
    • Fields that use a Sim enum have the frequencies for the enum add to 1
    • Points that are sent are at most 32 bits
    • Signed points are 8, 16, or 32 bits
    • Little endian points are 8, 16, or 32 bits
    • Points that are less than a byte should not specify endianness (no-op check)
    • IEEE754 32-bit float points are of size 32 bits
    • File IO works properly (Rust can access the can-messages directory and all its entries properly)
  • Code for performing the JSON validation is in libs/calypso-cangen/src/validate.rs
    • CANSpecError enum, used for descriptive error messages, uses thiserror crate to make the enum
    • Functions to validate all CAN spec, an individual CAN spec file, and an individual CAN Message
  • Fixed a bug that would ignore default field in encodable CAN Messages.

Notes

  • Moved CANGEN_SPEC_PATH to calypso-cangen (from daedalus)

To Do

Closes #81

@harrison-e harrison-e requested a review from jr1221 December 16, 2024 21:59
@harrison-e harrison-e self-assigned this Dec 16, 2024
@harrison-e harrison-e linked an issue Dec 16, 2024 that may be closed by this pull request
jr1221
jr1221 previously approved these changes Dec 20, 2024
Copy link
Contributor

@jr1221 jr1221 left a comment

Choose a reason for hiding this comment

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

One wierd thing with submodules. Other than that absolutely loving it. Works hella fast too at least on my computer. thiserror seems cool never used it before.

.gitmodules Outdated Show resolved Hide resolved
@harrison-e harrison-e requested a review from jr1221 December 21, 2024 19:49
Copy link
Contributor

@jr1221 jr1221 left a comment

Choose a reason for hiding this comment

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

me when a stale review dismissal doesnt allow me to merge a one line change: 😿

@harrison-e harrison-e merged commit e4e1199 into Develop Dec 21, 2024
1 check failed
@harrison-e harrison-e deleted the feature/sanitize_json branch December 21, 2024 20:37
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.

[CANGEN] - Fail to compile on faulty JSON
2 participants