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
charge-controller-supervisor/src
|
@ -18,6 +18,7 @@ pub struct CommonData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize, Clone)]
|
#[derive(serde::Serialize, Clone)]
|
||||||
|
#[serde(tag = "model")]
|
||||||
pub enum ControllerState {
|
pub enum ControllerState {
|
||||||
Pl(pl::PlState),
|
Pl(pl::PlState),
|
||||||
Tristar(tristar::TristarState),
|
Tristar(tristar::TristarState),
|
||||||
|
|
|
@ -52,8 +52,10 @@ pub fn rocket(state: ServerState) -> rocket::Rocket<rocket::Build> {
|
||||||
metrics,
|
metrics,
|
||||||
interfaces,
|
interfaces,
|
||||||
all_interfaces,
|
all_interfaces,
|
||||||
|
all_interfaces_full,
|
||||||
primary_interface,
|
primary_interface,
|
||||||
interface,
|
interface,
|
||||||
|
interface_full,
|
||||||
get_control,
|
get_control,
|
||||||
enable_control,
|
enable_control,
|
||||||
disable_control
|
disable_control
|
||||||
|
@ -96,6 +98,22 @@ async fn all_interfaces(
|
||||||
Json(data)
|
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>")]
|
#[get("/interface/<name>")]
|
||||||
async fn interface(
|
async fn interface(
|
||||||
name: &str,
|
name: &str,
|
||||||
|
@ -110,6 +128,20 @@ async fn interface(
|
||||||
Ok(Json(data.as_ref().ok_or(ServerError::NoData)?.common()))
|
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")]
|
#[get("/metrics")]
|
||||||
fn metrics() -> Result<String, ServerError> {
|
fn metrics() -> Result<String, ServerError> {
|
||||||
Ok(
|
Ok(
|
||||||
|
|
Loading…
Add table
Reference in a new issue