| Crates.io | nom-teltonika |
| lib.rs | nom-teltonika |
| version | 0.1.6 |
| created_at | 2023-01-02 13:02:14.056311+00 |
| updated_at | 2024-11-25 16:36:03.73562+00 |
| description | Teltonika protocol parser |
| homepage | |
| repository | https://github.com/DamianoPellegrini/nom-teltonika |
| max_upload_size | |
| id | 749362 |
| size | 98,323 |
This package makes use of the nom crate to parse the binary packets.
Parsing:
It fails parsing if any of the following checks fail:
It allows for sending commands to a device using Codec 12 ONLY.
A TeltonikaStream wrapper is provided to easily parse the incoming packets.
The following opt-in features are available:
[dependencies]
nom-teltonika = { version = "*", features = ["serde", "tokio"] }
let imei_buffer = [0x00, 0x0F, 0x33, 0x35,
0x36, 0x33, 0x30, 0x37,
0x30, 0x34, 0x32, 0x34,
0x34, 0x31, 0x30, 0x31,
0x33
];
let (rest, imei) = nom_teltonika::parser::imei(&imei_buffer).unwrap();
assert_eq!(rest, &[]);
assert_eq!(imei, String::from("356307042441013"));
let buffer = [0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x36,
0x08, 0x01, 0x00, 0x00,
0x01, 0x6B, 0x40, 0xD8,
0xEA, 0x30, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x05,
0x02, 0x15, 0x03, 0x01,
0x01, 0x01, 0x42, 0x5E,
0x0F, 0x01, 0xF1, 0x00,
0x00, 0x60, 0x1A, 0x01,
0x4E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00,
0xC7, 0xCF
];
let (rest, frame) = nom_teltonika::parser::tcp_frame(&buffer).unwrap();
assert_eq!(rest, &[]);
println!("{frame:#?}");
let mut file = std::fs::File::open("tests/test.bin").unwrap();
let mut stream = nom_teltonika::TeltonikaStream::new(file);
let frame = stream.read_frame().unwrap();
println!("{frame:#?}");
Further examples can be found in the examples folder.