Serialport Support
- allow communication to elm327 device via a serialport - allow creation of elm327 device without requiring unwrap() - added some extra documentation - expose reset() functionality of device - serial_comm and ftdi_comm abstractions added
This commit is contained in:
parent
83ce026d23
commit
c1cea1e488
11 changed files with 194 additions and 58 deletions
|
@ -3,6 +3,18 @@
|
|||
mod elm327;
|
||||
pub use elm327::Elm327;
|
||||
|
||||
mod serial_comm;
|
||||
|
||||
#[cfg(feature = "ftdi_comm")]
|
||||
mod ftdi_comm;
|
||||
#[cfg(feature = "ftdi_comm")]
|
||||
pub use ftdi_comm::FTDIDevice;
|
||||
|
||||
#[cfg(feature = "serialport_comm")]
|
||||
mod serialport_comm;
|
||||
#[cfg(feature = "serialport_comm")]
|
||||
pub use serialport_comm::SerialPort;
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// A lower-level API for using an OBD-II device
|
||||
|
@ -51,9 +63,15 @@ pub trait Obd2Reader {
|
|||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
/// An error with the underlying [FTDI device](ftdi::Device)
|
||||
#[cfg(feature = "ftdi_comm")]
|
||||
#[error("FTDI error: `{0:?}`")]
|
||||
Ftdi(ftdi::Error),
|
||||
|
||||
/// An error with the underlying [serialport device](serialport::SerialPort)
|
||||
#[cfg(feature = "serialport_comm")]
|
||||
#[error("Serialport error: `{0:?}`")]
|
||||
Serialport(serialport::Error),
|
||||
|
||||
/// An I/O error in a low-level [std::io] stream operation
|
||||
#[error("IO error: `{0:?}`")]
|
||||
IO(std::io::Error),
|
||||
|
@ -63,12 +81,20 @@ pub enum Error {
|
|||
Communication(String),
|
||||
}
|
||||
|
||||
#[cfg(feature = "ftdi_comm")]
|
||||
impl From<ftdi::Error> for Error {
|
||||
fn from(e: ftdi::Error) -> Self {
|
||||
Error::Ftdi(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialport_comm")]
|
||||
impl From<serialport::Error> for Error {
|
||||
fn from(e: serialport::Error) -> Self {
|
||||
Error::Serialport(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Error::IO(e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue