Comments (1)
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)
- Fix rendering of README on crates.io HOT 7
- Add stable channel to Travis configuration
- Dependency on `bytes` is out of date HOT 1
- Latest version depends on `alloc` via `BufMut` HOT 3
- Latest version doesn't compile on arm-thumbv6m targets HOT 1
- Supporting security on MAC layer with current `byte::TryRead` interface is not possible. HOT 2
- Transferring this repository to Rust IoT HOT 7
- Fix existing Clippy warnings
- New release? HOT 1
- Encoded frame cannot be decoded
- `try_read` produce error for at least Acknowledge frames HOT 2
- Is panicking when the buffer is too small the best approach?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-ieee802.15.4.