Implemented just enough functionality that gpredict thinks we are rotctl
This commit is contained in:
parent
6bf5b6aa1d
commit
e5e4e25438
31
src/main.rs
31
src/main.rs
|
@ -6,6 +6,8 @@ use tokio::{
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use rotctl::Command;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
async fn process_socket(socket: TcpStream) {
|
async fn process_socket(socket: TcpStream) {
|
||||||
|
@ -13,6 +15,9 @@ async fn process_socket(socket: TcpStream) {
|
||||||
|
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
|
|
||||||
|
let mut az = 0.0;
|
||||||
|
let mut el = 0.0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(n) = stream.read_line(&mut line).await {
|
if let Ok(n) = stream.read_line(&mut line).await {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
@ -22,7 +27,31 @@ async fn process_socket(socket: TcpStream) {
|
||||||
println!("> {}", line);
|
println!("> {}", line);
|
||||||
|
|
||||||
match rotctl::parse_command(&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) => {
|
Err(msg) => {
|
||||||
stream.write_all(msg.as_bytes()).await.unwrap();
|
stream.write_all(msg.as_bytes()).await.unwrap();
|
||||||
stream.flush().await.unwrap();
|
stream.flush().await.unwrap();
|
||||||
|
|
Loading…
Reference in a new issue