feat(backend/control-box): add a socket for the box
This commit is contained in:
parent
dfbaf2fd65
commit
11fc0388fe
1 changed files with 36 additions and 0 deletions
|
@ -9,6 +9,10 @@ use tokio::task;
|
||||||
use tokio::time::{sleep, Duration};
|
use tokio::time::{sleep, Duration};
|
||||||
use tower_http::cors::{Any, CorsLayer};
|
use tower_http::cors::{Any, CorsLayer};
|
||||||
|
|
||||||
|
use axum::extract::State;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::net::TcpListener;
|
||||||
|
|
||||||
pub fn create_router() -> Router {
|
pub fn create_router() -> Router {
|
||||||
let db = model::make_db();
|
let db = model::make_db();
|
||||||
|
|
||||||
|
@ -43,6 +47,38 @@ pub fn create_router() -> Router {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let db_listener = db.clone();
|
||||||
|
task::spawn(async move {
|
||||||
|
//TODO: parametrisation
|
||||||
|
let listener =
|
||||||
|
TcpListener::bind("10.10.10.1:1235").expect("Failed to listen for direct connection.");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match listener.accept() {
|
||||||
|
Ok((socket, _)) => {
|
||||||
|
let db_socket = db_listener.clone();
|
||||||
|
task::spawn(async move {
|
||||||
|
let mut de = serde_json::Deserializer::from_reader(socket);
|
||||||
|
loop {
|
||||||
|
match model::DMXBeamChange::deserialize(&mut de) {
|
||||||
|
Ok(data) => handler::edit_motor_value_handler(
|
||||||
|
State(db_socket.clone()),
|
||||||
|
axum::Json(data),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap_or(()),
|
||||||
|
Err(e) => tracing::debug!("Error reading incoming data: {e:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
task::spawn(async move { tracing::debug!("Failed to get client: {e:?}") })
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/api/healthcheck", get(handler::healthcheck_handler))
|
.route("/api/healthcheck", get(handler::healthcheck_handler))
|
||||||
.route(
|
.route(
|
||||||
|
|
Loading…
Reference in a new issue