diff --git a/candid_client/src/candid_connection.rs b/candid_client/src/candid_connection.rs index 453fd4b..5de593d 100644 --- a/candid_client/src/candid_connection.rs +++ b/candid_client/src/candid_connection.rs @@ -6,14 +6,14 @@ use std::net::{TcpStream, ToSocketAddrs}; use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt}; +/// A connection to a CANdid server. Simply contains a `TcpStream` wrapped by a +/// `BufReader`. Handles the communication with a server by reading one can +/// frame at a time from a TCP stream. pub struct CandidConnection { read_stream: BufReader, write_stream: BufWriter, } -/// A connection to a CANdid server. Simply contains a `TcpStream` wrapped by a -/// `BufReader`. Handles the communication with a server by reading one can -/// frame at a time from a TCP stream. impl CandidConnection { /// Creates a new CandidConnection with a server designated at `addr` pub fn new(addr: A) -> Result { @@ -35,6 +35,7 @@ impl CandidConnection { Ok(Frame::new(id, data)) } + /// Sends a frame to the server pub fn write_frame(&mut self, frame: Frame) -> Result<(), std::io::Error> { self.write_stream.write_u32::(frame.id)?; self.write_stream.write(&frame.data)?; @@ -53,9 +54,4 @@ impl CandidConnection { pub fn into_buffer(self) -> BufReader { self.read_stream } - - /// Returns an iterator over the raw lines form the underlying `TcpStream`. - pub fn lines(self) -> Lines> { - self.read_stream.lines() - } } diff --git a/candid_client/src/frame.rs b/candid_client/src/frame.rs index ca5c6bf..a4ecdb5 100644 --- a/candid_client/src/frame.rs +++ b/candid_client/src/frame.rs @@ -1,3 +1,4 @@ +/// Represents a basic CAN Frame containing the frame's id and data #[derive(Debug)] pub struct Frame { pub id: u32, @@ -5,9 +6,8 @@ pub struct Frame { } impl Frame { - // TODO: Implement more frame functionality from `socketcan-rs` + /// Creates a new frame with the given id and data pub fn new(id: u32, data: [u8; 8]) -> Frame { - // TODO: Error checking, etc Frame { id, data } } }