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

bump deku dependency #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

robamu
Copy link

@robamu robamu commented Jun 13, 2022

Hi!

I would like to use this dependency when converting my serde/postcard compatible header implementation to this variant for packed serialization. I have some improvements

  • Rerun cargo fmt
  • Fix warning about unused variable
  • Bump deku dependency to 0.13. I also re-tested with cargo test. I had some issues when converting a serde compatible header struct to this deku compatible version and then using the to_bytes() method. Now it seems to work

If you are interested, I can also provide you my serde/postcard compatible implementation of the space packet header, but this would probably require to put the implementation in separate serde and deku submodules because they use different derive macros

@MoralCode
Copy link
Member

MoralCode commented Jun 15, 2022

Thanks for the contribution! was there a specific change made in deku 0.13 that was needed to support your implementation? or is this just a general update because there's a newer version available?

having implementations compatible with both would be great and i'd be interested in learning about whats different between the derive implementations to see if its possible to get both serde/postcard and deku versions in together in a way that doesn't require separately maintaining both of them

@robamu
Copy link
Author

robamu commented Jun 15, 2022

I actually went for a zerocopy/serde implementation now. I can still send you my serde compatible version (has become a bit overengineered though..).

I think something was not available in the older version but I would need to recheck.

@MoralCode
Copy link
Member

Is there another space packet library out there based on zerocopy? sounds like there's also lot of rust serialization/deserialization libraries around as well. If there's a better implementation of CCSDS SpacePacket out there, i'd love to see if there's interest in collaborating since I mostly put this together because i thought i could do better than an existing library that i found via Aerorust.

As far as this PR goes, I agree with the formatting changes, the only thing id like to be a little cautious about is making sure the version update is there to solve a particular problem since there's always a risk that it could break something for someones workflow that may not be covered by the tests.

Let me know if you're still interested in pursuing this PR or if theres anything i can do to make this (relatively new) library helpful for you!

@robamu
Copy link
Author

robamu commented Jun 16, 2022

Yeah there are also other libraries out there based on zerocopy: https://docs.rs/ccsds_primary_header/latest/ccsds_primary_header/ . Deku has the advantage that it can handle bitfields as well though, so I am still interested in it. Packet protcols like the CCSDS File Delivery Protocol or the Unified Space Data Link Protocol (USLP) make a lot of use of bit fields as well. One thing you might find interesting is a generic trait type which abstracts away how exactly the primary header struct was implemented

/// Generic trait to access fields of a CCSDS space packet header according to CCSDS 133.0-B-2
pub trait CcsdsPrimaryHeader {
    const SEQ_FLAG_MASK: u16 = 0xC000;

    fn version(&self) -> u8;
    fn packet_id(&self) -> PacketId;
    fn psc(&self) -> PacketSequenceCtrl;
    /// Retrieve data length field
    fn data_len(&self) -> u16;
    /// Retrieve 13 bit Packet Identification field. Can usually be retrieved with a bitwise AND
    /// of the first 2 bytes with 0x1FFF
    #[inline]
    fn packet_id_raw(&self) -> u16 {
        self.packet_id().raw()
    }
    /// Retrieve Packet Sequence Count
    #[inline]
    fn psc_raw(&self) -> u16 {
        self.psc().raw()
    }
    #[inline]
    /// Retrieve Packet Type (TM: 0, TC: 1)
    fn ptype(&self) -> PacketType {
        // This call should never fail because only 0 and 1 can be passed to the try_from call
        self.packet_id().ptype
    }
    #[inline]
    fn is_tm(&self) -> bool {
        self.ptype() == PacketType::Tm
    }
    #[inline]
    fn is_tc(&self) -> bool {
        self.ptype() == PacketType::Tc
    }
    /// Retrieve the secondary header flag. Returns true if a secondary header is present
    /// and false if it is not
    #[inline]
    fn sec_header_flag(&self) -> bool {
        self.packet_id().sec_header_flag
    }
    /// Retrieve Application Process ID
    #[inline]
    fn apid(&self) -> u16 {
        self.packet_id().apid
    }
    #[inline]
    fn ssc(&self) -> u16 {
        self.psc().ssc
    }
    #[inline]
    fn sequence_flags(&self) -> SequenceFlags {
        // This call should never fail because the mask ensures that only valid values are passed
        // into the try_from function
        self.psc().seq_flags
    }
}

Something similar can actually be done for PUS as well.

The crate I am currently working on is still WIP and not public yet. I am actually working on a Rust framework supporting small satellite missions. For now, I have decided that serde/postcard is the best option for rust internal serialization and deserialization as it is explictely targeted towards embedded usage. The only other thing I needed was a library which I can use to serialize/deserialize from/to a network. zerocopy and deku appear equally suitable for this.

My current plan is to put all packet protocols (CCSDS, ECSS PUS, maybe also CFDP and USLP components soon) into a separate package similarly to this Python package: https://pypi.org/project/spacepackets/ .
I'd defnitely be interested in collaboration if this is something you could use as well. I was planning for serde / zerocopy compatibility for all other packet protocols as well.

I will check again why exactly version 12.4 did not work for me. Maybe it's also a package management issue.

@MoralCode
Copy link
Member

MoralCode commented Jun 16, 2022

oh wow, all of this sounds awesome! If you havent already you should join our discord server as im sure there's others in the community (and similar communities) that would also be interested in this.

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.

2 participants