Skip to content

Commit

Permalink
Sloppy fix for REV
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLostLambda committed Dec 12, 2019
1 parent c0e82a4 commit 0f9e6be
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ linker = "/usr/bin/x86_64-w64-mingw32-gcc"
ar = "/usr/x86_64-w64-mingw32/bin/ar"

[target.x86_64-apple-darwin]
linker = "/opt/osxcross/bin/x86_64-apple-darwin15-clang"
ar = "/opt/osxcross/bin/x86_64-apple-darwin15-ar"
linker = "/opt/osxcross/bin/x86_64-apple-darwin17-clang"
ar = "/opt/osxcross/bin/x86_64-apple-darwin17-ar"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ftc_http"
version = "1.3.0"
version = "1.4.0"
authors = ["Brooks J Rady <[email protected]>"]
edition = "2015"

Expand Down
71 changes: 39 additions & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::process;
use uuid::Uuid;
use std::fs;

static HOST: &'static str = "http://192.168.49.1:8080";
const HOSTS: [&'static str; 2] = ["http://192.168.49.1:8080", "http://192.168.43.1:8080"];
const TIMEOUT: u64 = 3;

pub fn up(src: &std::path::Path) -> Result<(), Error> {
conn_test()?;
let host = conn_test()?;

let mut core = Core::new()?;
let robot_controller = Client::new(&core.handle());
Expand All @@ -47,7 +47,7 @@ pub fn up(src: &std::path::Path) -> Result<(), Error> {

let mut upload_request = Request::new(
Method::Post,
(HOST.to_string() + "/java/file/upload").parse()?,
(host.to_string() + "/java/file/upload").parse()?,
);

let body = format!(
Expand Down Expand Up @@ -80,13 +80,13 @@ pub fn up(src: &std::path::Path) -> Result<(), Error> {
}

pub fn down(dest: &std::path::Path) -> Result<(), hyper::Error> {
conn_test()?;
let host = conn_test()?;

let mut core = Core::new()?;
let robot_controller = Client::new(&core.handle());

let tree_request = robot_controller
.get((HOST.to_string() + "/java/file/tree").parse()?)
.get((host.to_string() + "/java/file/tree").parse()?)
.and_then(|res| {
res.body()
.concat2()
Expand All @@ -107,7 +107,7 @@ pub fn down(dest: &std::path::Path) -> Result<(), hyper::Error> {
let mut file_handle = fs::File::create(&filepath)?;

let download_request = robot_controller
.get((HOST.to_string() + "/java/file/download?f=/src" + file).parse()?)
.get((host.to_string() + "/java/file/download?f=/src" + file).parse()?)
.and_then(|res| {
res.body()
.for_each(|chunk| file_handle.write_all(&chunk).map_err(From::from))
Expand All @@ -122,14 +122,14 @@ pub fn down(dest: &std::path::Path) -> Result<(), hyper::Error> {
}

pub fn build() -> Result<(), Error> {
conn_test()?;
let host = conn_test()?;

let mut core = Core::new()?;
let robot_controller = Client::new(&core.handle());

let tree_request = robot_controller.get((HOST.to_string() + "/java/file/tree").parse()?);
let tree_request = robot_controller.get((host.to_string() + "/java/file/tree").parse()?);

let build_request = robot_controller.get((HOST.to_string() + "/java/build/start").parse()?);
let build_request = robot_controller.get((host.to_string() + "/java/build/start").parse()?);

core.run(tree_request.join(build_request))?;

Expand All @@ -140,7 +140,7 @@ pub fn build() -> Result<(), Error> {

loop {
let status_request = robot_controller
.get((HOST.to_string() + "/java/build/status").parse()?)
.get((host.to_string() + "/java/build/status").parse()?)
.and_then(|res| {
res.body()
.concat2()
Expand All @@ -163,7 +163,7 @@ pub fn build() -> Result<(), Error> {
println!("BUILD FAILED");

let error_request = robot_controller
.get((HOST.to_string() + "/java/build/wait").parse()?)
.get((host.to_string() + "/java/build/wait").parse()?)
.and_then(|res| {
res.body()
.for_each(|chunk| std::io::stdout().write_all(&chunk).map_err(From::from))
Expand All @@ -176,7 +176,7 @@ pub fn build() -> Result<(), Error> {
}

pub fn wipe() -> Result<(), Error> {
conn_test()?;
let host = conn_test()?;

let mut core = Core::new()?;
let robot_controller = Client::new(&core.handle());
Expand All @@ -186,7 +186,7 @@ pub fn wipe() -> Result<(), Error> {

let mut wipe_request = Request::new(
Method::Post,
(HOST.to_string() + "/java/file/delete").parse()?,
(host.to_string() + "/java/file/delete").parse()?,
);

let body = "delete=[\"src\"]";
Expand All @@ -208,28 +208,35 @@ pub fn wipe() -> Result<(), Error> {
Ok(())
}

fn conn_test() -> Result<(), Error> {
fn conn_test() -> Result<&'static str, Error> {
let mut core = Core::new()?;
let robot_controller = Client::new(&core.handle());

let timeout = Timeout::new(Duration::from_secs(TIMEOUT), &core.handle())?;

let conn_request = robot_controller
.get(HOST.parse()?)
.select2(timeout)
.map(|res| match res {
Either::B(_) => {
println!(
"Failed to reach the robot controller. Please check that your robot controller\n\
is in \"Program & Manage\" mode and that your computer is connected to the\n\
robot controller via wifi-direct."
);
process::exit(1)
}
_ => (),
});
for host in &HOSTS {
let timeout = Timeout::new(Duration::from_secs(TIMEOUT), &core.handle())?;
let mut fail = false;
let conn_request = robot_controller
.get(host.parse()?)
.select2(timeout)
.map(|res| match res {
Either::B(_) => fail = true,
_ => (),
});

core.run(conn_request).unwrap_or_default();

if fail {
continue;
} else {
return Ok(host)
}
}

core.run(conn_request).unwrap_or_default();
println!(
"Failed to reach the robot controller. Please check that your robot controller\n\
is in \"Program & Manage\" mode and that your computer is connected to the\n\
robot controller via wifi-direct."
);

Ok(())
process::exit(0);
}
20 changes: 7 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate ftc_http;
use std::process;
use std::env;

static VERISON_STR: &'static str = "v1.3.0";
static VERISON_STR: &'static str = "v1.4.0";
static STARTUP_OPTS: &'static str = "hv";

fn main() {
Expand All @@ -29,33 +29,27 @@ fn main() {
'd' => {
let next_arg = args.next().unwrap_or(String::new());
ftc_http::down(&pwd.join(&next_arg)).unwrap_or_else(|_| {
println!("Failed to download files from the robot controller");
eprintln!("Failed to download files from the robot controller");
process::exit(0);
});
}
'u' => {
let next_arg = args.next().unwrap_or(String::new());
ftc_http::up(&pwd.join(&next_arg)).unwrap_or_else(|_| {
println!("Failed to upload files to the robot controller");
eprintln!("Failed to upload files to the robot controller");
process::exit(0);
});
}
'b' => ftc_http::build().unwrap_or_else(|_| {
println!("Failed to start build on the robot controller");
eprintln!("Failed to start build on the robot controller");
process::exit(0);
}),
'w' => ftc_http::wipe().unwrap_or_else(|_| {
println!("Failed to wipe files on the robot controller");
eprintln!("Failed to wipe files on the robot controller");
process::exit(0);
}),
'v' => {
version();
process::exit(0);
}
_ => {
help();
process::exit(0);
}
'v' => version(),
_ => help(),
};
}
}
Expand Down

0 comments on commit 0f9e6be

Please sign in to comment.