-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple tool for TCP loopback testing
Monitor your board's serial log for the IP address it's assigned. Then, pass it into this command-line tool to make sure you can connect, send a message, and receive the response.
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ eh02-unproven = [] | |
members = [ | ||
"board", | ||
"logging", | ||
"tools", | ||
] | ||
|
||
[workspace.dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "tools" | ||
version = "0.1.0" | ||
repository.workspace = true | ||
keywords.workspace = true | ||
categories.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
publish = false | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::io::prelude::*; | ||
use std::net::TcpStream; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let ip = std::env::args() | ||
.skip(1) | ||
.next() | ||
.ok_or("Provide an IPv4 address")?; | ||
|
||
let ip: std::net::Ipv4Addr = ip.parse()?; | ||
|
||
let mut client = TcpStream::connect(std::net::SocketAddrV4::new(ip, 5000))?; | ||
|
||
const MSG: &[u8] = b"Hello, world!"; | ||
client.write(MSG)?; | ||
let mut resp = [0; MSG.len()]; | ||
client.read(&mut resp)?; | ||
|
||
if resp == MSG { | ||
Ok(()) | ||
} else { | ||
Err(format!("Expected '{MSG:?}' but received '{resp:?}'").into()) | ||
} | ||
} |