#固件 #摩托罗拉 #S记录

srec

解析和生成摩托罗拉S记录(SRECORD/SREC)文件

4个版本

0.2.0 2020年6月26日
0.1.2 2020年2月8日
0.1.1 2019年12月3日
0.1.0 2019年12月3日

#1072解析实现

Download history 292/week @ 2024-03-14 189/week @ 2024-03-21 238/week @ 2024-03-28 200/week @ 2024-04-04 248/week @ 2024-04-11 305/week @ 2024-04-18 486/week @ 2024-04-25 417/week @ 2024-05-02 304/week @ 2024-05-09 257/week @ 2024-05-16 266/week @ 2024-05-23 267/week @ 2024-05-30 320/week @ 2024-06-06 308/week @ 2024-06-13 250/week @ 2024-06-20 199/week @ 2024-06-27

1,127 每月下载量
用于 rxprog

MIT 许可证

35KB
844

srec

crates.io badge

一个Rust包,用于解析/读取和生成/写入摩托罗拉S记录(也称为SRECORD或SREC)文件。

在docs.rs上查看文档

示例

读取

examples/read_srec_file.rs

let s = fs::read_to_string(path)?;

let records = srec::read_records(&s);

for record in records {
    match record {
        Ok(record) => match record {
            srec::Record::S0(s) => println!("S0 header: \"{}\"", s),
            srec::Record::S1(data) => println!(
                "S1 data w/ 16-bit address: addr = {:#06X}, data = {:02X?}",
                u32::from(data.address),
                data.data
            ),
            srec::Record::S2(data) => println!(
                "S2 data w/ 24-bit address: addr = {:#08X}, data = {:02X?}",
                u32::from(data.address),
                data.data
            ),
            srec::Record::S3(data) => println!(
                "S3 data w/ 32-bit address: addr = {:#010X}, data = {:02X?}",
                u32::from(data.address),
                data.data
            ),
            srec::Record::S5(count) => {
                println!("S5 16-bit record count: count = {:#06X}", u32::from(count))
            }
            srec::Record::S6(count) => {
                println!("S6 24-bit record count: count = {:#08X}", u32::from(count))
            }
            srec::Record::S7(addr) => {
                println!("S7 32-bit start address: addr = {:#010X}", u32::from(addr))
            }
            srec::Record::S8(addr) => {
                println!("S8 24-bit start address: addr = {:#08X}", u32::from(addr))
            }
            srec::Record::S9(addr) => {
                println!("S9 16-bit start address: addr = {:#06X}", u32::from(addr))
            }
        },
        Err(err) => println!("error reading record: {}", err),
    }
}

写入

examples/write_srec_file.rs

let records = [
    srec::Record::S0("HDR".into()),
    srec::Record::S1(srec::Data {
        address: srec::Address16(0x1234),
        data: vec![0x00, 0x01, 0x02, 0x03],
    }),
    srec::Record::S1(srec::Data {
        address: srec::Address16(0x1238),
        data: vec![0x04, 0x05, 0x06, 0x07],
    }),
    srec::Record::S9(srec::Address16(0x1234)),
];

let s = srec::writer::generate_srec_file(&records);

let mut file = fs::File::create(path)?;
file.write_all(&s.into_bytes())?;

无运行时依赖