diff --git a/Cargo.lock b/Cargo.lock index ce8558539bfe8b4e6c1346399472552c04562a03..d513fef8a4d5185f6594aa85c9e1381499d87e9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ dependencies = [ [[package]] name = "ham-cats" version = "0.1.0" -source = "git+https://gitlab.scd31.com/cats/ham-cats#25ed83d5eb68cd54f438f487c37f9059cd464e87" +source = "git+https://gitlab.scd31.com/cats/ham-cats#b9c0f3a6bd123262454e5e56758f8a0c0db8da89" dependencies = [ "arrayvec", "bitvec", diff --git a/src/main.rs b/src/main.rs index b5253a39764edbed9394f6d68b54212b2269c289..5b936f2b398a8da3edc9baeeeb308dcbeeb1fd78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,10 +33,10 @@ mod app { use ham_cats::{ buffer::Buffer, packet::Packet, - whisker::{Gps, Route}, + whisker::{Gps, NodeInfoBuilder, Route}, }; use stm32f4xx_hal as hal; - use systick_monotonic::{ExtU64, Systick}; + use systick_monotonic::{fugit::Instant, ExtU64, Systick}; use usb_device::prelude::*; use crate::{ @@ -54,6 +54,9 @@ mod app { const LED_BLINK_RATE: u64 = 250; + const HARDWARE_ID: u16 = 0x7c84; + const SOFTWARE_ID: u8 = 0; + const MODE: Mode = Mode { polarity: Polarity::IdleLow, phase: Phase::CaptureOnFirstTransition, @@ -70,6 +73,7 @@ mod app { flash: LockedFlash, buf: &'static mut [u8; MAX_PACKET_LEN], gps_enable: gpio::Pin<'C', 8, gpio::Output<gpio::OpenDrain>>, + bootup_time: Instant<u64, 1, { SYS_TICK_FREQ }>, } #[shared] @@ -194,6 +198,8 @@ mod app { .device_class(usbd_serial::USB_CLASS_CDC) .build(); + let bootup_time = monotonics::now(); + let shell = Shell::new(config.clone(), usb_serial); let buf = cortex_m::singleton!(: [u8; MAX_PACKET_LEN] = [0; MAX_PACKET_LEN]).unwrap(); @@ -239,6 +245,7 @@ mod app { flash, buf, gps_enable, + bootup_time, }, init::Monotonics(Systick::new(ctx.core.SYST, H_CLK)), ) @@ -258,7 +265,7 @@ mod app { } } - #[task(priority = 2, local = [buf], shared = [red, radio, gps, config, status])] + #[task(priority = 2, local = [buf, bootup_time], shared = [red, radio, gps, config, status, volt_meter])] fn transmit_position(mut ctx: transmit_position::Context) { let mut config = ctx.shared.config; let (black_hole, transmit_period_seconds) = @@ -300,6 +307,26 @@ mod app { cats.add_route(Route::new(config.max_hops)).unwrap(); }); + let voltage = ctx.shared.volt_meter.lock(|vm| vm.voltage()); + let temp = ctx + .shared + .radio + .lock(|r| r.as_mut().unwrap().get_temp().unwrap()); + let uptime_secs = (monotonics::now() - *ctx.local.bootup_time) + .to_secs() + .try_into() + .unwrap_or(0); + + let info = NodeInfoBuilder::default() + .hardware_id(HARDWARE_ID) + .software_id(SOFTWARE_ID) + .uptime(uptime_secs) + .voltage(voltage) + .xcvr_temperature(temp) + .build(); + + cats.add_node_info(info).unwrap(); + if let Some(pos) = pos { cats.add_gps(Gps::new( pos.latitude, diff --git a/src/radio.rs b/src/radio.rs index 52afe786b71053ea9d3a7a9b154d9a6fa78ac0ea..1c3812eee33dc4af53ce6f7cfae6a4da0fcdbd33 100644 --- a/src/radio.rs +++ b/src/radio.rs @@ -53,6 +53,13 @@ impl<'a> RadioManager<'a> { }) } + pub fn get_temp(&mut self) -> Option<i8> { + self.radio + .get_temp() + .ok() + .map(|x| x.clamp(i8::MIN as f32, i8::MAX as f32) as i8) + } + // call me every 20-ish ms // technically needs to be every 100ms, tops // digipeats only if ident is Some,