lib-bms-protocol expose U26 error and use thiserror
This commit is contained in:
@@ -8,11 +8,12 @@ extern crate chrono;
|
||||
mod types;
|
||||
mod timestamp;
|
||||
|
||||
pub use types::{Stored_U26, Transit_U26, Transit_I26, U26Error};
|
||||
pub use timestamp::{Store_DateTimeUtc, Transit_DateTimeUtc};
|
||||
|
||||
use embedded_hal::i2c::{I2c, Operation, SevenBitAddress};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::types::Transit_U26;
|
||||
|
||||
pub const BMS_I2C_ADDRESS: u8 = 0x55;
|
||||
|
||||
pub trait BmsReadable {
|
||||
|
||||
@@ -44,15 +44,21 @@
|
||||
//! errors random errors in the transmission have a probabilty of 2**-6 = 0.015625 of matching the original messages CRC code.
|
||||
//! Meaning the chance of errors going undetected is <2%.
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
const U26_VALUE_MASK: u32 = 0xFFFFFFc0;
|
||||
const U26_MAX_VALUE: u32 = 0x03FFFFFF;
|
||||
const U26_HEMMING_MASK: u32 = 0x0000003e;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Error)]
|
||||
pub enum U26Error {
|
||||
#[error("data read from bytes has unexpected format")]
|
||||
InvalidCodeWord,
|
||||
#[error("detected an uncorrectible error, data is invalid")]
|
||||
IncorrectibleError,
|
||||
#[error("data does not fit in u26")]
|
||||
Overflow,
|
||||
#[error("checksum error")]
|
||||
ChecksumError,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user