Skip to content

Commit

Permalink
Merge pull request #219 from quartiq/feature/service-publish
Browse files Browse the repository at this point in the history
Adding metadata topic publish on alive tree
  • Loading branch information
ryan-summers authored May 3, 2022
2 parents 79307c0 + ecb5e8a commit 02aed07
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 117 deletions.
55 changes: 6 additions & 49 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ shared-bus = { version = "0.2", features = ["cortex-m"] }
usb-device = "0.2.8"
postcard = "0.5.1"
crc-any = { version = "2.3.5", default-features = false }
panic-persist = { version = "0.3", features = ["custom-panic-handler"] }
panic-persist = { version = "0.3", features = ["custom-panic-handler", "utf8"] }
smoltcp-nal = { version = "0.2" }
miniconf = { version = "0.3", features = ["mqtt-client"]}
minimq = "0.5.3"
Expand All @@ -40,7 +40,7 @@ minireq = "0.1"
rtt-target = {version = "0.3", features=["cortex-m"]}

[build-dependencies]
built = { version = "0.5", features = ["git2", "chrono"], default-features = false }
built = { version = "0.5", features = ["git2"], default-features = false }

# Add RawDevice support for the W5500 to operate as an external MAC
[patch.crates-io.w5500]
Expand Down
6 changes: 6 additions & 0 deletions book/src/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ this manual:
1. Pressing any of two the front-panel buttons
1. Communicating with Booster over the USB port
1. Communicating with Booster over ethernet via MQTT

# Fault Mode

When Booster encounters a software fault, it goes into a safe mode where no channels will be
enabled. To acknowledge and clear the fault, utilize the `service` command from the front panel USB
port.
65 changes: 65 additions & 0 deletions src/hardware/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Booster run-time application metadata
//!
//! # Copyright
//! Copyright (C) 2020 QUARTIQ GmbH - All Rights Reserved
//! Unauthorized usage, editing, or copying is strictly prohibited.
//! Proprietary and confidential.
use serde::Serialize;

use super::{platform, HardwareVersion};

mod build_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

#[derive(Serialize)]
pub struct ApplicationMetadata {
pub firmware_version: &'static str,
pub rust_version: &'static str,
pub profile: &'static str,
pub git_dirty: bool,
pub features: &'static str,
pub panic_info: &'static str,
pub watchdog: bool,
pub hardware_version: HardwareVersion,
}

impl ApplicationMetadata {
/// Construct the global metadata.
///
/// # Note
/// This may only be called once.
///
/// # Args
/// * `hardware_version` - The hardware version detected.
///
/// # Returns
/// A reference to the global metadata.
pub fn new(hardware_version: HardwareVersion) -> &'static ApplicationMetadata {
let mut meta = cortex_m::singleton!(: ApplicationMetadata = ApplicationMetadata {
firmware_version: "Unspecified",
rust_version: build_info::RUSTC_VERSION,
profile: build_info::PROFILE,
git_dirty: true,
features: build_info::FEATURES_STR,
panic_info: "None",
watchdog: platform::watchdog_detected(),
hardware_version,
})
.unwrap();

if let Some(panic_data) = panic_persist::get_panic_message_utf8() {
meta.panic_info = panic_data;
}

if let Some(dirty) = build_info::GIT_DIRTY {
meta.git_dirty = dirty;
}

if let Some(version) = build_info::GIT_VERSION {
meta.firmware_version = version;
}

meta
}
}
10 changes: 10 additions & 0 deletions src/hardware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Unauthorized usage, editing, or copying is strictly prohibited.
//! Proprietary and confidential.
use core::fmt::Write;
use enum_iterator::IntoEnumIterator;
use serde::{Deserialize, Serialize};
use stm32f4xx_hal as hal;
Expand All @@ -13,6 +14,7 @@ pub mod booster_channels;
pub mod chassis_fans;
pub mod delay;
pub mod external_mac;
pub mod metadata;
mod mutex;
pub mod net_interface;
pub mod platform;
Expand Down Expand Up @@ -115,3 +117,11 @@ impl core::fmt::Display for HardwareVersion {
}
}
}

impl serde::Serialize for HardwareVersion {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut version_string: heapless::String<32> = heapless::String::new();
write!(&mut version_string, "{}", self).unwrap();
serializer.serialize_str(&version_string)
}
}
32 changes: 19 additions & 13 deletions src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use super::{
booster_channels::BoosterChannels,
chassis_fans::ChassisFans,
delay::AsmDelay,
external_mac, net_interface, platform,
external_mac,
metadata::ApplicationMetadata,
net_interface, platform,
rf_channel::{AdcPin, ChannelPins as RfChannelPins},
user_interface::{UserButtons, UserLeds},
HardwareVersion, NetworkManager, NetworkStack, SystemTimer, Systick, UsbBus, CPU_FREQ, I2C,
Expand Down Expand Up @@ -84,7 +86,7 @@ pub struct BoosterDevices {
pub usb_device: UsbDevice<'static, UsbBus>,
pub usb_serial: usbd_serial::SerialPort<'static, UsbBus>,
pub settings: BoosterSettings,
pub hardware_version: HardwareVersion,
pub metadata: &'static ApplicationMetadata,
pub systick: Systick,
}

Expand Down Expand Up @@ -272,17 +274,21 @@ pub fn setup(
BoosterSettings::new(eui)
};

// Read the hardware version pins.
let hardware_version = {
let hwrev0 = gpiof.pf0.into_pull_down_input();
let hwrev1 = gpiof.pf1.into_pull_down_input();
let hwrev2 = gpiof.pf2.into_pull_down_input();
let metadata = {
// Read the hardware version pins.
let hardware_version = {
let hwrev0 = gpiof.pf0.into_pull_down_input();
let hwrev1 = gpiof.pf1.into_pull_down_input();
let hwrev2 = gpiof.pf2.into_pull_down_input();

HardwareVersion::from(
*0u8.set_bit(0, hwrev0.is_high().unwrap())
.set_bit(1, hwrev1.is_high().unwrap())
.set_bit(2, hwrev2.is_high().unwrap()),
)
};

HardwareVersion::from(
*0u8.set_bit(0, hwrev0.is_high().unwrap())
.set_bit(1, hwrev1.is_high().unwrap())
.set_bit(2, hwrev2.is_high().unwrap()),
)
ApplicationMetadata::new(hardware_version)
};

let (manager, network_stack) = {
Expand Down Expand Up @@ -431,7 +437,7 @@ pub fn setup(
usb_device,
usb_serial,
watchdog,
hardware_version,
metadata,
systick,
}
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ mod app {
booster.settings.id(),
settings,
clock,
booster.metadata,
),
watchdog: watchdog_manager,
},
Expand All @@ -128,7 +129,7 @@ mod app {
booster.usb_device,
booster.usb_serial,
booster.settings,
booster.hardware_version,
booster.metadata,
),
},
init::Monotonics(booster.systick),
Expand Down
2 changes: 2 additions & 0 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl NetworkDevices {
identifier: &str,
settings: crate::RuntimeSettings,
clock: SystemTimer,
metadata: &'static crate::hardware::metadata::ApplicationMetadata,
) -> Self {
let crate::hardware::setup::NetworkDevices {
manager,
Expand Down Expand Up @@ -82,6 +83,7 @@ impl NetworkDevices {
shared.acquire_stack(),
clock,
identifier,
metadata,
),
settings: miniconf::MqttClient::new(
shared.acquire_stack(),
Expand Down
Loading

0 comments on commit 02aed07

Please sign in to comment.