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

Feature/channel settings #68

Merged
merged 16 commits into from
Oct 2, 2020
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
15 changes: 15 additions & 0 deletions booster.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Action(enum.Enum):
Enable = 'Enable'
Disable = 'Disable'
Powerup = 'Powerup'
Save = 'Save'


def generate_request(**kwargs):
Expand Down Expand Up @@ -122,6 +123,15 @@ async def disable_channel(self, channel):
await self._update_channel_state(channel, Action.Disable)


async def save_channel(self, channel):
""" Save a booster channel state.

Args:
channel: The channel index to save.
"""
await self._update_channel_state(channel, Action.Save)


async def _update_channel_state(self, channel, action):
""" Update the state of a booster RF channel.

Expand Down Expand Up @@ -193,6 +203,10 @@ async def channel_configuration(args):
await interface.disable_channel(args.channel)
print(f'Channel {args.channel} disabled')

if args.save:
await interface.save_channel(args.channel)
print(f'Channel {args.channel} configuration saved')

await interface.client.disconnect()


Expand All @@ -210,6 +224,7 @@ def main():
parser.add_argument('--thresholds', type=float, nargs=2,
help='The interlock thresholds in the following order: '
'<output> <reflected>')
parser.add_argument('--save', action='store_true', help='Save the RF channel configuration')

loop = asyncio.get_event_loop()
loop.run_until_complete(channel_configuration(parser.parse_args()))
Expand Down
16 changes: 16 additions & 0 deletions rf-module-eeprom/2004220PW-0007A0214.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[0x2, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xa, 0xd4, 0x1, 0x83, 0x0, 0xf4, 0x0, 0x37, 0x0, 0x56, 0x5, 0x84, 0x42, 0x64,
0x0, 0x0, 0x44, 0x42, 0x40, 0x0, 0x3c, 0x7d, 0x9f, 0x4e, 0xc1, 0xd7, 0x9a, 0x8d, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x4, 0x91, 0x62, 0xc2, 0x63, 0xb5]
54 changes: 14 additions & 40 deletions src/booster_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ use crate::error::Error;
use crate::rf_channel::{ChannelPins as RfChannelPins, ChannelState, RfChannel};
use embedded_hal::blocking::delay::DelayUs;

/// A EUI-48 identifier for a given channel.
pub struct ChannelIdentifier {
pub data: [u8; 6],
}

impl ChannelIdentifier {
/// Construct a new channel identifier.
pub fn new(identifier: [u8; 6]) -> Self {
Self { data: identifier }
}
}

/// Contains channel status information in SI base units.
#[derive(Debug, serde::Serialize)]
pub struct ChannelStatus {
Expand Down Expand Up @@ -115,10 +103,7 @@ impl BoosterChannels {
.expect("Channel pins not available");

match RfChannel::new(&manager, control_pins, delay) {
Some(mut rf_channel) => {
// Setting interlock thresholds should not fail here as we have verified the
// device is on the bus.
rf_channel.set_interlock_thresholds(0.0, 0.0).unwrap();
Some(rf_channel) => {
rf_channels[channel as usize].replace(rf_channel);
}
None => {
Expand Down Expand Up @@ -163,30 +148,6 @@ impl BoosterChannels {
}
}

/// Get a channel's EUI-48 identifier.
///
/// # Args
/// * `channel` - The channel to get the identifier from.
///
/// # Returns
/// The channel identifier.
pub fn get_identifier(&mut self, channel: Channel) -> Result<ChannelIdentifier, Error> {
self.mux.select_bus(Some(channel.into())).unwrap();

match &mut self.channels[channel as usize] {
Some(rf_channel) => {
let mut identifier: [u8; 6] = [0; 6];
rf_channel
.i2c_devices
.eui48
.read_eui48(&mut identifier)
.unwrap();
Ok(ChannelIdentifier::new(identifier))
}
None => Err(Error::NotPresent),
}
}

/// Enable an RF channel.
///
/// # Args
Expand Down Expand Up @@ -332,6 +293,19 @@ impl BoosterChannels {
}
}

/// Save the current channel configuration in channel EEPROM.
pub fn save_configuration(&mut self, channel: Channel) -> Result<(), Error> {
self.mux.select_bus(Some(channel.into())).unwrap();

match &mut self.channels[channel as usize] {
Some(rf_channel) => {
rf_channel.save_configuration();
Ok(())
}
None => Err(Error::NotPresent),
}
}

/// Update the states of RF channels as necessary.
pub fn update(&mut self) {
for channel in Channel::into_enum_iter() {
Expand Down
8 changes: 8 additions & 0 deletions src/linear_transformation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
//! Booster NGFW linear-transformation routines
//!
//! # Copyright
//! Copyright (C) 2020 QUARTIQ GmbH - All Rights Reserved
//! Unauthorized usage, editing, or copying is strictly prohibited.
//! Proprietary and confidential.

/// A structure for mapping values between two different domains.
#[derive(serde::Serialize, serde::Deserialize)]
pub struct LinearTransformation {
slope: f32,
offset: f32,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ const APP: () = {
c.schedule.usb(c.start).unwrap();
c.schedule.fans(c.start).unwrap();

// Clear the reset flags now that initialization has completed.
platform::clear_reset_flags();

init::LateResources {
// Note that these share a resource because they both exist on the same I2C bus.
main_bus: MainBus { fans, channels },
Expand Down
5 changes: 5 additions & 0 deletions src/mqtt_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum ChannelAction {
Enable,
Disable,
Powerup,
Save,
}

/// Specifies a generic request for a specific channel.
Expand Down Expand Up @@ -216,6 +217,10 @@ fn handle_channel_update(message: &[u8], channels: &mut BoosterChannels) -> Stri
|e| Response::error(e),
|_| Response::okay("Channel powered"),
),
ChannelAction::Save => channels.save_configuration(request.channel).map_or_else(
|e| Response::error(e),
|_| Response::okay("Configuration saved"),
),
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ pub fn shutdown_channels() {
gpiod.bsrr.write(|w| w.bits(0x00FF_0000));
}
}

/// Check if a watchdog reset has been detected.
///
/// # Returns
/// True if a watchdog reset has been detected. False otherwise.
pub fn watchdog_detected() -> bool {
let rcc = unsafe { &*hal::stm32::RCC::ptr() };

rcc.csr.read().wdgrstf().bit_is_set()
}

/// Clear all of the reset flags in the device.
pub fn clear_reset_flags() {
let rcc = unsafe { &*hal::stm32::RCC::ptr() };

rcc.csr.modify(|_, w| w.rmvf().set_bit());
}
Loading