pub struct TcpClientHandshake { /* private fields */ }
Expand description
Handles the client-side of the VBus-over-TCP handshake.
§Examples
use async_std::net::{SocketAddr, TcpStream};
use async_resol_vbus::TcpClientHandshake;
let address = "192.168.5.217:7053".parse::<SocketAddr>()?;
let stream = TcpStream::connect(address).await?;
let mut hs = TcpClientHandshake::start(stream).await?;
hs.send_pass_command("vbus").await?;
let stream = hs.send_data_command().await?;
// ...
Implementations§
Source§impl TcpClientHandshake
impl TcpClientHandshake
Sourcepub async fn start(stream: TcpStream) -> Result<TcpClientHandshake>
pub async fn start(stream: TcpStream) -> Result<TcpClientHandshake>
Start the handshake by waiting for the initial greeting reply from the service.
Examples found in repository?
examples/live_data_recorder.rs (line 20)
9fn main() -> Result<()> {
10 async_std::task::block_on(async {
11 // Create an recording file and hand it to a `RecordingWriter`
12 let file = File::create("test.vbus")?;
13 let mut rw = RecordingWriter::new(file);
14
15 // Parse the address of the DL2 to connect to
16 let addr = "192.168.5.217:7053".parse::<SocketAddr>()?;
17
18 let stream = TcpStream::connect(addr).await?;
19
20 let mut hs = TcpClientHandshake::start(stream).await?;
21 hs.send_pass_command("vbus").await?;
22 let stream = hs.send_data_command().await?;
23
24 let (reader, writer) = (&stream, &stream);
25
26 let mut stream = LiveDataStream::new(reader, writer, 0, 0x0020);
27
28 while let Some(data) = stream.receive_any_data(60000).await? {
29 println!("{}", data.id_string());
30
31 // Add `Data` value into `DataSet` to be stored
32 let mut data_set = DataSet::new();
33 data_set.timestamp = data.as_ref().timestamp;
34 data_set.add_data(data);
35
36 // Write the `DataSet` into the `RecordingWriter` for permanent storage
37 rw.write_data_set(&data_set)
38 .expect("Unable to write data set");
39 }
40
41 Ok(())
42 })
43}
Sourcepub fn into_inner(self) -> TcpStream
pub fn into_inner(self) -> TcpStream
Consume self
and return the underlying TcpStream
.
Sourcepub async fn send_connect_command(&mut self, via_tag: &str) -> Result<()>
pub async fn send_connect_command(&mut self, via_tag: &str) -> Result<()>
Send the CONNECT
command and wait for the reply.
Sourcepub async fn send_pass_command(&mut self, password: &str) -> Result<()>
pub async fn send_pass_command(&mut self, password: &str) -> Result<()>
Send the PASS
command and wait for the reply.
Examples found in repository?
examples/live_data_recorder.rs (line 21)
9fn main() -> Result<()> {
10 async_std::task::block_on(async {
11 // Create an recording file and hand it to a `RecordingWriter`
12 let file = File::create("test.vbus")?;
13 let mut rw = RecordingWriter::new(file);
14
15 // Parse the address of the DL2 to connect to
16 let addr = "192.168.5.217:7053".parse::<SocketAddr>()?;
17
18 let stream = TcpStream::connect(addr).await?;
19
20 let mut hs = TcpClientHandshake::start(stream).await?;
21 hs.send_pass_command("vbus").await?;
22 let stream = hs.send_data_command().await?;
23
24 let (reader, writer) = (&stream, &stream);
25
26 let mut stream = LiveDataStream::new(reader, writer, 0, 0x0020);
27
28 while let Some(data) = stream.receive_any_data(60000).await? {
29 println!("{}", data.id_string());
30
31 // Add `Data` value into `DataSet` to be stored
32 let mut data_set = DataSet::new();
33 data_set.timestamp = data.as_ref().timestamp;
34 data_set.add_data(data);
35
36 // Write the `DataSet` into the `RecordingWriter` for permanent storage
37 rw.write_data_set(&data_set)
38 .expect("Unable to write data set");
39 }
40
41 Ok(())
42 })
43}
Sourcepub async fn send_channel_command(&mut self, channel: u8) -> Result<()>
pub async fn send_channel_command(&mut self, channel: u8) -> Result<()>
Send the CHANNEL
command and wait for the reply.
Sourcepub async fn send_data_command(self) -> Result<TcpStream>
pub async fn send_data_command(self) -> Result<TcpStream>
Send the DATA
command and wait for the reply.
This function returns the underlying TcpStream
since the handshake is complete
after sending this command.
Examples found in repository?
examples/live_data_recorder.rs (line 22)
9fn main() -> Result<()> {
10 async_std::task::block_on(async {
11 // Create an recording file and hand it to a `RecordingWriter`
12 let file = File::create("test.vbus")?;
13 let mut rw = RecordingWriter::new(file);
14
15 // Parse the address of the DL2 to connect to
16 let addr = "192.168.5.217:7053".parse::<SocketAddr>()?;
17
18 let stream = TcpStream::connect(addr).await?;
19
20 let mut hs = TcpClientHandshake::start(stream).await?;
21 hs.send_pass_command("vbus").await?;
22 let stream = hs.send_data_command().await?;
23
24 let (reader, writer) = (&stream, &stream);
25
26 let mut stream = LiveDataStream::new(reader, writer, 0, 0x0020);
27
28 while let Some(data) = stream.receive_any_data(60000).await? {
29 println!("{}", data.id_string());
30
31 // Add `Data` value into `DataSet` to be stored
32 let mut data_set = DataSet::new();
33 data_set.timestamp = data.as_ref().timestamp;
34 data_set.add_data(data);
35
36 // Write the `DataSet` into the `RecordingWriter` for permanent storage
37 rw.write_data_set(&data_set)
38 .expect("Unable to write data set");
39 }
40
41 Ok(())
42 })
43}
Sourcepub async fn send_quit_command(self) -> Result<()>
pub async fn send_quit_command(self) -> Result<()>
Send the QUIT
command and wait for the reply.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TcpClientHandshake
impl RefUnwindSafe for TcpClientHandshake
impl Send for TcpClientHandshake
impl Sync for TcpClientHandshake
impl Unpin for TcpClientHandshake
impl UnwindSafe for TcpClientHandshake
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more