#diagnostics #codec #vehicle #doip

doip-codec

Diagnostics over Internet Protocol codec for client-server communication

4 stable releases

2.0.2 Jan 3, 2025
1.0.0 Dec 11, 2024

#381 in Simulation

Download history 146/week @ 2024-12-11 3/week @ 2024-12-18 376/week @ 2025-01-01 69/week @ 2025-01-08

449 downloads per month
Used in doip-sockets

MIT license

16KB
248 lines

Diagnostics over Internet Protocol (DoIP) Codec

The doip-codec crate provides a Encoder and Decoder implementation for encoding and decoding Diagnostics Over Internet Protocol (DoIP) messages. It is designed to integrate seamlessly with the Tokio ecosystem, leveraging tokio-util's Framed for efficient stream-based reading and writing of DoIP messages.

Features

  • Full support for encoding and decoding DoIP messages as per the ISO 13400 standard.
  • Easy integration with Tokio's asynchronous I/O framework.
  • Robust and efficient handling of DoIP message framing.
  • Customizable for various DoIP use cases, including vehicle diagnostics and testing.

Installation

Add the following to your Cargo.toml:

[dependencies]
doip-codec = "1.0.0"

Then, include the crate in your code:

use doip_codec::DoipCodec;

Usage

Here's a simple example to get started with DoipCodec:

use futures::{SinkExt, StreamExt};
use tokio::net::TcpStream;
use tokio_util::codec::Framed;
use doip_definitions::{
    header::DoipVersion,
    message::{DoipMessage, VehicleIdentificationRequest},
};
use doip_codec::DoipCodec;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  // Connect to a DoIP server
  let stream = TcpStream::connect("127.0.0.1:13400").await?;

  // Wrap the stream with the DoipCodec
  let mut framed = Framed::new(stream, DoipCodec);

  // Send a DoIP message
  let request = DoipMessage::new(
      DoipVersion::Iso13400_2012,
      Box::new(VehicleIdentificationRequest {}),
  ); // Example payload

  framed.send(request).await?;

  // Receive a DoIP message
  if let Some(response) = framed.next().await {
      match response {
          Ok(msg) => println!("Received message: {:?}", msg),
          Err(e) => eprintln!("Failed to decode message: {}", e),
      }
  }

  Ok(())
}

Documentation

Comprehensive API documentation is available on docs.rs.

Why DoIP?

Diagnostics Over Internet Protocol (DoIP) is a modern diagnostic communication protocol that leverages IP-based networks for vehicle diagnostics, making it a critical component in automotive software. The doip-codec crate simplifies the implementation of DoIP messaging for Rust developers.

Contributing

Contributions are welcome! Feel free to open issues, submit pull requests, or suggest features. Please follow the Rust Code of Conduct when contributing.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Dependencies

~2.9–9MB
~74K SLoC