#dlt #serialization #messages #parser #trace #diagnostics #writer

dlt-core

Autosar DLT 诊断日志和跟踪的解析器和写入器

14 个版本

0.14.5 2023年7月21日
0.14.3 2022年11月18日
0.14.0 2022年2月15日
0.11.0 2021年12月14日
0.10.1 2021年7月12日

#507编码

Download history 36/week @ 2024-03-13 33/week @ 2024-03-20 8/week @ 2024-03-27 22/week @ 2024-04-03 105/week @ 2024-04-10 95/week @ 2024-04-17 108/week @ 2024-04-24 70/week @ 2024-05-01 75/week @ 2024-05-08 54/week @ 2024-05-15 88/week @ 2024-05-22 87/week @ 2024-05-29 68/week @ 2024-06-05 20/week @ 2024-06-12 6/week @ 2024-06-19 58/week @ 2024-06-26

每月下载量:158

Apache-2.0

260KB
6K SLoC

LICENSE

Autosar DLT 支持

支持以 Diagnositic LogTrace 消息编码的日志消息的高效解析和写入的库。

特性

  • 符合官方 Autosar DLT 规范
  • 高效解析二进制 DLT 内容
  • 序列化 DLT 消息
  • 通过 FIBEX 文件信息支持非冗长消息

用法

将此添加到您的 Cargo.toml

[dependencies]
dlt_core = "0.14"

这是如何解析消息并将其反序列化为字节数组的示例。

use dlt_core::dlt_parse::{dlt_message, ParsedMessage};

fn main() {
    let raw1: Vec<u8> = vec![
        // --------------- storage header
        /* DLT + 0x01 */ 0x44, 0x4C, 0x54, 0x01,
        /* timestamp sec */ 0x2B, 0x2C, 0xC9, 0x4D, /* timestamp us */ 0x7A, 0xE8, 0x01,
        0x00, /* ecu id "ECU" */ 0x45, 0x43, 0x55, 0x00,
        // --------------- header
        /* header-type       0b0010 0001 */ 0x21,
        /* extended header        | |||^ */
        /* MSBF: 0  little endian | ||^  */
        /* WEID: 0  no ecu id     | |^   */
        /* WSID: 0  sess id       | ^    */
        /* WTMS: 0 no timestamp   ^      */
        /* version nummber 1   ^^^       */
        /* message counter */
        0x0A, /* length = 0 */ 0x00, 0x13,
        // --------------- extended header
        0x41, // MSIN 0b0100 0001 => verbose, MST log, ApplicationTraceType::State
        0x01, // arg count
        0x4C, 0x4F, 0x47, 0x00, // app id LOG
        0x54, 0x45, 0x53, 0x32, // context id TES2
        // --------------- payload
        /* type info 0b0001 0000 => type bool */ 0x10,
        0x00, 0x00, 0x00, 0x6F,
    ];
    match dlt_message(&raw1[..], None, true) {
        Ok((_rest, ParsedMessage::Item(msg))) => {
            let msg_bytes = msg.as_bytes();
            assert_eq!(raw1, msg_bytes);
        }
        _ => panic!("could not parse message"),
    }
}

解析器非常快。解析包含超过 3.5 mio 条消息的 4.8 GByte DLT 文件花费了大约 37 秒 (~134MB/sec)

此示例可以用以下命令构建:cargo build --example file_parser --release

...
fn main() {
    // collect input file details
    let dlt_file_path = PathBuf::from(&env::args().nth(1).expect("No filename given"));
    let dlt_file = File::open(&dlt_file_path).expect("could not open file");
    let source_file_size = fs::metadata(&dlt_file_path).expect("file size error").len();
    // create a reader that maintains a minimum amount of bytes in it's buffer
    let mut reader = BufReader::with_capacity(BIN_READER_CAPACITY, dlt_file)
        .set_policy(MinBuffered(BIN_MIN_BUFFER_SPACE));
    // now parse all file content
    let mut parsed = 0usize;
    let start = Instant::now();
    loop {
        let consumed: usize = match reader.fill_buf() {
            Ok(content) => {
                if content.is_empty() {
                    println!("empty content after {} parsed messages", parsed);
                    break;
                }
                let available = content.len();

                match dlt_message(content, None, true) {
                    Ok((rest, _maybe_msg)) => {
                        let consumed = available - rest.len();
                        parsed += 1;
                        consumed
                    }
                    Err(DltParseError::IncompleteParse { needed }) => {
                        println!("parse incomplete, needed: {:?}", needed);
                        return;
                    }
                    Err(DltParseError::ParsingHickup(reason)) => {
                        println!("parse error: {}", reason);
                        4 //skip 4 bytes
                    }
                    Err(DltParseError::Unrecoverable(cause)) => {
                        println!("unrecoverable parse failure: {}", cause);
                        return;
                    }
                }
            }
            Err(e) => {
                println!("Error reading: {}", e);
                return;
            }
        };
        reader.consume(consumed);
    }

    // print some stats
    let duration_in_s = start.elapsed().as_millis() as f64 / 1000.0;
    let file_size_in_mb = source_file_size as f64 / 1024.0 / 1024.0;
    let amount_per_second: f64 = file_size_in_mb / duration_in_s;
    println!(
        "parsing {} messages took {:.3}s! ({:.3} MB/s)",
        parsed, duration_in_s, amount_per_second
    );
}
empty content after 33554430 parsed messages
parsing 33554430 messages took 37.015s! (133.773 MB/s)

依赖项

~3.5–4.5MB
~85K SLoC