ltc681x 0.6.2

Client LTC681X battery monitoring family
Documentation
//! Tests for PEC15 checksum algorithm
use crate::pec15::PEC15;

#[test]
fn test_pec15_two_bytes() {
    // STSCTRL command
    assert_eq!([0x8e, 0x4e], PEC15::calc(&[0x0, 0x19]));

    // CLRSCTRL command
    assert_eq!([0x5, 0x7c], PEC15::calc(&[0x0, 0x18]));

    // Cell Voltage register A
    assert_eq!([0x7, 0xC2], PEC15::calc(&[0x0, 0x4]));

    // Status register group A
    assert_eq!([0xED, 0x72], PEC15::calc(&[0x0, 0x10]));

    // Status register group B
    assert_eq!([0x70, 0x24], PEC15::calc(&[0x0, 0x12]));

    // Read Configuration register group A
    assert_eq!([0x2B, 0xA], PEC15::calc(&[0x0, 0x2]));

    // Read Configuration register group B
    assert_eq!([0x2C, 0xC8], PEC15::calc(&[0x0, 0x26]));

    // Write Configuration register group A
    assert_eq!([0x3D, 0x6E], PEC15::calc(&[0x0, 0x1]));

    // Write Configuration register group B
    assert_eq!([0xB1, 0x9E], PEC15::calc(&[0x0, 0x24]));
}

#[test]
fn test_pec15_multiple_bytes() {
    assert_eq!([0x37, 0x9e], PEC15::calc(&[0x32, 0x67, 0xF2, 0x1E, 0x5F, 0x24]));
    assert_eq!([0x98, 0x84], PEC15::calc(&[0xCD, 0x62, 0x11, 0x1F, 0x83, 0x24]));
    assert_eq!([0x1B, 0xE6], PEC15::calc(&[0xC9, 0x62, 0x7C, 0x1C, 0x1A, 0x21]));

    assert_eq!([0x89, 0xD8], PEC15::calc(&[0x1A, 0x59, 0x74, 0x50, 0x60, 0x6D]));
    assert_eq!([0x5A, 0xC4], PEC15::calc(&[0x68, 0xBF, 0x00, 0x56, 0x00, 0x2B]));
}