Initial Commit

This commit is contained in:
2025-03-30 10:58:46 -07:00
commit e59b3f3a5f
16 changed files with 547 additions and 0 deletions

View File

@@ -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 {}

19
flight/src/hal/mod.rs Normal file
View File

@@ -0,0 +1,19 @@
use anyhow::Result;
pub trait Hal {}
#[cfg(feature = "raspi")]
mod raspi;
#[cfg(feature = "raspi")]
pub fn initialize() -> Result<impl Hal> {
raspi::RaspiHal::new()
}
#[cfg(not(feature = "raspi"))]
mod emulated;
#[cfg(not(feature = "raspi"))]
pub fn initialize() -> Result<impl Hal> {
Ok(emulated::EmulatedHal::new())
}

View File

@@ -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<Self> {
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 {}

21
flight/src/lib.rs Normal file
View File

@@ -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(())
}

39
flight/src/logger.rs Normal file
View File

@@ -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(())
}

11
flight/src/main.rs Normal file
View File

@@ -0,0 +1,11 @@
use log::error;
use nautilus_flight::run;
fn main() {
match run() {
Ok(_) => {}
Err(err) => {
error!("An unhandled error occurred: {}", err);
}
}
}