commit e59b3f3a5f4995fa26dc00062712b8b6e9d1fdaa Author: Sergey Savelyev Date: Sun Mar 30 10:58:46 2025 -0700 Initial Commit diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..d4d977a --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-unknown-linux-gnu-gcc" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..604ef9f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +.idea/ +/target +/logs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..beba15e --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,353 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + +[[package]] +name = "cc" +version = "1.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "fern" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4316185f709b23713e41e3195f90edef7fb00c3ed4adc79769cf09cc762a3b29" +dependencies = [ + "log", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2fd658b06e56721792c5df4475705b6cda790e9298d19d2f8af083457bcd127" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "nautilus_common" +version = "0.1.0" + +[[package]] +name = "nautilus_flight" +version = "0.1.0" +dependencies = [ + "anyhow", + "chrono", + "fern", + "log", + "rppal", +] + +[[package]] +name = "nautilus_ground" +version = "0.1.0" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "proc-macro2" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rppal" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ce3b019009cff02cb6b0e96e7cc2e5c5b90187dc1a490f8ef1521d0596b026" +dependencies = [ + "libc", +] + +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..79e1465 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "3" +members = ["common", "flight", "ground"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..b8f7bcf --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Project Nautilus + +## Prerequisites + +1. Install `aarch64-unknown-linux-gnu` linker + 1. macOS: https://github.com/messense/homebrew-macos-cross-toolchains + +## Build Ground + +`cargo build --bin nautilus-ground` + +## Build Flight + +`cargo build --target aarch64-unknown-linux-gnu --bin nautilus-flight --features raspi` + diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..cf3c706 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "nautilus_common" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/flight/Cargo.toml b/flight/Cargo.toml new file mode 100644 index 0000000..7e85610 --- /dev/null +++ b/flight/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "nautilus_flight" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1.0.97" +fern = "0.7.1" +log = "0.4.27" +rppal = { version = "0.22.1", optional = true } +chrono = "0.4.40" + +[features] +raspi = ["dep:rppal"] diff --git a/flight/src/hal/emulated/mod.rs b/flight/src/hal/emulated/mod.rs new file mode 100644 index 0000000..2d01a69 --- /dev/null +++ b/flight/src/hal/emulated/mod.rs @@ -0,0 +1,14 @@ +use crate::hal::Hal; +use log::info; + +pub struct EmulatedHal {} + +impl EmulatedHal { + pub fn new() -> Self { + info!("Running in Emulated Hardware Mode"); + + Self {} + } +} + +impl Hal for EmulatedHal {} diff --git a/flight/src/hal/mod.rs b/flight/src/hal/mod.rs new file mode 100644 index 0000000..e7debb8 --- /dev/null +++ b/flight/src/hal/mod.rs @@ -0,0 +1,19 @@ +use anyhow::Result; + +pub trait Hal {} + +#[cfg(feature = "raspi")] +mod raspi; + +#[cfg(feature = "raspi")] +pub fn initialize() -> Result { + raspi::RaspiHal::new() +} + +#[cfg(not(feature = "raspi"))] +mod emulated; + +#[cfg(not(feature = "raspi"))] +pub fn initialize() -> Result { + Ok(emulated::EmulatedHal::new()) +} diff --git a/flight/src/hal/raspi/mod.rs b/flight/src/hal/raspi/mod.rs new file mode 100644 index 0000000..9c0d947 --- /dev/null +++ b/flight/src/hal/raspi/mod.rs @@ -0,0 +1,23 @@ +use crate::hal::Hal; +use anyhow::Result; +use log::info; +use rppal::gpio::Gpio; + +pub struct RaspiHal { + gpio: Gpio, +} + +impl RaspiHal { + pub fn new() -> Result { + let device = rppal::system::DeviceInfo::new()?; + info!( + "Running on Raspberry Pi Emulated Hardware Model {} with {}", + device.model(), + device.soc() + ); + + Self { gpio: Gpio::new()? } + } +} + +impl Hal for RaspiHal {} diff --git a/flight/src/lib.rs b/flight/src/lib.rs new file mode 100644 index 0000000..49628be --- /dev/null +++ b/flight/src/lib.rs @@ -0,0 +1,21 @@ +use crate::hal::initialize; +use crate::logger::setup_logger; +use anyhow::Result; +use log::info; + +mod hal; +mod logger; + +pub fn run() -> Result<()> { + setup_logger()?; + info!( + "Project Nautilus Flight Software {}", + env!("CARGO_PKG_VERSION") + ); + + let hal = initialize()?; + + drop(hal); + + Ok(()) +} diff --git a/flight/src/logger.rs b/flight/src/logger.rs new file mode 100644 index 0000000..1f38960 --- /dev/null +++ b/flight/src/logger.rs @@ -0,0 +1,39 @@ +use anyhow::Result; +use std::env; +use std::fs::create_dir_all; +use std::str::FromStr; + +pub fn setup_logger() -> Result<()> { + let log_file = env::var("LOG_FILE").or_else(|_| { + create_dir_all("logs/")?; + + anyhow::Ok(format!( + "logs/{}_{}.log", + env!("CARGO_PKG_NAME"), + chrono::Local::now().format("%Y%m%d_%H%M%S") + )) + })?; + let log_level = match env::var("LOG_LEVEL") { + Ok(log_level) => log::LevelFilter::from_str(&log_level).unwrap_or(log::LevelFilter::Info), + Err(_) => log::LevelFilter::Info, + }; + + fern::Dispatch::new() + .format(|out, message, record| { + out.finish(format_args!( + "[{}][{}][{}] {}", + chrono::Local::now().format("%Y-%m-%d %H:%M:%S"), + record.target(), + record.level(), + message + )) + }) + .chain( + fern::Dispatch::new() + .level(log_level) + .chain(std::io::stdout()), + ) + .chain(fern::log_file(log_file)?) + .apply()?; + Ok(()) +} diff --git a/flight/src/main.rs b/flight/src/main.rs new file mode 100644 index 0000000..093d893 --- /dev/null +++ b/flight/src/main.rs @@ -0,0 +1,11 @@ +use log::error; +use nautilus_flight::run; + +fn main() { + match run() { + Ok(_) => {} + Err(err) => { + error!("An unhandled error occurred: {}", err); + } + } +} diff --git a/ground/Cargo.toml b/ground/Cargo.toml new file mode 100644 index 0000000..f6f0ae0 --- /dev/null +++ b/ground/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "nautilus_ground" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/ground/src/main.rs b/ground/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/ground/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}