Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating watchdog service rate #114

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/chassis_fans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ impl ChassisFans {
/// * `delay` - An object to implement delays during the test.
///
/// # Returns
/// True if 5 of the six fans properly spun up to a high-speed RPM, 5 were below a specific
/// RPM at 10% duty cycle, and all fans had no speed when disabled.
/// True if 5 of the six fans properly spun up to a high-speed RPM and all fans had no speed
/// when disabled.
pub fn self_test(
&mut self,
delay: &mut impl embedded_hal::blocking::delay::DelayMs<u16>,
Expand All @@ -143,29 +143,18 @@ impl ChassisFans {
delay.delay_ms(5000);
let high_rpms = self.read_rpms();

self.set_duty_cycles(0.1);
delay.delay_ms(7000);
let low_rpms = self.read_rpms();

self.set_duty_cycles(0.0);
delay.delay_ms(7000);
let dead_rpms = self.read_rpms();

// Check that all dead RPMS are zero.
let fans_powered_down = dead_rpms.iter().filter(|&rpms| *rpms == 0).count();

// Check all the low RPMs are lower than 3200 RPMs.
let fans_spun_low = low_rpms
.iter()
.filter(|&rpms| *rpms <= 3200 && *rpms > 0)
.count();

// Check all the high RPMs are higher than 4800 RPMs.
let fans_spun_high = high_rpms.iter().filter(|&rpms| *rpms >= 4800).count();

// If 5 fans (the count mounted on the chassis) spun up to a nominal high speed RPM, 5
// fans were at a nominal low RPM, and 6 fans were not spinning when powered down, fans are
// operating nominally.
(fans_spun_high == 5) && (fans_spun_low == 5) && (fans_powered_down == 6)
// If 5 fans (the count mounted on the chassis) spun up to a nominal high speed RPM and 6
// fans were not spinning when powered down, fans are operating nominally.
(fans_spun_high == 5) && (fans_powered_down == 6)
}
}
70 changes: 32 additions & 38 deletions src/mqtt_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,48 +255,42 @@ impl ControlState {

resources.mqtt_client.lock(|client| {
match client.poll(|client, topic, message, properties| {
main_bus.lock(|main_bus| {
let (id, route) = topic.split_at(topic.find('/').unwrap());
let route = &route[1..];
let (id, route) = topic.split_at(topic.find('/').unwrap());
let route = &route[1..];

if id != self.id {
warn!("Ignoring topic for identifier: {}", id);
return;
}
if id != self.id {
warn!("Ignoring topic for identifier: {}", id);
return;
}

let response = match route {
"channel/state" => handle_channel_update(message, &mut main_bus.channels),
"channel/bias" => {
handle_channel_bias(message, &mut main_bus.channels, *delay)
}
"channel/read" => {
handle_channel_property_read(message, &mut main_bus.channels)
}
"channel/write" => {
handle_channel_property_write(message, &mut main_bus.channels)
}
_ => Response::error_msg("Unexpected topic"),
};

if let Property::ResponseTopic(topic) = properties
.iter()
.find(|&prop| {
if let Property::ResponseTopic(_) = *prop {
true
} else {
false
}
})
.or(Some(&Property::ResponseTopic(
&self.generate_topic_string("log"),
)))
.unwrap()
{
client
.publish(topic, &response.into_bytes(), QoS::AtMostOnce, &[])
.unwrap();
let response = main_bus.lock(|main_bus| match route {
"channel/state" => handle_channel_update(message, &mut main_bus.channels),
"channel/bias" => handle_channel_bias(message, &mut main_bus.channels, *delay),
"channel/read" => handle_channel_property_read(message, &mut main_bus.channels),
"channel/write" => {
handle_channel_property_write(message, &mut main_bus.channels)
}
_ => Response::error_msg("Unexpected topic"),
});

if let Property::ResponseTopic(topic) = properties
.iter()
.find(|&prop| {
if let Property::ResponseTopic(_) = *prop {
true
} else {
false
}
})
.or(Some(&Property::ResponseTopic(
&self.generate_topic_string("log"),
)))
.unwrap()
{
client
.publish(topic, &response.into_bytes(), QoS::AtMostOnce, &[])
.unwrap();
}
}) {
Ok(_) => {}

Expand Down
2 changes: 1 addition & 1 deletion src/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl WatchdogManager {
/// * `watchdog` - The inedpdent watchdog timer.
pub fn new(mut watchdog: hal::watchdog::IndependentWatchdog) -> Self {
watchdog.feed();
watchdog.start(2_000_u32.ms());
watchdog.start(4_000_u32.ms());

Self {
watchdog,
Expand Down