### Build MIL-STD-1553B Message with String/Byte Data in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Demonstrates building MIL-STD-1553B messages with string and byte data, showcasing automatic chunking into 2-byte data words. Includes examples of retrieving data and mutating message content. ```Rust use mil_std_1553b::*; fn main() -> Result<()> { // Build message with string data (auto-chunks to 2-byte words) let message = Message::<3>::new() .with_command(0b0000000000000010u16) // word_count = 2 .with_string("TEST") // Creates 2 data words: "TE", "ST" .build()?; assert!(message.is_full()); assert_eq!(message.count(), 2); // Retrieve string data let word0: &str = message.get(0).unwrap(); let word1: &str = message.get(1).unwrap(); assert_eq!(word0, "TE"); assert_eq!(word1, "ST"); // Build message with byte data let message2 = Message::<3>::new() .with_command(0b0000000000000010u16) .with_bytes(&[0x01, 0x02, 0x03, 0x04]) // Creates 2 data words .build()?; let bytes: [u8; 2] = message2.get(0).unwrap(); assert_eq!(bytes, [0x01, 0x02]); // Mutate message data let mut mutable_msg = Message::<3>::new() .with_command(0b0000000000000010u16); mutable_msg.add_string("AB"); mutable_msg.set_string("CD"); // Replaces existing data words let result = mutable_msg.build(); assert!(result.is_ok()); Ok(()) } ``` -------------------------------- ### Creating a StatusWord Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Demonstrates how to create a StatusWord by setting various flags such as terminal address, service request, busy status, and error indicators. It also shows how to build a StatusWord with calculated parity and how to create one from raw bytes. ```APIDOC ## Creating a StatusWord StatusWord is sent by remote terminals in response to valid messages from the bus controller. It contains terminal address, error flags, busy status, and other condition indicators. ### Method This is a conceptual representation of creating a StatusWord object in Rust. ### Endpoint N/A (Library Usage) ### Parameters N/A (Library Usage) ### Request Example ```rust use mil_std_1553b::* fn main() -> Result<()> { // Create a status word with various flags let status = StatusWord::new() .with_address(Address::Value(16)) .with_service_request(ServiceRequest::Service) // Terminal needs servicing .with_broadcast_received(BroadcastReceived::Received) // Received broadcast command .with_terminal_busy(TerminalBusy::NotBusy) .with_dynamic_bus_acceptance(DynamicBusAcceptance::NotAccepted) .with_message_error(MessageError::None) .with_subsystem_error(SubsystemError::None) .with_terminal_error(TerminalError::None) .with_calculated_parity() .build()?; // Check status word flags assert_eq!(status.broadcast_received(), BroadcastReceived::Received); assert_eq!(status.service_request(), ServiceRequest::Service); assert!(!status.is_error()); // Check if any error flag is set assert!(!status.is_busy()); // Check terminal busy status // Create from raw bytes let status_from_bytes: StatusWord = [0b10000001, 0b00000001].into(); Ok(()) } ``` ### Response N/A (Library Usage) ### Response Example N/A (Library Usage) ``` -------------------------------- ### Word Construction and Mutation Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Details how to instantiate and modify Command, Status, and Data words using constructors, builder patterns, and setter methods. ```APIDOC ## Word Construction ### Description Words can be created from raw values, byte arrays, or via a builder pattern for complex configurations. ### Construction Methods - `new()`: Creates an empty word. - `from_value(u16)`: Creates a word from a 16-bit integer. - `from_bytes([u8; 2])`: Creates a word from a byte array. ### Builder Pattern Use the builder pattern to chain configuration methods: ```rust let status = StatusWord::new() .with_value(0x0000) .with_calculated_parity() .build()?; ``` ### Mutable Operations - `set_value(u16)`: Updates the word value. - `set_bytes([u8; 2])`: Updates the word via bytes. - `set_parity(bool)`: Manually sets the parity bit. ``` -------------------------------- ### Creating a DataWord Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Illustrates how to create a DataWord, which holds two bytes of data. It covers creation from u16 values, raw bytes, and strings, along with automatic parity calculation and conversion to different data types. ```APIDOC ## Creating a DataWord DataWord contains two bytes of data transmitted in a message. Data words can be created from bytes, u16 values, or strings, and automatically handle parity calculation. ### Method This is a conceptual representation of creating a DataWord object in Rust. ### Endpoint N/A (Library Usage) ### Parameters N/A (Library Usage) ### Request Example ```rust use mil_std_1553b::* fn main() -> Result<()> { // Create from u16 value let data1 = DataWord::new() .with_value(0b0100100001001001u16) // "HI" in ASCII .with_calculated_parity() .build()?; // Create from bytes let data2 = DataWord::new() .with_bytes([0b01001000, 0b01001001]) .with_calculated_parity() .build()?; // Create from string (must be exactly 2 ASCII characters) let data3 = DataWord::try_from("HI")?; // Using with_string builder pattern let data4 = DataWord::new() .with_string("NO")? .with_calculated_parity() .build()?; // Convert to string assert_eq!(data1.as_string(), Ok("HI")); assert_eq!(data4.as_string(), Ok("NO")); // Convert to various numeric types let value_u16: u16 = data1.as_value(); let value_i32: i32 = data1.into(); let value_u64: u64 = data1.into(); let bytes: [u8; 2] = data1.as_bytes(); // Parity checking assert!(data1.check_parity()); let parity_bit = data1.parity(); Ok(()) } ``` ### Response N/A (Library Usage) ### Response Example N/A (Library Usage) ``` -------------------------------- ### Create and Parse Data Words Source: https://github.com/mjhouse/mil_std_1553b/blob/development/README.md Illustrates the creation of a data word from raw bytes and verifying its content as a string. Demonstrates the use of parity calculation methods. ```rust use mil_std_1553b::*;let word = DataWord::new().with_bytes([0b01001000, 0b01001001]).with_calculated_parity().build().unwrap();assert_eq!(word.as_string(),Ok("HI")); ``` -------------------------------- ### Create MIL-STD-1553B StatusWord in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Demonstrates creating a MIL-STD-1553B StatusWord, setting various terminal status flags, and checking them. It also shows how to initialize a StatusWord from raw bytes. ```Rust use mil_std_1553b::*; fn main() -> Result<()> { // Create a status word with various flags let status = StatusWord::new() .with_address(Address::Value(16)) .with_service_request(ServiceRequest::Service) // Terminal needs servicing .with_broadcast_received(BroadcastReceived::Received) // Received broadcast command .with_terminal_busy(TerminalBusy::NotBusy) .with_dynamic_bus_acceptance(DynamicBusAcceptance::NotAccepted) .with_message_error(MessageError::None) .with_subsystem_error(SubsystemError::None) .with_terminal_error(TerminalError::None) .with_calculated_parity() .build()?; // Check status word flags assert_eq!(status.broadcast_received(), BroadcastReceived::Received); assert_eq!(status.service_request(), ServiceRequest::Service); assert!(!status.is_error()); // Check if any error flag is set assert!(!status.is_busy()); // Check terminal busy status // Create from raw bytes let status_from_bytes: StatusWord = [0b10000001, 0b00000001].into(); Ok(()) } ``` -------------------------------- ### Building a Message with Command Word Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Explains how to construct a MIL-STD-1553B message, which includes a command or status word followed by data words. This section covers specifying the message capacity, adding command and data words, and checking message properties like length, count, and validity. ```APIDOC ## Building a Message with Command Word Message is the primary struct for building and parsing 1553B messages. Messages consist of a header word (command or status) followed by data words. The generic parameter specifies maximum word capacity. ### Method This is a conceptual representation of building a Message object in Rust. ### Endpoint N/A (Library Usage) ### Parameters N/A (Library Usage) ### Request Example ```rust use mil_std_1553b::* fn main() -> Result<()> { // Build a command message with 3 words total (1 command + 2 data) let message = Message::<3>::new() .with_command(CommandWord::new() .with_address(Address::Value(12)) .with_subaddress(SubAddress::Value(5)) .with_word_count(2) // Expects 2 data words .build()? ) .with_data(DataWord::new()) .with_data(DataWord::new()) .build()?; // Check message properties assert!(message.is_command()); assert!(!message.is_status()); assert!(message.is_full()); // All expected words added assert!(message.is_valid()); // Passes validation assert_eq!(message.length(), 3); // Total words assert_eq!(message.count(), 2); // Data words only assert_eq!(message.size(), 3); // Max capacity // Access words let cmd = message.command().unwrap(); let data0 = message.at(0).unwrap(); // First data word (index 0) // Using u16 values directly (auto-converts) let simple_message = Message::<2>::new() .with_command(0b0000000000000001u16) // word_count = 1 .with_data(0b0100100001001001u16) // "HI" .build()?; Ok(()) } ``` ### Response N/A (Library Usage) ### Response Example N/A (Library Usage) ``` -------------------------------- ### Rust: Message Validation and Error Handling Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Demonstrates how to use the MIL-STD-1553B library for message validation, including checking for header order, parity, and word count. It also shows how to manually validate messages and handle various parsing errors. ```rust use mil_std_1553b::*; fn main() { // Validation during build let invalid_message = Message::<2>::new() .with_data(0u16) // Data word first - invalid! .with_command(0u16) .build(); assert!(matches!(invalid_message, Err(Error::HeaderNotFirst))); // Parity validation let bad_parity = CommandWord::new() .with_value(0b0000000000000000) .with_parity(0) // Incorrect parity .build(); assert!(matches!(bad_parity, Err(Error::InvalidWord))); // Word count validation let wrong_count = Message::<3>::new() .with_command(0b0000000000000001u16) // word_count = 1 .with_data(0u16) .with_data(0u16) // Too many data words .build(); assert!(matches!(wrong_count, Err(Error::InvalidMessage))); // Manual validation let message = Message::<2>::new() .with_command(0b0000000000000001u16) .with_data(0u16); if message.is_valid() { println!("Message is valid"); } // Get detailed validation error match message.validate() { Ok(()) => println!("Valid"), Err(Error::InvalidWord) => println!("Bad word parity"), Err(Error::InvalidMessage) => println!("Wrong word count"), Err(Error::HeaderNotFirst) => println!("Data before header"), Err(Error::OutOfBounds) => println!("Overflow"), Err(e) => println!("Other error: {:?}", e), } // Parse errors let too_short = Message::<2>::read_command(&[0x00, 0x01]); assert!(matches!(too_short, Err(Error::InvalidMessage))); } ``` -------------------------------- ### Create MIL STD 1553B CommandWord in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Demonstrates how to create a MIL STD 1553B CommandWord using the builder pattern in Rust. It covers setting terminal address, subaddress, transmit/receive direction, and word count. It also shows how to access fields and convert the CommandWord to bytes or a u16 value. ```rust use mil_std_1553b::*; fn main() -> Result<()> { // Create a command word with builder pattern let command = CommandWord::new() .with_address(Address::Value(16)) // Terminal address 0-30 (31 = broadcast) .with_subaddress(SubAddress::Value(5)) // Subaddress 1-30 (0, 31 = mode code) .with_transmit_receive(TransmitReceive::Receive) .with_word_count(3) // Number of data words (1-32, 0 = 32) .with_calculated_parity() // Auto-calculate parity bit .build()?; // Access command word fields assert_eq!(command.address(), Address::Value(16)); assert_eq!(command.subaddress(), SubAddress::Value(5)); assert_eq!(command.word_count(), 3); assert!(command.is_receive()); assert!(!command.is_mode_code()); // Create from raw u16 value let command_from_u16 = CommandWord::from(0b1000000101000011); // Convert back to bytes or u16 let bytes: [u8; 2] = command.as_bytes(); let value: u16 = command.as_value(); Ok(()) } ``` -------------------------------- ### Write MIL-STD-1553B Messages to Binary in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Demonstrates serializing MIL-STD-1553B messages into a byte buffer for transmission. Includes error handling for insufficient buffer size and a round-trip parse verification. ```Rust use mil_std_1553b::*; fn main() -> Result<()> { // Create a message let message = Message::<3>::new() .with_command(CommandWord::new() .with_address(Address::Value(12)) .with_subaddress(SubAddress::Value(3)) .with_word_count(2) .with_calculated_parity() .build()?) .with_data(DataWord::try_from("AB")?) .with_data(DataWord::try_from("CD")?) .build()?; // Allocate buffer for output (20 bits per word, packed) // 3 words * 20 bits = 60 bits = 8 bytes let mut buffer = [0u8; 10]; // Write message to buffer message.write(&mut buffer)?; // Round-trip: parse the buffer back let parsed = Message::<3>::read_command(&buffer)?; assert_eq!(parsed.length(), message.length()); // Buffer too small causes error let mut small_buffer = [0u8; 3]; let result = message.write(&mut small_buffer); assert!(result.is_err()); Ok(()) } ``` -------------------------------- ### Construct a MIL-STD-1553B Message Source: https://github.com/mjhouse/mil_std_1553b/blob/development/README.md Demonstrates how to build a message object by chaining command and data word constructors. It utilizes the builder pattern to ensure valid message structure. ```rust 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); ``` -------------------------------- ### Build MIL-STD-1553B Message with Command Word in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Shows how to construct a MIL-STD-1553B Message, including a Command Word and Data Words. It covers setting message properties, validation, and accessing individual words within the message. ```Rust use mil_std_1553b::*; fn main() -> Result<()> { // Build a command message with 3 words total (1 command + 2 data) let message = Message::<3>::new() .with_command(CommandWord::new() .with_address(Address::Value(12)) .with_subaddress(SubAddress::Value(5)) .with_word_count(2) // Expects 2 data words .build()?) .with_data(DataWord::new()) .with_data(DataWord::new()) .build()?; // Check message properties assert!(message.is_command()); assert!(!message.is_status()); assert!(message.is_full()); // All expected words added assert!(message.is_valid()); // Passes validation assert_eq!(message.length(), 3); // Total words assert_eq!(message.count(), 2); // Data words only assert_eq!(message.size(), 3); // Max capacity // Access words let cmd = message.command().unwrap(); let data0 = message.at(0).unwrap(); // First data word (index 0) // Using u16 values directly (auto-converts) let simple_message = Message::<2>::new() .with_command(0b0000000000000001u16) // word_count = 1 .with_data(0b0100100001001001u16) // "HI" .build()?; Ok(()) } ``` -------------------------------- ### Create MIL-STD-1553B DataWord in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Illustrates creating a MIL-STD-1553B DataWord from different sources like u16 values, byte arrays, and strings. It covers automatic parity calculation and conversion to various types. ```Rust use mil_std_1553b::*; fn main() -> Result<()> { // Create from u16 value let data1 = DataWord::new() .with_value(0b0100100001001001u16) // "HI" in ASCII .with_calculated_parity() .build()?; // Create from bytes let data2 = DataWord::new() .with_bytes([0b01001000, 0b01001001]) .with_calculated_parity() .build()?; // Create from string (must be exactly 2 ASCII characters) let data3 = DataWord::try_from("HI")?; // Using with_string builder pattern let data4 = DataWord::new() .with_string("NO")? .with_calculated_parity() .build()?; // Convert to string assert_eq!(data1.as_string(), Ok("HI")); assert_eq!(data4.as_string(), Ok("NO")); // Convert to various numeric types let value_u16: u16 = data1.as_value(); let value_i32: i32 = data1.into(); let value_u64: u64 = data1.into(); let bytes: [u8; 2] = data1.as_bytes(); // Parity checking assert!(data1.check_parity()); let parity_bit = data1.parity(); Ok(()) } ``` -------------------------------- ### Rust: Address and SubAddress Types Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Illustrates the use of type-safe `Address` and `SubAddress` types in the MIL-STD-1553B library, which provide automatic validation for terminal addresses, subaddresses, broadcast, and mode codes. ```rust use mil_std_1553b::*; fn main() { // Terminal Address (5 bits: 0-30 are terminals, 31 is broadcast) let terminal = Address::Value(12); let broadcast = Address::Broadcast(0b11111); assert!(terminal.is_value()); assert!(broadcast.is_broadcast()); // Automatic classification from raw values let addr: Address = 30u8.into(); // Address::Value(30) let addr: Address = 31u8.into(); // Address::Broadcast(31) // Values > 31 are masked to 5 bits let addr: Address = 0xFFu8.into(); // Address::Broadcast(31) // SubAddress (5 bits: 1-30 are subaddresses, 0 and 31 indicate mode code) let sub = SubAddress::Value(5); let mode = SubAddress::ModeCode(0); assert!(sub.is_value()); assert!(mode.is_mode_code()); // Automatic classification let sub: SubAddress = 15u8.into(); // SubAddress::Value(15) let sub: SubAddress = 0u8.into(); // SubAddress::ModeCode(0) let sub: SubAddress = 31u8.into(); // SubAddress::ModeCode(31) // Convert back to numeric let value: u8 = terminal.into(); let value: u16 = sub.into(); } ``` -------------------------------- ### Word Trait and Common Operations Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Explains the Word trait interface, which provides unified methods for construction, parity checking, and byte manipulation across Command, Status, and Data words. ```APIDOC ## Word Trait Interface ### Description The `Word` trait is the core abstraction for all MIL-STD-1553B word types. It provides methods for byte conversion, value retrieval, and parity validation. ### Methods - `as_bytes()`: Returns the word representation as a byte array. - `as_value()`: Returns the raw u16 value. - `parity()`: Returns the current parity bit. - `check_parity()`: Validates the parity of the current word. - `calculate_parity()`: Computes the correct parity bit for the current value. ### Usage Example ```rust fn process_word(word: W) -> W { let bytes = word.as_bytes(); let valid = word.check_parity(); word } ``` ``` -------------------------------- ### Parse MIL-STD-1553B Messages from Binary in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Shows how to parse raw binary data into MIL-STD-1553B command or status messages. The library automatically handles 20-bit word alignment and packing into bytes. ```Rust use mil_std_1553b::*; fn main() -> Result<()> { // Raw binary data (20-bit words packed into bytes) let binary_data = [ 0b10000011, 0b00001100, 0b00100010, 0b11010000, 0b11010010 ]; // Parse as command message (word count from command determines data words) let cmd_message = Message::<4>::read_command(&binary_data)?; assert!(cmd_message.is_command()); assert_eq!(cmd_message.length(), 2); // 1 command + 1 data word // Parse as status message (parses data words to end of buffer) let status_message = Message::<4>::read_status(&binary_data)?; assert!(status_message.is_status()); assert_eq!(status_message.length(), 2); // Parse longer message let longer_data = [ 0b10000011, 0b00001100, 0b01110010, 0b11010000, 0b11010010, 0b00101111, 0b00101101, 0b11100010, 0b11001110, 0b11011110, ]; let message = Message::<4>::read_command(&longer_data)?; assert_eq!(message.length(), 4); // 1 command + 3 data words Ok(()) } ``` -------------------------------- ### Message Construction and Parsing Source: https://github.com/mjhouse/mil_std_1553b/blob/development/README.md Methods for building and parsing MIL-STD-1553B messages, including command and status word handling. ```APIDOC ## Rust Library Usage: Message Operations ### Description This library provides a fluent API to construct and parse MIL-STD-1553B messages. It supports static allocation and is suitable for embedded systems. ### Usage - **Message Construction**: Use the `Message::new()` builder pattern to assemble command and data words. - **Parsing**: Use `Message::read_command` or `Message::read_status` to deserialize raw byte buffers into structured objects. ### Request Example (Construction) ```rust 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(); ``` ### Response - **Success**: Returns a `Message` struct containing the validated words and parity bits. - **Error**: Returns an `Err` if the word count or parity validation fails. ``` -------------------------------- ### Message Data Handling Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Demonstrates how to add string or byte data to messages, which are automatically chunked into 2-byte data words. ```APIDOC ## PUT /message/data ### Description Updates or adds data to an existing message. Strings and byte arrays are automatically partitioned into 2-byte MIL-STD-1553B data words. ### Method PUT ### Endpoint /message/data ### Parameters #### Request Body - **data_type** (String) - Required - 'string' or 'bytes'. - **payload** (String/Array) - Required - The content to be added to the message. ### Request Example { "data_type": "string", "payload": "TEST" } ### Response #### Success Response (200) - **status** (String) - Confirmation of data addition. ``` -------------------------------- ### Parse Command and Status Messages Source: https://github.com/mjhouse/mil_std_1553b/blob/development/README.md Shows how to parse raw byte arrays into command or status messages. The library automatically determines the expected data word count based on the leading command word. ```rust use mil_std_1553b::*;let message: Message = Message::read_command(&[0b10000011, 0b00001100, 0b00100010, 0b11010000, 0b11010010]).unwrap();assert_eq!(message.length(),2);let message: Message = Message::read_status(&[0b10000011, 0b00001100, 0b01000010, 0b11010000, 0b11010010]).unwrap();assert_eq!(message.length(), 2); ``` -------------------------------- ### Rust: Custom Data Words with Derive Macro Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Shows how to define custom data word types with named bit fields using the `derive(Word)` macro for domain-specific message parsing in the MIL-STD-1553B library. ```rust use mil_std_1553b::{ derive::{field, Word}, Field, Message, Result, }; // Define custom data word with derive macro #[derive(Default, Word)] struct SensorData { #[data] data: [u8; 2], #[parity] parity: u8, // Additional fields for your application cached_value: Option, } impl SensorData { // Define a bit field using the field! attribute // STATUS_LIGHT field: bit 15 (MSB), mask 0x8000 #[field(STATUS_LIGHT, 0b1000000000000000)] pub fn status_light_on(&self) -> bool { Self::STATUS_LIGHT.get::<_, u16>(self) == 1 } // Define temperature field: bits 0-7 (low byte) #[field(TEMPERATURE, 0b0000000011111111)] pub fn temperature(&self) -> u8 { Self::TEMPERATURE.get::<_, u8>(self) } } fn main() -> Result<()> { // Parse raw binary with custom word type let input = [ 0b10000011, 0b00001100, 0b01110011, 0b11010000, 0b11010011, 0b00101111, 0b00101101, 0b11100010, 0b11001110, 0b11011110, ]; let message = Message::<4>::read_command(&input)?; // Get custom typed words let sensor1: SensorData = message.get(0).unwrap(); let sensor2: SensorData = message.get(1).unwrap(); // Access typed fields println!("Sensor 1 status light: {}", sensor1.status_light_on()); println!("Sensor 2 status light: {}", sensor2.status_light_on()); Ok(()) } ``` -------------------------------- ### Create MIL STD 1553B CommandWord with Mode Code in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Illustrates creating a MIL STD 1553B CommandWord that includes a mode code in Rust. This is used for bus management and error handling, where the subaddress is 0 or 31. It shows how to set specific mode codes and check their properties. ```rust use mil_std_1553b::*; fn main() -> Result<()> { // Create a mode code command (e.g., transmitter shutdown) let mode_command = CommandWord::new() .with_address(Address::Value(16)) .with_subaddress(SubAddress::ModeCode(0)) // 0 or 31 indicates mode code .with_transmit_receive(TransmitReceive::Receive) .with_mode_code(ModeCode::TransmitterShutdown) // Kill a malfunctioning RT .with_calculated_parity() .build()?; assert!(mode_command.is_mode_code()); assert_eq!(mode_command.mode_code(), ModeCode::TransmitterShutdown); // Check mode code properties let code = ModeCode::SynchronizeWithDataWord; assert!(code.is_broadcast()); // Can be sent to all terminals assert!(!code.has_data()); // Does not have associated data word assert!(code.is_transmit()); // Associated with transmit messages // Available mode codes include: // DynamicBusControl, Synchronize, TransmitStatusWord, InitiateSelfTest, // TransmitterShutdown, OverrideTransmitterShutdown, InhibitTerminalFlagBit, // OverrideInhibitTerminalFlagBit, ResetRemoteTerminal, TransmitVectorWord, // SynchronizeWithDataWord, TransmitLastCommandWord, TransmitBITWord, // SelectedTransmitterShutdown, OverrideSelectedTransmitterShutdown Ok(()) } ``` -------------------------------- ### Build MIL-STD-1553B Status Message in Rust Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Constructs a MIL-STD-1553B status message, including a status word with address and service request, and appends data words. Demonstrates message type checking and data retrieval. ```Rust use mil_std_1553b::*; fn main() -> Result<()> { // Build a status message let message = Message::<3>::new() .with_status(StatusWord::new() .with_address(Address::Value(8)) .with_service_request(ServiceRequest::NoService) .with_calculated_parity() .build()?) .with_data(DataWord::try_from("TE")?) .with_data(DataWord::try_from("ST")?) .build()?; assert!(message.is_status()); assert!(!message.is_command()); assert_eq!(message.length(), 3); // Access the status word let status = message.status().unwrap(); assert_eq!(status.service_request(), ServiceRequest::NoService); // Get data as typed values let text: &str = message.get(0).unwrap(); assert_eq!(text, "TE"); Ok(()) } ``` -------------------------------- ### Building a Status Message Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Constructs a MIL-STD-1553B status message including a status word and associated data words. ```APIDOC ## POST /message/status ### Description Creates a new status message object. Status messages consist of a StatusWord followed by zero or more data words. ### Method POST ### Endpoint /message/status ### Request Body - **status_word** (Object) - Required - The status word configuration including address and service request status. - **data_words** (Array) - Optional - List of data words to include in the message. ### Request Example { "status_word": { "address": 8, "service_request": "NoService" }, "data": ["TE", "ST"] } ### Response #### Success Response (200) - **message_id** (String) - Unique identifier for the constructed message. - **length** (Integer) - Total number of words in the message. ``` -------------------------------- ### Parsing Binary Messages Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Parses raw binary data from the bus into structured message objects. ```APIDOC ## POST /message/parse ### Description Parses a raw binary buffer into a structured message object, handling 20-bit word alignment (sync, data, parity). ### Method POST ### Endpoint /message/parse ### Parameters #### Request Body - **binary_data** (Array) - Required - Raw byte array representing the 1553B message. - **type** (String) - Required - 'command' or 'status'. ### Request Example { "binary_data": [131, 12, 34, 208, 210], "type": "command" } ### Response #### Success Response (200) - **words** (Array) - The parsed word components of the message. ``` -------------------------------- ### Serializing Messages Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt Serializes a constructed message object into a binary buffer for transmission. ```APIDOC ## POST /message/serialize ### Description Converts a message object into a packed binary format suitable for transmission over the 1553B bus. ### Method POST ### Endpoint /message/serialize ### Parameters #### Request Body - **message** (Object) - Required - The message structure to serialize. ### Request Example { "message": { "command": 0x0002, "data": ["AB", "CD"] } } ### Response #### Success Response (200) - **buffer** (Array) - The serialized binary byte array. ``` -------------------------------- ### Rust MIL-STD-1553B Word Trait Operations Source: https://context7.com/mjhouse/mil_std_1553b/llms.txt This Rust code snippet showcases the common operations provided by the `Word` trait for MIL-STD-1553B CommandWord, StatusWord, and DataWord types. It demonstrates construction from various sources (empty, value, bytes, conversion), using a builder pattern for StatusWord, and mutable operations for DataWord, including parity checking and setting. ```rust use mil_std_1553b::* fn main() -> Result<()> { // Word trait methods work on CommandWord, StatusWord, and DataWord fn process_word(word: W) -> W { // Common operations available on all word types let bytes = word.as_bytes(); let value = word.as_value(); let parity = word.parity(); let valid_parity = word.check_parity(); let calculated = word.calculate_parity(); word } // Create words with various methods let cmd1 = CommandWord::new(); // Empty word let cmd2 = CommandWord::from_value(0x1234); // From u16 let cmd3 = CommandWord::from_bytes([0x12, 0x34]); // From bytes let cmd4: CommandWord = 0x1234u16.into(); // From conversion // Builder pattern with method chaining let status = StatusWord::new() .with_value(0x0000) .with_calculated_parity() .build()?; // Mutable operations let mut data = DataWord::new(); data.set_value(0x4849); // "HI" data.set_bytes([0x48, 0x49]); data.set_parity(data.calculate_parity()); assert!(data.check_parity()); Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.