Skip to content

Commit

Permalink
web: Add mavlink post endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Oct 29, 2024
1 parent ee3458a commit 812c6b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/lib/web/endpoints.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use axum::{
extract::Path,
extract::{Path, State},
http::{header, StatusCode},
response::IntoResponse,
Json,
};
use include_dir::{include_dir, Dir};
use mime_guess::from_path;
use serde::Serialize;
use tracing::*;

use crate::stats;
use crate::web::AppState;

static HTML_DIST: Dir = include_dir!("src/webpage/dist");

Expand Down Expand Up @@ -81,6 +83,12 @@ pub async fn mavlink(path: Option<Path<String>>) -> impl IntoResponse {
crate::drivers::rest::data::messages(&path)
}

pub async fn post_mavlink(State(state): State<AppState>, message: String) {
if let Err(error) = state.message_tx.send(message) {
error!("Failed to send message to main loop: {error:?}");
}
}

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())
Expand Down
3 changes: 2 additions & 1 deletion src/lib/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use axum::{
},
http::StatusCode,
response::Response,
routing::get,
routing::{get, post},
Router,
};
use futures::{sink::SinkExt, stream::StreamExt};
Expand Down Expand Up @@ -40,6 +40,7 @@ fn default_router(state: AppState) -> Router {
.route("/rest/ws", get(websocket_handler))
// We are matching all possible keys for the user
.route("/rest/mavlink", get(endpoints::mavlink))
.route("/rest/mavlink", post(endpoints::post_mavlink))
.route("/rest/mavlink/", get(endpoints::mavlink))
.route("/rest/mavlink/*path", get(endpoints::mavlink))
.route(
Expand Down

0 comments on commit 812c6b0

Please sign in to comment.