MIL-STD-1553B Protocol Parser
A comprehensive Rust library for parsing and handling MIL-STD-1553B military data bus protocol. This library provides robust encoding/decoding, message parsing, and protocol validation for aerospace and military avionics systems.
Overview
MIL-STD-1553B is a serial synchronous data bus specification used in military avionics and aerospace systems. Key characteristics:
- Clock Frequency: 1 MHz
- Word Length: 20 bits (1 start + 16 data + 1 parity + 2 sync bits)
- Encoding: Manchester encoding (Thomas variant)
- Bus Architecture: Dual-redundant (Bus A and Bus B)
- Network Topology: 1 Bus Controller (BC) + up to 30 Remote Terminals (RTs) + Bus Monitors (BMs)
- Protocol: Command/Response based synchronous communication
Project Structure
src/
├── lib.rs # Library root and module definitions
├── core.rs # Core types: Word, Address, Bus, WordType
├── encoding.rs # Manchester encoding/decoding
├── error.rs # Error types and result handling
├── message.rs # Message types: Command, Status, StatusFlags
├── parser.rs # High-level message parsing
├── protocol.rs # Protocol validation and bus management
└── main.rs # Example usage
Module Descriptions
core Module
Defines the fundamental data structures:
Word: 20-bit word with validation and parity checkingAddress: Device address (0-31, with 31 as broadcast)Bus: Bus identification (BusA or BusB)WordType: Word classification (Command, Data, Status, ModeCode)
Key Features:
- Odd parity validation over 17 bits (start + 16 data bits)
- Parity calculation utilities
- Safe address construction with bounds checking
encoding Module
Manchester encoding/decoding for MIL-STD-1553B:
ManchesterEncoder: Converts bits to Manchester-encoded bytesManchesterDecoder: Decodes Manchester-encoded bytes back to bitsManchesterType: Configurable encoding variants (IEEE, Thomas)
Features:
- Bit-level encoding/decoding
- Word-level (20-bit) encoding/decoding
- Error detection for invalid Manchester patterns
error Module
Comprehensive error handling:
ParseError: Custom error type with specific error variantsResult<T>: Type alias for convenient error handling
Error Types:
InvalidWord: Malformed word structureParityError: Parity validation failureInvalidAddress: Address out of rangeInvalidMessageType: Unexpected message typeInsufficientData: Not enough data to parseInvalidManchesterEncoding: Invalid Manchester pattern
message Module
Protocol message definitions:
-
Command: Command word from Bus Controller- Address (4 bits)
- T/R bit (Transmit/Receive)
- Sub-address (5 bits)
- Word count (6 bits)
-
StatusWord: Status word from Remote Terminal- Address (4 bits)
- Status flags (5 bits)
- Error code (7 bits)
-
StatusFlags: Individual status indicators- Reserved, Subsystem, Busy, Broadcast, Parity Error
-
ModeCode: Special mode commands- Synchronize, SelfTest, VectorWord, etc.
-
Message: Complete message envelope- CommandData: Command with optional data words
- Status: Status word response
- CommandOnly: Command without data
parser Module
High-level message parsing:
-
Parser: Main parser for converting raw data to messages- Bus-specific context
- Word parsing from Manchester-encoded bytes
- Transaction parsing (command + response)
- Message encoding/decoding
-
ParserBuilder: Fluent builder pattern for parser configuration -
Transaction: Parsed transaction with timestamp and context
protocol Module
Protocol-level handling and validation:
-
BusController: Manages bus operations and RT state- Remote Terminal registration and tracking
- Transaction recording and statistics
- Response timeout management
-
RemoteTerminal: RT state information- Address, state, error count, success count
- Last seen timestamp
- Response status checking
-
RTStats: Statistics for Remote Terminals- Error rates and transaction counts
- Current state and responsiveness
-
MessageValidator: Protocol validation utilities- Address validation
- Word count limits
- Sub-address range checking
Design Principles
1. Type Safety
- Strong typing for addresses, word types, and message components
- Enum-based variants instead of magic numbers
- Result-based error handling avoiding panics
2. Validation
- Parity checking on word construction
- Address bounds validation
- Redundant format checks
3. Modularity
- Clean separation of concerns (encoding, parsing, protocol)
- No cross-module dependencies on private details
- Extensible through public interfaces
4. Manchester Encoding
- Proper Thomas variant implementation (0=high-to-low, 1=low-to-high)
- Bit-accurate encoding/decoding
- Roundtrip consistency
5. Protocol State Management
- Bus Controller tracks RT status
- Supports both successful and failed transactions
- Statistics collection for monitoring
Usage Examples
Creating and Encoding a Command
use ;
// Create a parser
let parser = new;
// Build a command
let command = new?;
// Encode to Manchester bytes
let encoded_bytes = parser.encode_command?;
println!;
Parsing Status Words
use ;
// Create a status word
let flags = new;
let status = new?;
// Encode it
let word = status.to_word?;
println!;
// Decode it back
let decoded = from_word?;
assert_eq!;
Bus Controller State Management
use BusController;
use ;
// Create a bus controller
let mut bc = new;
// Register remote terminals
bc.register_rts?;
// Record transactions
bc.record_rt_success?;
bc.record_rt_error?;
// Get statistics
let stats = bc.get_rt_stats;
println!;
Features
- ✅ Full MIL-STD-1553B word structure support
- ✅ Manchester encoding/decoding (Thomas variant)
- ✅ Odd parity calculation and validation
- ✅ Command and Status word parsing
- ✅ Bus Controller and Remote Terminal management
- ✅ Transaction-level parsing
- ✅ Comprehensive error handling
- ✅ Optional serialization support (with
serdefeature)
Optional Features
Serialization
Enable JSON serialization/deserialization:
This adds serde::Serialize and serde::Deserialize derives to data structures.
Testing
Run the comprehensive test suite:
Tests cover:
- Word creation and parity validation
- Manchester encoding/decoding roundtrips
- Command/Status word encode/decode
- Parser functionality
- Bus Controller operations
- Error handling
Design Decisions
Word Encoding Format
The 20-bit word is structured as:
- Bit 0: Start bit (always 0)
- Bits 16-1: Data (16 bits)
- Bit 17: Parity (odd parity over bits 16-0)
- Bits 19-18: Sync/Reserved
Parity Scheme
Uses odd parity over 17 bits (start bit + 16 data bits). This ensures:
- Even number of 0s in the data → parity bit = 1
- Odd number of 0s in the data → parity bit = 0
- Total count of 1s is always odd
Command/Status Format
Maps protocol data into 16-bit data field:
- Bits 15-12: Address (4 bits)
- Bits 11-7: Function bits (5 bits)
- Bits 6-0: Operand (7 bits)
Note: This limits some fields compared to full MIL-STD-1553B. Can be extended for specific implementations.
Constants
The library exports key specification constants:
Future Enhancements
- Real-time bus monitoring capabilities
- Support for Bus Monitor parsing
- Advanced error recovery mechanisms
- Performance optimizations for high-speed parsing
- Additional serialization formats (CBOR, MessagePack)
- Async/await support for bus operations
- Extended mode codes implementation
- Signal integrity analysis
License
This project is provided as-is for educational and commercial use in MIL-STD-1553B implementations.
Contributing
Contributions are welcome! Areas for improvement:
- Additional test coverage
- Performance optimizations
- Extended protocol features
- Documentation improvements
References
- MIL-STD-1553B: Aircraft Internal Time Division Command/Response Multiplex Data Bus
- Manchester Encoding and Decoding
- Aerospace data bus systems and avionics integration