calamp-rs

Crates.iocalamp-rs
lib.rscalamp-rs
version0.2.4
sourcesrc
created_at2021-07-03 04:37:10.928939
updated_at2021-07-10 15:48:03.085025
descriptionParser for the Calamp LMDirect message protocol
homepagehttps://git.sr.ht/~mbsd/calamp-rs
repositoryhttps://git.sr.ht/~mbsd/calamp-rs
max_upload_size
id418097
size70,863
msi (murilobsd)

documentation

https://docs.rs/calamp-rs

README

Calamp-rs

Banner

License: MIT Crates.io Version Doc

Features

  • Fast: use nom parser combinator
  • Security: memory safe
  • Messages: support EventReport
  • Serde: serialize to json, xml

Quickstart

To start with calamp-rs, add the following to your Cargo.toml file:

[dependencies]
calamp-rs= "0.2.4"

Next, parse message:

use calamp_rs::Message;

fn main() {
    let data: [u8; 117] = [
        0x83, 0x05, 0x46, 0x34, 0x66, 0x32, 0x35, 0x01, 0x01, 0x01, 0x02, 0x3a,
        0x86, 0x5f, 0xf1, 0x3a, 0x54, 0x5f, 0xf1, 0x3a, 0x57, 0xf1, 0xe2, 0x85,
        0x78, 0xe4, 0x22, 0xd6, 0x40, 0x00, 0x01, 0x36, 0xf8, 0x00, 0x00, 0x00,
        0x0b, 0x00, 0x00, 0x06, 0x20, 0x00, 0x00, 0xff, 0x8d, 0x02, 0x1e, 0x1e,
        0x00, 0x7b, 0x21, 0x10, 0x00, 0x00, 0x00, 0x31, 0xe0, 0x00, 0x00, 0x10,
        0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2a, 0x32, 0x00, 0x00, 0x03,
        0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc8, 0x2d,
        0x3f, 0x01, 0xc8, 0x2d, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
        0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    ];

    let msg = Message::parse(&data);

    println!("Message Type: {}", msg.message_header.message_type);
}

Finally, run this benchmark with cargo run. You should see output similar to the following:

Message Type: MessageType::EventReport

Examples

To see some examples just run them via cargo run --examples.

cargo run --example srv_udp

Another terminal:

cargo run --example cli_udp

Contributing

First, thank you for contributing.

One great way to contribute to calamp-rs is to use it for your own benchmarking needs and report your experiences, file and comment on issues, etc.

Code or documentation improvements in the form of pull requests are also welcome. If you're not sure what to work on, try checking the Beginner label.

If your issues or pull requests have no response after a few days, feel free to ping me (@muriloijanc).

For more details, see the CONTRIBUTING.md file.

License

Calamp-rs is distributed under the terms of the BSD2 license.

See LICENSE

Commit count: 0

cargo fmt