Skip to content

Commit

Permalink
Merge pull request #11 from wcampbell0x2a/use-deku
Browse files Browse the repository at this point in the history
Use deku library
MoralCode authored Nov 4, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 650835e + 90ceffc commit d726369
Showing 6 changed files with 211 additions and 274 deletions.
185 changes: 111 additions & 74 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ccsds_spacepacket"
version = "0.1.0"
version = "0.2.0"
authors = ["Adrian Edwards <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
@@ -17,5 +17,4 @@ exclude = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
byteorder = "1.2.7"
failure = "0.1.3"
deku = "0.12"
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -21,4 +21,32 @@ The Secondary Header and Payload make up the "User Data Field" and at least one
## What this library does
This library attempts to implement a general-purpose parser for Space Packets that can interperet both the generic aspects of the space packet protocol (i.e. the Primary Header) in addition to any custom fields supplied within the Secondary Headers.

This Secondary Header parsing is accomplished by allowing users of the library to pass in a parser that can interperet the Secondary Header as specified by their project or organisation.
This Secondary Header parsing is accomplished by allowing users of the library to pass in a parser that can interperet the Secondary Header as specified by their project or organisation.


## Current status
Currently this library just implements Primary Header parsing, but expanding it to be able to deal with a complete, generic spacepacket (think of generics in programming) with user defined custom secondary headers is one of the projects main goals.


## Usage

```rust
// say you have some bytes you want to turn into a PrimaryHeader
let raw = b"\x00\x00\xc0\x00\x00\x40\xff\xff";

let expected = PrimaryHeader {
version: 0,
packet_type: types::PacketType::Data,
sec_header_flag: types::SecondaryHeaderFlag::NotPresent,
app_proc_id: 0,
sequence_flags: types::SeqFlag::Unsegmented,
sequence_count: 0,
data_length: 64,
};

// do the parsing and save the parsed header and any remaining bytes
let (rest, parsed) = PrimaryHeader::from_bytes((raw, 0)).expect("failed to parse header");

assert_eq!(parsed, expected);
assert_eq!(rest.0, [255,255])
```
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,3 @@
mod primaryheader;
pub use primaryheader::PrimaryHeader;
pub mod types;

use failure::Error;

pub type ParseResult<T> = Result<T, Error>;
Loading

0 comments on commit d726369

Please sign in to comment.