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

packets.rs: introduce CfgItfm frame #41

Merged
merged 1 commit into from
Sep 25, 2022
Merged

Conversation

gwbres
Copy link
Collaborator

@gwbres gwbres commented Sep 16, 2022

Hello @lkolbly, @reitermarkus,

The CFG_ITFM frame is an important frame to our application, it controls the Interference (jamming) detection module.

I would like to control the Default value of this frame myself, as some part of the config words (Algorithm & config2) must have very specific (and undocumented values). This is how I did it

@gwbres gwbres force-pushed the cfg_itfm branch 3 times, most recently from 971a7ba to 1a313e4 Compare September 16, 2022 16:28
@maximeborges
Copy link
Collaborator

I think doing something similar to CfgPrtUart with UartMode would fit better in this code and be more Rustic.

Something along those lines:

#[ubx_packet_recv_send]
#[ubx(
    class = 0x06, 
    id = 0x39, 
    fixed_payload_len = 8,
    flags = "default_for_builder"
)]
struct CfgItfm {
    /// Interference config Word
    #[ubx(map_type = CfgItfmConfig)]
    config: u32,

    /// Extra settings
    #[ubx(map_type = CfgItfmConfig2)]
    config2: u32,
}

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CfgItfmConfig {
    /// Broadband jamming detection threshold (dB)
    bb_threshold: BbThreshold,
    /// CW jamming detection threshold (dB)
    cw_threshold: CwThreshold,
    /// Reserved algorithm settings - should be set to 0x16B156 in hex for correct settin
    algorithm_bits: AlgorithmBits,
    /// enable interference detection
    enable: bool,
}

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BbThreshold(u32);
impl BbThreshold {
    const POSITION: u32 = 0;
    const LENGTH: u32 = 4;
    const MASK: u32 = (1<<Self::LENGTH)-1;

    const fn into_raw(self) -> u32 {
        (self.0 & Self::MASK) << Self::POSITION
    }
}
impl From<u32> for BbThreshold {
    fn from(thres: u32) -> Self {
        Self(thres)
    }
}

And so on.

@gwbres
Copy link
Collaborator Author

gwbres commented Sep 22, 2022

I think doing something similar to CfgPrtUart with UartMode would fit better in this code and be more Rustic.

Yes that would work, I will update this PR accordingly

@gwbres
Copy link
Collaborator Author

gwbres commented Sep 22, 2022

Hello,

@maximeborges for information, the code did not compile as is, because every single structures involved in the ubx_recv/send generators require an into_raw() method.

I also wanted to keep the boolean native types for enable bits, because I think it's easier to use, at the user level.
Finally, I also wanted to use an enum not a struct wrapper for the AntennaSettings, to emphasize that only those values are correct. I use the [repr(u8)] derivation, and cast it to u32 in the needed into_raw() methods

Copy link
Collaborator

@lkolbly lkolbly 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, thank you!

@lkolbly lkolbly merged commit 96faed8 into ublox-rs:master Sep 25, 2022
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