diff --git a/src/main.rs b/src/main.rs index 26cd515..1947a3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ use tokio::{ net::{TcpListener, TcpStream}, }; +use rotctl::Command; + use std::io; async fn process_socket(socket: TcpStream) { @@ -13,6 +15,9 @@ async fn process_socket(socket: TcpStream) { let mut line = String::new(); + let mut az = 0.0; + let mut el = 0.0; + loop { if let Ok(n) = stream.read_line(&mut line).await { if n == 0 { @@ -22,7 +27,31 @@ async fn process_socket(socket: TcpStream) { println!("> {}", line); match rotctl::parse_command(&line) { - Ok(cmd) => println!("Commmand: {:?}", cmd), + Ok(cmd) => match cmd { + Command::GetPos => { + stream + .write_all(format!("{}\n{}\n", az, el).as_bytes()) + .await + .unwrap(); + stream.flush().await.unwrap(); + } + Command::SetPos(new_az, new_el) => { + az = new_az; + el = new_el; + stream.write_all("RPRT 0\n".as_bytes()).await.unwrap(); + stream.flush().await.unwrap(); + } + Command::Stop => { + stream.write_all("RPRT 0\n".as_bytes()).await.unwrap(); + stream.flush().await.unwrap(); + } + Command::Exit => { + stream.write_all("RPRT 0\n".as_bytes()).await.unwrap(); + stream.flush().await.unwrap(); + return; + } + _ => {} + }, Err(msg) => { stream.write_all(msg.as_bytes()).await.unwrap(); stream.flush().await.unwrap();