mirror of
https://github.com/italicsjenga/fh5-telemetry-watcher.git
synced 2025-01-10 22:31:32 +11:00
dual server baybee
This commit is contained in:
parent
f47b37ac92
commit
2dee00761b
1347
Cargo.lock
generated
1347
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -11,4 +11,5 @@ serde = { version = "1.0", features = ["derive"] }
|
|||
bincode = "1.3"
|
||||
csv = "1.1"
|
||||
chrono = "0.4"
|
||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||
fh5-common = { path = "fh5-common", version="0.1" }
|
48
src/main.rs
48
src/main.rs
|
@ -1,17 +1,19 @@
|
|||
use fh5_common::{Filename, Telemetry};
|
||||
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
use bincode;
|
||||
use chrono::Local;
|
||||
use clap::Parser;
|
||||
use rocket::State;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::net::UdpSocket;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{fs, net};
|
||||
|
||||
use bincode;
|
||||
use chrono::Local;
|
||||
use clap::Parser;
|
||||
|
||||
macro_rules! verbose_print {
|
||||
($args:expr, $($tts:tt)*) => {
|
||||
if($args.verbose) {
|
||||
|
@ -55,9 +57,24 @@ fn listen(socket: &net::UdpSocket, mut buffer: &mut [u8]) -> usize {
|
|||
number_of_bytes
|
||||
}
|
||||
|
||||
fn main() {
|
||||
struct DataStruct {
|
||||
data: Arc<Mutex<[f32; 3]>>,
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() {
|
||||
let args = Args::parse();
|
||||
let ip = format!("0.0.0.0:{}", args.port.to_string());
|
||||
|
||||
let data = Arc::new(Mutex::new([0. as f32, 0. as f32, 0. as f32]));
|
||||
let data_for_thread = data.clone();
|
||||
|
||||
let _listener = std::thread::spawn(move || {
|
||||
let mut data = data_for_thread.lock().unwrap();
|
||||
data[0] = 1.;
|
||||
data[1] = 2.;
|
||||
data[2] = 3.;
|
||||
drop(data);
|
||||
verbose_print!(
|
||||
args,
|
||||
"{}: Starting server",
|
||||
|
@ -80,6 +97,7 @@ fn main() {
|
|||
next: None,
|
||||
position: 0,
|
||||
};
|
||||
|
||||
'listener: while listen(&socket, &mut buf) != 0 {
|
||||
let deserialised: Telemetry = bincode::deserialize(&buf).expect("error parsing packet");
|
||||
if deserialised.is_race_on == 0 {
|
||||
|
@ -90,6 +108,12 @@ fn main() {
|
|||
status.position = deserialised.race_position;
|
||||
verbose_print!(args, "now position {}", status.position);
|
||||
}
|
||||
let mut data = data_for_thread.lock().unwrap();
|
||||
data[0] = deserialised.position_x;
|
||||
data[1] = deserialised.position_y;
|
||||
data[2] = deserialised.position_z;
|
||||
drop(data);
|
||||
|
||||
// status.next.
|
||||
if deserialised.race_position == 0 {
|
||||
status.next.take().and_then(|next| -> Option<NextFile> {
|
||||
|
@ -121,6 +145,18 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
let _result = rocket::custom(rocket::Config::figment().merge(("port", 1111)))
|
||||
.mount("/", routes![index])
|
||||
.manage(DataStruct { data })
|
||||
.launch()
|
||||
.await;
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index(data: &State<DataStruct>) -> String {
|
||||
let get = data.data.lock().unwrap();
|
||||
format!("x: {}, y: {}, z: {}", get[0], get[1], get[2])
|
||||
}
|
||||
|
||||
fn begin_race(deserialised: &Telemetry) -> NextFile {
|
||||
|
|
Loading…
Reference in a new issue