[][src]Crate sensirion_hdlc

sensirion-hdlc

Only frames the data. Rust implementation of Sensirion High-level Data Link Control (HDLC) library.

Usage

Encode packet

extern crate sensirion_hdlc;
use sensirion_hdlc::{SpecialChars, encode};

let msg = [0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09, 0x20];
let cmp = [0x7E, 0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x09, 0x20, 0x7E];

let result = encode(&msg, SpecialChars::default()).unwrap();

assert_eq!(result[0..result.len()], cmp);

Custom Special Characters

extern crate sensirion_hdlc;
use sensirion_hdlc::{SpecialChars, encode};

let msg = [0x01, 0x7E, 0x70, 0x50, 0x00, 0x05, 0x80, 0x09, 0xe2];
let cmp = [0x71, 0x01, 0x7E, 0x70, 0x50, 0x50, 0x00, 0x05, 0x80, 0x09, 0xe2, 0x71];
let chars = SpecialChars::new(0x71, 0x70, 0x51, 0x50, 0x11, 0x31, 0x13, 0x33).unwrap();

let result = encode(&msg, chars).unwrap();

assert_eq!(result[0..result.len()], cmp)

Decode packet

extern crate sensirion_hdlc;
use sensirion_hdlc::{SpecialChars, decode};

let chars = SpecialChars::default();
let msg = [
    chars.fend, 0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x29, chars.fend,
];
let cmp = [0x01, 0x50, 0x00, 0x00, 0x00, 0x05, 0x80, 0x29];

let result = decode(&msg, chars).unwrap();

assert_eq!(result[0..result.len()], cmp);

Structs

SpecialChars

Special Character structure for holding the encode and decode values.

Enums

HDLCError

Common error for HDLC actions.

Functions

calculate_checksum

Calculate the SHDLC checksum

decode

Produces unescaped (decoded) message without FEND characters.

encode

Produces escaped (encoded) message surrounded with FEND