ccs: get full controller state via web
This commit is contained in:
parent
0b53d347dc
commit
88144693a8
2 changed files with 33 additions and 0 deletions
|
@ -18,6 +18,7 @@ pub struct CommonData {
|
|||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
#[serde(tag = "model")]
|
||||
pub enum ControllerState {
|
||||
Pl(pl::PlState),
|
||||
Tristar(tristar::TristarState),
|
||||
|
|
|
@ -52,8 +52,10 @@ pub fn rocket(state: ServerState) -> rocket::Rocket<rocket::Build> {
|
|||
metrics,
|
||||
interfaces,
|
||||
all_interfaces,
|
||||
all_interfaces_full,
|
||||
primary_interface,
|
||||
interface,
|
||||
interface_full,
|
||||
get_control,
|
||||
enable_control,
|
||||
disable_control
|
||||
|
@ -96,6 +98,22 @@ async fn all_interfaces(
|
|||
Json(data)
|
||||
}
|
||||
|
||||
#[get("/interfaces/data/full")]
|
||||
async fn all_interfaces_full(
|
||||
state: &State<ServerState>,
|
||||
) -> Json<Vec<(String, crate::controller::ControllerState)>> {
|
||||
let mut data = Vec::new();
|
||||
|
||||
for (k, v) in &state.map {
|
||||
let v = v.read().await;
|
||||
if let Some(v) = v.as_ref() {
|
||||
data.push((k.clone(), v.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
Json(data)
|
||||
}
|
||||
|
||||
#[get("/interface/<name>")]
|
||||
async fn interface(
|
||||
name: &str,
|
||||
|
@ -110,6 +128,20 @@ async fn interface(
|
|||
Ok(Json(data.as_ref().ok_or(ServerError::NoData)?.common()))
|
||||
}
|
||||
|
||||
#[get("/interface/<name>/full")]
|
||||
async fn interface_full(
|
||||
name: &str,
|
||||
state: &State<ServerState>,
|
||||
) -> Result<Json<crate::controller::ControllerState>, ServerError> {
|
||||
let data = state
|
||||
.map
|
||||
.get(name)
|
||||
.ok_or(ServerError::NotFound)?
|
||||
.read()
|
||||
.await;
|
||||
Ok(Json(data.as_ref().ok_or(ServerError::NoData)?.clone()))
|
||||
}
|
||||
|
||||
#[get("/metrics")]
|
||||
fn metrics() -> Result<String, ServerError> {
|
||||
Ok(
|
||||
|
|
Loading…
Add table
Reference in a new issue