-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c6bf52
commit ef94039
Showing
11 changed files
with
560 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: ci | ||
on: [push, pull_request] | ||
jobs: | ||
test: | ||
name: test | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macOS-latest] | ||
rust: [1.76.0, stable, beta, nightly] | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Install Rust | ||
uses: hecrj/setup-rust-action@v2 | ||
with: | ||
rust-version: ${{ matrix.rust }} | ||
- if: matrix.rust == 'stable' | ||
run: rustup component add clippy | ||
- if: matrix.rust == 'stable' | ||
run: cargo clippy --all-features --all-targets -- -D warnings | ||
- if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest' | ||
run: cargo fmt --all -- --check | ||
- run: cargo check --no-default-features --all-targets | ||
- run: cargo test --all-features | ||
- if: matrix.rust == 'nightly' | ||
run: | | ||
cargo +nightly update -Z minimal-versions | ||
cargo check --all-features --all-targets | ||
name: Check with minimal-versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Change Log | ||
|
||
## [Unreleased][unreleased] | ||
|
||
### Changed/Fixed | ||
|
||
### Added | ||
|
||
### Thanks | ||
|
||
## 0.1.0 | ||
|
||
vrt-rs: | ||
|
||
- Initial version with VRT header and trailer parsing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "vrt" | ||
description = "Parser/encoder for VITA Radio Transport data" | ||
license = "MIT" | ||
keywords = ["VRT", "parser", "nom"] | ||
homepage = "https://github.com/littleairmada/vrt-rs" | ||
repository = "https://github.com/littleairmada/vrt-rs" | ||
version = "0.1.0" | ||
authors = ["Blair Gillam <ns1h@airmada.net>"] | ||
categories = ["parser-implementations"] | ||
edition = "2021" | ||
readme = "README.md" | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
nom = "7.1.3" | ||
nom-derive = "0.10.1" | ||
rusticata-macros = "4.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2024 Blair Gillam | ||
|
||
Permission is hereby granted, free of charge, to any | ||
person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the | ||
Software without restriction, including without | ||
limitation the rights to use, copy, modify, merge, | ||
publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software | ||
is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice | ||
shall be included in all copies or substantial portions | ||
of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,27 @@ | ||
# vrt-rs | ||
Parser/Encoder for VITA Radio Transport data | ||
# vrt - a VITA Radio Transport (49.0-2015) protocol parser/encoder library for Rust | ||
=========================== | ||
|
||
[![Crates.io Version](https://img.shields.io/crates/v/vrt.svg)](https://crates.io/crates/vrt) | ||
[![Documentation](https://docs.rs/vrt/badge.svg)](https://docs.rs/vrt) | ||
![GitHub License](https://img.shields.io/github/license/littleairmada/vrt-rs) | ||
[![CI Status](https://github.com/littleairmada/vrt-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/littleairmada/vrt-rs/actions/workflows/ci.yml) | ||
|
||
A library for interacting with systems supporting VITA Radio Transport (VRT). The crate is a work in progress. | ||
|
||
Currently, this crate supports: | ||
|
||
* basic data structures and functionality for parsing VRT message headers and trailers | ||
|
||
If you have ideas, requests, or proposals for future features, pleased don’t hesitate to open Github issues. | ||
|
||
## Changes | ||
|
||
See `CHANGELOG.md`. | ||
|
||
|
||
## Licensing | ||
|
||
The vrt crate is distributed under the terms of the MIT license. See the [LICENSE] file for details. | ||
|
||
[LICENSE]: https://github.com/littleairmada/vrt-rs/blob/main/LICENSE | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE) | ||
//! [![Crates.io Version](https://img.shields.io/crates/v/vrt.svg)](https://crates.io/crates/vrt) | ||
//! [![Github CI](https://github.com/littleairmada/vrt-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/littleairmada/vrt-rs/actions) | ||
//! [![Minimum rustc version](https://img.shields.io/badge/rustc-1.76.0+-lightgray.svg)](#rust-version-requirements) | ||
//! | ||
//! # A VRT parser/encoder library for Rust | ||
//! | ||
//! A VITA Radio Transport (VITA 49.0-2015) parser and encoder, implemented with the [nom](https://github.com/Geal/nom) | ||
//! parser combinator framework. | ||
//! | ||
|
||
#![deny( | ||
missing_docs, | ||
unstable_features, | ||
unused_import_braces, | ||
unused_qualifications, | ||
unreachable_pub | ||
)] | ||
#![forbid(unsafe_code)] | ||
#![warn(rust_2018_idioms, missing_debug_implementations)] | ||
// pragmas for doc | ||
#![deny(rustdoc::broken_intra_doc_links)] | ||
#![cfg_attr(docsrs, feature(doc_cfg))] | ||
#![doc(test( | ||
no_crate_inject, | ||
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) | ||
))] | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
mod parser; | ||
mod vrt; | ||
|
||
pub use parser::*; | ||
pub use vrt::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use crate::vrt::*; | ||
use nom::number::streaming::be_u8; | ||
use nom::{Err, IResult, Needed}; | ||
|
||
fn u8_to_bool(v: u8) -> bool { | ||
match v { | ||
0 => false, | ||
1 => true, | ||
_ => panic!("Invalid bool in u8 {}", v), | ||
} | ||
} | ||
|
||
/// Parses the VRT packet's header | ||
pub fn parse_vrt_header(i: &[u8]) -> IResult<&[u8], Header> { | ||
if i.len() < 4 { | ||
return Err(Err::Incomplete(Needed::new(4))); | ||
} | ||
|
||
let (i, first_byte) = be_u8(i)?; | ||
let packet_type: u8 = first_byte >> 4; | ||
let c: u8 = (first_byte >> 3) & 0x01; | ||
let t: u8 = (first_byte >> 2) & 0x01; | ||
|
||
let (i, second_byte) = be_u8(i)?; | ||
let tsi: u8 = (second_byte >> 6) & 0x03; | ||
let tsf: u8 = (second_byte >> 4) & 0x03; | ||
let packet_count: u8 = (second_byte) & 0xf; | ||
|
||
let (i, third_byte) = be_u8(i)?; | ||
let (i, fourth_byte) = be_u8(i)?; | ||
let packet_size: u16 = (third_byte + fourth_byte) as u16; | ||
|
||
let hdr = Header { | ||
packet_type: VitaPacketType(packet_type), | ||
c: u8_to_bool(c), | ||
t: u8_to_bool(t), | ||
tsi: Tsi(tsi), | ||
tsf: Tsf(tsf), | ||
packet_count, | ||
packet_size, | ||
}; | ||
Ok((i, hdr)) | ||
} | ||
|
||
/// Parses the VRT packet's trailer | ||
pub fn parse_vrt_trailer(i: &[u8]) -> IResult<&[u8], Trailer> { | ||
if i.len() < 4 { | ||
return Err(Err::Incomplete(Needed::new(4))); | ||
} | ||
|
||
let (i, first_byte) = be_u8(i)?; | ||
let (i, second_byte) = be_u8(i)?; | ||
let (i, third_byte) = be_u8(i)?; | ||
let (i, fourth_byte) = be_u8(i)?; | ||
|
||
// first byte | ||
let calibrated_time_enable: u8 = (first_byte >> 7) & 0x01; | ||
let valid_data_enable: u8 = (first_byte >> 6) & 0x01; | ||
let reference_lock_enable: u8 = (first_byte >> 5) & 0x01; | ||
let agcmgc_enable: u8 = (first_byte >> 4) & 0x01; | ||
let detected_signal_enable: u8 = (first_byte >> 3) & 0x01; | ||
let spectral_inversion_enable: u8 = (first_byte >> 2) & 0x01; | ||
let overrange_enable: u8 = (first_byte >> 1) & 0x01; | ||
let sample_loss_enable: u8 = (first_byte) & 0x01; | ||
|
||
// second byte | ||
let user_defined_enable_1: u8 = (second_byte >> 7) & 0x01; | ||
let user_defined_enable_2: u8 = (second_byte >> 6) & 0x01; | ||
let user_defined_enable_3: u8 = (second_byte >> 5) & 0x01; | ||
let user_defined_enable_4: u8 = (second_byte >> 4) & 0x01; | ||
let calibrated_time_indicator: u8 = (second_byte >> 3) & 0x01; | ||
let valid_data_indicator: u8 = (second_byte >> 2) & 0x01; | ||
let reference_lock_indicator: u8 = (second_byte >> 1) & 0x01; | ||
let agcmgc_indicator: u8 = (second_byte) & 0x01; | ||
|
||
// third byte | ||
let detected_signal_indicator: u8 = (third_byte >> 7) & 0x01; | ||
let spectral_inversion_indicator: u8 = (third_byte >> 6) & 0x01; | ||
let overrange_indicator: u8 = (third_byte >> 5) & 0x01; | ||
let sample_loss_indicator: u8 = (third_byte >> 4) & 0x01; | ||
let user_defined_indicator_1: u8 = (third_byte >> 3) & 0x01; | ||
let user_defined_indicator_2: u8 = (third_byte >> 2) & 0x01; | ||
let user_defined_indicator_3: u8 = (third_byte >> 1) & 0x01; | ||
let user_defined_indicator_4: u8 = (third_byte) & 0x01; | ||
|
||
// fourth byte | ||
let associated_context_packet_count_enable: u8 = (fourth_byte >> 7) & 0x01; | ||
let associated_context_packet_count_value: u8 = (fourth_byte) & 0x7f; | ||
|
||
let hdr: Trailer = Trailer { | ||
calibrated_time_enable: u8_to_bool(calibrated_time_enable), | ||
valid_data_enable: u8_to_bool(valid_data_enable), | ||
reference_lock_enable: u8_to_bool(reference_lock_enable), | ||
agcmgc_enable: u8_to_bool(agcmgc_enable), | ||
detected_signal_enable: u8_to_bool(detected_signal_enable), | ||
spectral_inversion_enable: u8_to_bool(spectral_inversion_enable), | ||
overrange_enable: u8_to_bool(overrange_enable), | ||
sample_loss_enable: u8_to_bool(sample_loss_enable), | ||
user_defined_enable_1: u8_to_bool(user_defined_enable_1), | ||
user_defined_enable_2: u8_to_bool(user_defined_enable_2), | ||
user_defined_enable_3: u8_to_bool(user_defined_enable_3), | ||
user_defined_enable_4: u8_to_bool(user_defined_enable_4), | ||
calibrated_time_indicator: u8_to_bool(calibrated_time_indicator), | ||
valid_data_indicator: u8_to_bool(valid_data_indicator), | ||
reference_lock_indicator: u8_to_bool(reference_lock_indicator), | ||
agcmgc_indicator: u8_to_bool(agcmgc_indicator), | ||
detected_signal_indicator: u8_to_bool(detected_signal_indicator), | ||
spectral_inversion_indicator: u8_to_bool(spectral_inversion_indicator), | ||
overrange_indicator: u8_to_bool(overrange_indicator), | ||
sample_loss_indicator: u8_to_bool(sample_loss_indicator), | ||
user_defined_indicator_1: u8_to_bool(user_defined_indicator_1), | ||
user_defined_indicator_2: u8_to_bool(user_defined_indicator_2), | ||
user_defined_indicator_3: u8_to_bool(user_defined_indicator_3), | ||
user_defined_indicator_4: u8_to_bool(user_defined_indicator_4), | ||
associated_context_packet_count_enable: u8_to_bool(associated_context_packet_count_enable), | ||
associated_context_packet_count: associated_context_packet_count_value, | ||
}; | ||
Ok((i, hdr)) | ||
} |
Oops, something went wrong.