Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Oct 17, 2024
1 parent 8fd65be commit d363ba4
Show file tree
Hide file tree
Showing 25 changed files with 888 additions and 777 deletions.
38 changes: 35 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ anyhow = "1"
arc-swap = "1.7"
async-trait = "0.1.81"
axum = { version = "0.7.5", features = ["ws"] }
bytes = { version = "1.7", features = ["serde"] }
byteorder = "1.5.0"
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4.5", features = ["derive"] }
Expand All @@ -32,16 +33,17 @@ include_dir = "0.7.4"
indexmap = { version = "2.5.0", features = ["serde"] }
json5 = "0.4.1"
lazy_static = "1.5.0"
# mavlink = { default-features = false, features = ["ardupilotmega", "std", "tokio-1"], path = "../rust-mavlink/mavlink" }
# mavlink = { version = "0.13.1", default-features = false, features = ["ardupilotmega", "std"] }
mavlink = { default-features = false, features = ["ardupilotmega", "serde", "std", "tokio-1"], git = "https://github.com/joaoantoniocardoso/rust-mavlink", branch = "add-tokio" }
mavlink = { default-features = false, features = ["std", "ardupilotmega", "serde", "tokio-1"], git = "https://github.com/mavlink/rust-mavlink", hash = "5f2ecbe8" }
# mavlink-codec = { path = "../mavlink-codec" }
mavlink-codec = { git = "https://github.com/bluerobotics/rust-mavlink-codec", branch = "master" }
regex = "1.10.6"
serde = { version = "1", features = ["rc"] }
serde_derive = "1.0.210"
serde_json = "1.0.128"
shellexpand = "3.1"
tokio = { version = "1", features = ["full"] }
tokio-serial = "5.4.4"
tokio-util = { version = "0.7", features = [ "codec", "net" ] }
url = { version = "2.5.2", features = ["serde"] }
uuid = { version = "1", features = ["v5", "v4", "serde"] }
mime_guess = "2.0.5"
Expand Down
18 changes: 18 additions & 0 deletions cross_build_and_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

TARGET=armv7-unknown-linux-gnueabihf
BUILDTYPE=release

cross build --$BUILDTYPE --target=$TARGET

/home/joaoantoniocardoso/BlueRobotics/cross_build_dev/old/upload_to_blueos.sh \
target/$TARGET/$BUILDTYPE/mavlink-server \
/home/pi/mavlink-server

echo ""
echo ""
echo 'clear; sshpass -p raspberry scp -o StrictHostKeyChecking=no pi@localhost:/home/pi/mavlink-server "$(which mavlink-server)" ; /home/pi/services/ardupilot_manager/main.py'
echo ""
echo ""
92 changes: 0 additions & 92 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,5 @@
use std::process::{exit, Command};

use vergen_gix::{BuildBuilder, CargoBuilder, DependencyKind, GixBuilder};

macro_rules! info {
($($tokens: tt)*) => {
println!("cargo:warning={}", format!($($tokens)*))
}
}

fn is_wasm_target_installed() -> bool {
let output = Command::new("rustup")
.args(["target", "list", "--installed"])
.output()
.expect("Failed to execute rustup");

let installed_targets = String::from_utf8_lossy(&output.stdout);
installed_targets.contains("wasm32-unknown-unknown")
}

fn install_wasm_target() {
info!("Adding wasm32-unknown-unknown target...");
let output = Command::new("rustup")
.args(["target", "add", "wasm32-unknown-unknown"])
.output()
.expect("Failed to execute rustup");

if !output.status.success() {
eprintln!("T{}", String::from_utf8_lossy(&output.stderr));
exit(1);
}
}

fn get_trunk_version() -> Option<String> {
Command::new("trunk")
.arg("--version")
.output()
.ok()
.and_then(|output| String::from_utf8(output.stdout).ok())
.and_then(|version_string| version_string.split_whitespace().last().map(String::from))
}

fn install_trunk() -> Result<(), Box<dyn std::error::Error>> {
info!("Installing trunk...");

let output = Command::new("cargo")
.arg("install")
.arg("trunk")
.arg("--force")
.output()?;

if !output.status.success() {
eprintln!("TT{}", String::from_utf8_lossy(&output.stderr));
exit(1);
}

Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=./src/webpage/");

Expand All @@ -68,40 +11,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)?
.emit()?;

if std::env::var("SKIP_FRONTEND").is_ok() {
return Ok(());
}

if !is_wasm_target_installed() {
install_wasm_target();
}

if get_trunk_version().is_none() {
info!("trunk not found");
install_trunk().unwrap_or_else(|e| {
eprintln!("Error: {}", e);
exit(1);
});
}

let mut trunk_command = Command::new("trunk");
trunk_command.args(["build", "./src/webpage/index.html"]);

// Add --release argument if not in debug mode
if cfg!(not(debug_assertions)) {
trunk_command.args(["--release", "--locked"]);
}

let trunk_output = trunk_command.output().expect("Failed to execute trunk");

if !trunk_output.status.success() {
eprintln!(
"Trunk build failed: {}",
String::from_utf8_lossy(&trunk_output.stderr)
);
exit(1);
}
info!("{}", String::from_utf8_lossy(&trunk_output.stdout));

Ok(())
}
6 changes: 6 additions & 0 deletions src/lib/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ pub struct Callbacks<T> {
callbacks: Arc<Mutex<IndexMap<usize, Callback<T>>>>,
}

impl<T> std::fmt::Debug for Callbacks<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Callbacks").finish()
}
}

impl<T> Callbacks<T> {
pub fn new() -> Self {
Self {
Expand Down
12 changes: 9 additions & 3 deletions src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing::*;

use crate::drivers;

#[derive(Parser)]
#[derive(Debug, Parser)]
#[command(
version = env!("CARGO_PKG_VERSION"),
author = env!("CARGO_PKG_AUTHORS"),
Expand Down Expand Up @@ -83,7 +83,7 @@ fn build_endpoints_help() -> String {
.collect::<Vec<String>>()
.join("\n\t\t ");

vec![
[
format!("{name}\t {help_schemas}").to_string(),
format!("\t legacy: {help_legacy}").to_string(),
format!("\t url: {help_url}\n").to_string(),
Expand Down Expand Up @@ -154,14 +154,20 @@ pub fn endpoints() -> Vec<Arc<dyn drivers::Driver>> {
let default_endpoints = Arc::new(crate::drivers::rest::Rest::builder("Default").build());
let mut endpoints = MANAGER.clap_matches.endpoints.clone();
endpoints.push(default_endpoints);
return endpoints;
endpoints
}

#[instrument(level = "debug")]
pub fn command_line_string() -> String {
std::env::args().collect::<Vec<String>>().join(" ")
}

// Return a clone of current Args struct
#[instrument(level = "debug")]
pub fn command_line() -> String {
format!("{:#?}", MANAGER.clap_matches)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit d363ba4

Please sign in to comment.