Crates.io | mil_std_1553b |
lib.rs | mil_std_1553b |
version | 0.5.0 |
source | src |
created_at | 2024-03-03 21:28:34.325005 |
updated_at | 2024-04-01 23:09:26.553948 |
description | MIL STD 1553B message parsing and types |
homepage | |
repository | https://github.com/mjhouse/mil_std_1553b |
max_upload_size | |
id | 1160929 |
size | 246,493 |
This library implements a complete set of Rust structs for parsing or constructing messages that comply with the MIL STD 1553B communication protocal.
The following features make this library useable in constrained embedded systems for government, commercial, or military projects that can't have virally licensed dependencies.
no_std
)* No runtime dependencies. If you use the derive
feature flag, you will have to build proc-macro
dependencies, but these are built and used on the host, not on the target system.
A message can be built using the constructor methods of Message, CommandWord, StatusWord, and DataWord.
use mil_std_1553b::*;
let message = Message::<3>::new()
.with_command(CommandWord::new()
.with_address(Address::Value(12))
.with_subaddress(SubAddress::Value(5))
.with_word_count(2)
.build().unwrap()
)
.with_data(DataWord::new())
.with_data(DataWord::new())
.build()
.unwrap();
assert_eq!(message.length(),3);
Messages can be parsed as command messages, and the leading command word will determine how many data words will be parsed from the buffer.
use mil_std_1553b::*;
let message: Message = Message::read_command(&[
0b10000011,
0b00001100,
0b00100010,
0b11010000,
0b11010010
])
.unwrap();
assert_eq!(message.length(),2);
use mil_std_1553b::*;
let message: Message = Message::read_status(&[
0b10000011,
0b00001100,
0b01000010,
0b11010000,
0b11010010
])
.unwrap();
assert_eq!(message.length(), 2);
Words can be parsed from two-byte byte arrays or u16s. Data words can also be created from strings.
use mil_std_1553b::*;
let word = DataWord::new()
.with_bytes([0b01001000, 0b01001001])
.with_calculated_parity()
.build()
.unwrap();
assert_eq!(word.as_string(),Ok("HI"));
CI/CD pipelines building for all host -> cross compile targets
Round-trip tests (binary -> struct -> binary) exist for messages
Round-trip tests (binary -> struct -> binary) exist for words
Configuration tests (JSON) exist for words
Configuration tests (JSON) exist for messages
A "word" in the 1553B standard is made up of twenty bits, total. Three sync bits, 16 bits of data (in one of three different formats), and a trailing parity bit 1. This means that there are two ways of referencing a particular bit- either with a bit index offset from the beginning of the word data or as a "bit time" offset from the beginning of the word, including the sync bits.
Index | Sync1 | Sync2 | Sync3 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Parity |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Time | - | - | - | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | - |
Offset | - | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | - |
The bit-time reference is used in the standard, but because we're only dealing with the 16-bit data from each word in this project we'll be using a zero-indexed reference in the actual code.