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

Hard and takes a while: Switch to proc macros #53

Closed
jr1221 opened this issue Sep 23, 2024 · 0 comments · Fixed by #67
Closed

Hard and takes a while: Switch to proc macros #53

jr1221 opened this issue Sep 23, 2024 · 0 comments · Fixed by #67
Assignees

Comments

@jr1221
Copy link
Contributor

jr1221 commented Sep 23, 2024

Right now, we use Python in order to generate the runtime code we are using to parse messages bit by bit.

Instead, we can take the heavy lifting string manipulation off of python and switch to proc macros. The new flow would have derive proc macros on structs. My current thoughts would be each CANMsg is a struct containing the various attributes from the YAML. These derive macros would add a trait to the struct that convets CANMsg to a list of MQTT packets as the current function lookup table does.

I recommend first writing the macro then using it to achieve correct syntax that matches or exceeds the python generated rust. Then make that macro work on structs. Then add those structs to a phf list. Then python generate the structs and phf list, and it should work like a charm.

The new flow:

  1. YAML is edited
  2. Python generates a definitions file which converts CANMsg --> CANMsg Struct in a giant phf map. The map has type <u16, impl calypso_derive::NetEncoder> Each instance is matched to its ID, such that key is CAN ID and value is the instance of the struct.
  3. On compile time, rust adds a trait NetEncoder to each struct, adding a function called fetch_net which takes in the CANMsg data and passes back the net info similar to normal.
  4. At runtime when calypso gets a message, it looks the message up by ID using the phf map, then calls net_encode on the struct, getting the data.

The encoder flow:

  1. YAML is edited
  2. Python generates a definitions file which converts EncodableCANMsg --> EncodableCANMsg struct in a giant phf map with the type <String, calypso_derive::CanEncoder>. It adds these to both lists??
  3. TODO: how does encodableCANmsg work?
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 a pull request may close this issue.

2 participants