Skip to main content

teltonika_avl_protocol/
lib.rs

1#![cfg_attr(not(test), no_std)]
2
3pub mod codec8;
4pub mod error;
5
6pub use heapless::Vec as StackVec;
7
8// https://wiki.teltonika-gps.com/view/Codec#CRC-16
9pub fn crc16(msg: &[u8]) -> u16 {
10    let mut crc: u16 = 0x0;
11
12    for byte in msg.iter() {
13        crc ^= *byte as u16;
14
15        for _ in 0..=7 {
16            let carry = crc & 1;
17
18            crc >>= 1;
19
20            if carry == 1 {
21                crc ^= 0xa001
22            }
23        }
24    }
25
26    crc
27}