Git Product home page Git Product logo

Comments (1)

rudihorn avatar rudihorn commented on September 26, 2024

I'm not sure if there are better crates out there, but I have been experimenting with doing some code generation similar to the crate svd2rust does in https://github.com/rudihorn/prot2rust (edit: the generation is now done in https://github.com/rudihorn/rust-ieee802.15.4-gen).

My main motivation for this was to reduce the memory footprint currently required by a field for each flag and to get rid of serialization / de-serialization while still providing a nice interface. So for the frame control one can do something like:

    let mut v = frame_control::W::new(0);
    v.frame_type()
        .data()
        .ack_request()
        .ack_requested()
        .dest_addr_mode()
        .address_16bit();
    v

and then in theory this should be able to inline to a more efficient representation that just constructs the 16 bit field.

I'd also suggest the use of generics to support different field configurations.

// trait for addresses
pub trait Address {}
// each address type is declared as a struct
pub struct AddrNone {}
pub struct AddrShort {
    pub address: u16,
}
pub struct AddrExtended {
    pub address: u32,
}
// each address type implements the Address trait
impl Address for AddrNone {}
impl Address for AddrShort {}
impl Address for AddrExtended {}

Then a frame header can be constructed with mac_frame::Mhr::<PanNone, AddrNone, PanNone, AddrNone>::new() and should be transmutable from raw memory. There are some issues using packed structs one would still need to figure out (a warning is thrown during compilation of the generated project). It would be nice if one could combine the generics of the header type with the frame control reader / writer, but this may be more tricky.

The code generated by this project is available at https://github.com/rudihorn/rust-ieee802.15.4

Are you aware of any declarative definition of 802.15.4 one could use as the source of such a code generator? Or crates that already do something like this? I know there are some for bitfield related projects, but nothing more complete. It would be nice if such a project could be used for the zigbee protocol as well. Let me know what you think.

(Disclaimer: These contributions are my own and are not related to my employment)

from rust-ieee802.15.4.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.