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 trait that converts from DataWord to a custom word type #41

Closed
6 of 7 tasks
mjhouse opened this issue Mar 6, 2024 · 1 comment
Closed
6 of 7 tasks

Add trait that converts from DataWord to a custom word type #41

mjhouse opened this issue Mar 6, 2024 · 1 comment
Assignees

Comments

@mjhouse
Copy link
Owner

mjhouse commented Mar 6, 2024

Users of this library will probably be transmitting words that, while they may use the same sync/parity bits, interpret the u16 word bodies in a specific way (not as bytes, &str etc). To support this, we need to:

  • Provide a way of quickly creating a custom word
    • Initially thought this would be a trait but investigating proc-macro1
    • Derive(Word) on a custom struct that has two attributes (data and parity) decorated
    • Proc macro crate could be a sub-crate of mil_std_1553b
  • Provide access to the Field struct
    • Make the Field struct part of the public API
    • Update the Field struct to support fields greater than 8 bits
    • Add documentation and examples to the Field struct
  • Update the Message::get method to be generic or add another, generic getter method.2
  • Add a comprehensive example for defining and parsing custom words. Add standalone examples to project #54

After everything is implemented a user should be able to do the following:

#[derive(Word)]
pub struct CustomWord {
    /// the body of the word
    #[data]
    mydata: [u8;2],

    /// the parity bit of the word
    #[parity]
    myparity: u8,

    /// some other data
    othervar: u8,
}

impl CustomWord {

    /// Mask for parsing a custom flag from the leading bit
    pub const CUSTOM_FLAG: u16 = 0b1000000000000000;

    /// Field definition for the custom flag
    pub const CUSTOM_FLAG_FIELD: Field = Field::from(Self::CUSTOM_FLAG);

    /// Check the custom flag on the word
    pub fn is_custom_flag(&self) -> bool {
        Self::CUSTOM_FLAG_FIELD.get(self) == 1
    }

}

Footnotes

  1. https://doc.rust-lang.org/reference/procedural-macros.html

  2. message.get(0).map(CustomWord::from).unwrap()

@mjhouse mjhouse changed the title At trait that converts from data word body to type Add trait that converts from data word body to type Mar 10, 2024
@mjhouse mjhouse changed the title Add trait that converts from data word body to type Add trait that converts from DataWord to a custom word type Mar 17, 2024
@mjhouse mjhouse self-assigned this Mar 20, 2024
@mjhouse mjhouse mentioned this issue Mar 22, 2024
@mjhouse
Copy link
Owner Author

mjhouse commented Mar 22, 2024

Resolved by #66, I'll make a separate issue for the change to field.

@mjhouse mjhouse closed this as completed Mar 22, 2024
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

No branches or pull requests

1 participant