better pli error propagation
This commit is contained in:
parent
af67a1e678
commit
8de6c8db61
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2256,7 +2256,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tesla-charge-controller"
|
||||
version = "0.1.18"
|
||||
version = "0.1.19"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"chrono",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tesla-charge-controller"
|
||||
version = "0.1.18"
|
||||
version = "0.1.19"
|
||||
edition = "2021"
|
||||
license = "MITNFA"
|
||||
description = "Controls Tesla charge rate based on solar charge data"
|
||||
|
|
|
@ -60,6 +60,8 @@ pub enum RequestError {
|
|||
pub enum PliError {
|
||||
#[error("read error")]
|
||||
ReadError(u8),
|
||||
#[error("io error")]
|
||||
StdioErr(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
|
|
@ -206,10 +206,10 @@ impl Pli {
|
|||
.expect("failed to write to serial port");
|
||||
}
|
||||
|
||||
fn receive<const LENGTH: usize>(&mut self) -> [u8; LENGTH] {
|
||||
fn receive<const LENGTH: usize>(&mut self) -> Result<[u8; LENGTH], PliError> {
|
||||
let mut buf = [0; LENGTH];
|
||||
let _ = self.port.read_exact(&mut buf).some_or_print();
|
||||
buf
|
||||
self.port.read_exact(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn read_ram<T>(&mut self, address: T) -> Result<u8, PliError>
|
||||
|
@ -217,7 +217,7 @@ impl Pli {
|
|||
T: Into<u8>,
|
||||
{
|
||||
self.send_command(command(20, address.into(), 0));
|
||||
let buf: [u8; 2] = self.receive();
|
||||
let buf: [u8; 2] = self.receive()?;
|
||||
if buf[0] == 200 {
|
||||
Ok(buf[1])
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue