From 014d7906180825d57e420f26da223dde74ea37e1 Mon Sep 17 00:00:00 2001 From: Stephen D <webmaster@scd31.com> Date: Sat, 2 Dec 2023 10:27:48 -0400 Subject: [PATCH] basic nodeinfo support --- Cargo.lock | 2 +- src/main.rs | 33 ++++++++++++++++++++++++++++++--- src/radio.rs | 7 +++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce85585..d513fef 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 b5253a3..5b936f2 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 52afe78..1c3812e 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, -- GitLab