Skip to content

Commit

Permalink
web: Add message_id_from_name
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric authored and joaoantoniocardoso committed Oct 27, 2024
1 parent 2b289e0 commit ee3458a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/web/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ pub async fn mavlink(path: Option<Path<String>>) -> impl IntoResponse {
crate::drivers::rest::data::messages(&path)
}

pub async fn message_id_from_name(name: Path<String>) -> impl IntoResponse {
use mavlink::{self, Message};
mavlink::ardupilotmega::MavMessage::message_id_from_name(&name.0.to_ascii_uppercase())
.map(|id| (StatusCode::OK, Json(id)).into_response())
.unwrap_or_else(|_| (StatusCode::NOT_FOUND, "404 Not Found").into_response())
}

pub async fn driver_stats() -> impl IntoResponse {
Json(stats::drivers_stats().await.unwrap())
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ fn default_router(state: AppState) -> Router {
.route("/rest/mavlink", get(endpoints::mavlink))
.route("/rest/mavlink/", get(endpoints::mavlink))
.route("/rest/mavlink/*path", get(endpoints::mavlink))
.route(
"/rest/mavlink/message_id_from_name/*name",
get(endpoints::message_id_from_name),
)
.fallback(get(|| async { (StatusCode::NOT_FOUND, "Not found :(") }))
.with_state(state)
}
Expand Down

0 comments on commit ee3458a

Please sign in to comment.