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

format: run cargo fmt #106

Merged
merged 2 commits into from
May 11, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
components: clippy
toolchain: stable
target: thumbv7em-none-eabihf
- name: cargofmt
run: cargo fmt --check
- uses: actions/cache@v3
with:
path: |
Expand All @@ -31,3 +33,4 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion boards/beacon/src/communication.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//! Interface the SPI-based CAN device here.
//! Interface the SPI-based CAN device here.
29 changes: 14 additions & 15 deletions boards/beacon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
mod data_manager;
mod types;

use common_arm::SdManager;

Check warning on line 8 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `common_arm::SdManager`

warning: unused import: `common_arm::SdManager` --> boards/beacon/src/main.rs:8:5 | 8 | use common_arm::SdManager; | ^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use common_arm::*;
use data_manager::DataManager;
// use defmt::info;
use messages::sensor::Sensor;
use messages::*;
use stm32l0xx_hal as hal;
use hal::{
gpio::*,
gpio::{
gpioa::{PA10, PA9},
Output, PushPull,
},
prelude::*,
rcc::Config,
gpio::{gpioa::{PA9, PA10}, Output, PushPull},
};
use messages::sensor::Sensor;

Check warning on line 21 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `messages::sensor::Sensor`

warning: unused import: `messages::sensor::Sensor` --> boards/beacon/src/main.rs:21:5 | 21 | use messages::sensor::Sensor; | ^^^^^^^^^^^^^^^^^^^^^^^^
use messages::*;
use stm32l0xx_hal as hal;

use systick_monotonic::*;

// use https://github.com/lora-rs/lora-rs.git
// use https://github.com/lora-rs/lora-rs.git

/// Custom panic handler.
/// Reset the system if a panic occurs.
Expand All @@ -30,7 +33,7 @@
stm32l0xx_hal::pac::SCB::sys_reset();
}

// Add dispatchers
// Add dispatchers
#[rtic::app(device = hal::pac, peripherals = true, dispatchers = [EXTI0_1, EXTI2_3, EXTI4_15])]
mod app {

Expand All @@ -39,7 +42,7 @@
#[shared]
struct Shared {
em: ErrorManager,
data_manager: DataManager,

Check warning on line 45 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

field `data_manager` is never read

warning: field `data_manager` is never read --> boards/beacon/src/main.rs:45:9 | 45 | data_manager: DataManager, | ^^^^^^^^^^^^ ... 59 | fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { | ------ field in this struct
}

#[local]
Expand All @@ -56,14 +59,14 @@
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
let device = cx.device;
let core = cx.core;
// configure the clock

// configure the clock
let mut rcc = device.RCC.freeze(Config::hse(64_000_000u32.Hz()));

// configure leds
// configure leds
let gpioa = device.GPIOA.split(&mut rcc);
let mut green_led = gpioa.pa9.into_push_pull_output();

Check warning on line 68 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> boards/beacon/src/main.rs:68:13 | 68 | let mut green_led = gpioa.pa9.into_push_pull_output(); | ----^^^^^^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
let mut red_led = gpioa.pa10.into_push_pull_output();

Check warning on line 69 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> boards/beacon/src/main.rs:69:13 | 69 | let mut red_led = gpioa.pa10.into_push_pull_output(); | ----^^^^^^^ | | | help: remove this `mut`

/* Monotonic clock */
// implement the monotonic clock
Expand All @@ -73,12 +76,8 @@
Shared {
em: ErrorManager::new(),
data_manager: DataManager::new(),

},
Local {
green_led,
red_led,
},
Local { green_led, red_led },
init::Monotonics(mono),
)
}
Expand All @@ -86,19 +85,19 @@
/// Idle task for when no other tasks are running.
#[idle]
fn idle(_: idle::Context) -> ! {
loop {}

Check warning on line 88 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

empty `loop {}` wastes CPU cycles

warning: empty `loop {}` wastes CPU cycles --> boards/beacon/src/main.rs:88:9 | 88 | loop {} | ^^^^^^^ | = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop = note: `#[warn(clippy::empty_loop)]` on by default
}

/**
* Sends a message over CAN.
*/
#[task(capacity = 10, local = [counter: u16 = 0], shared = [&em])]
fn send_internal(cx: send_internal::Context, m: Message) {

Check warning on line 95 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `m`

warning: unused variable: `m` --> boards/beacon/src/main.rs:95:50 | 95 | fn send_internal(cx: send_internal::Context, m: Message) { | ^ help: if this is intentional, prefix it with an underscore: `_m`

Check warning on line 95 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `cx`

warning: unused variable: `cx` --> boards/beacon/src/main.rs:95:22 | 95 | fn send_internal(cx: send_internal::Context, m: Message) { | ^^ help: if this is intentional, prefix it with an underscore: `_cx` | = note: `#[warn(unused_variables)]` on by default
todo!("Send messages over CAN");
}

#[task(capacity = 5)]
#[task(capacity = 5)]
fn send_external(cx: send_external::Context, m: Message) {

Check warning on line 100 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `m`

warning: unused variable: `m` --> boards/beacon/src/main.rs:100:50 | 100 | fn send_external(cx: send_external::Context, m: Message) { | ^ help: if this is intentional, prefix it with an underscore: `_m`

Check warning on line 100 in boards/beacon/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `cx`

warning: unused variable: `cx` --> boards/beacon/src/main.rs:100:22 | 100 | fn send_external(cx: send_external::Context, m: Message) { | ^^ help: if this is intentional, prefix it with an underscore: `_cx`
todo!("Send messages over LORA");
}

Expand Down
2 changes: 1 addition & 1 deletion boards/beacon/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
// -------
// Node ID
// -------
pub static COM_ID: Node = BeaconBoard;
pub static COM_ID: Node = BeaconBoard;

Check warning on line 7 in boards/beacon/src/types.rs

View workflow job for this annotation

GitHub Actions / clippy

static `COM_ID` is never used

warning: static `COM_ID` is never used --> boards/beacon/src/types.rs:7:12 | 7 | pub static COM_ID: Node = BeaconBoard; | ^^^^^^
3 changes: 1 addition & 2 deletions boards/camera/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@
}

pub struct CanDevice0 {
pub can: Can<
'static,
Can0,
Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>,
Capacities,
>,

Check warning on line 53 in boards/camera/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> boards/camera/src/communication.rs:48:14 | 48 | pub can: Can< | ______________^ 49 | | 'static, 50 | | Can0, 51 | | Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>, 52 | | Capacities, 53 | | >, | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
line_interrupts: OwnedInterruptSet<Can0, EnabledLine0>,
}

impl CanDevice0 {
pub fn new<S>(
can_rx: Pin<PA23, AlternateI>,
can_tx: Pin<PA22, AlternateI>,
pclk_can: Pclk<Can0, Gclk0Id>,
ahb_clock: AhbClk<Can0>,
peripheral: CAN0,
gclk0: S,
can_memory: &'static mut SharedMemory<Capacities>,
loopback: bool,
) -> (Self, S::Inc)

Check warning on line 67 in boards/camera/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> boards/camera/src/communication.rs:58:5 | 58 | / pub fn new<S>( 59 | | can_rx: Pin<PA23, AlternateI>, 60 | | can_tx: Pin<PA22, AlternateI>, 61 | | pclk_can: Pclk<Can0, Gclk0Id>, ... | 66 | | loopback: bool, 67 | | ) -> (Self, S::Inc) | |_______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default
where
S: Source<Id = Gclk0Id> + Increment,
{
Expand Down Expand Up @@ -103,8 +103,7 @@
can.filters_standard()
.push(Filter::Classic {
action: Action::StoreFifo0,
filter: ecan::StandardId::new(messages::node::Node::SensorBoard.into())
.unwrap(),
filter: ecan::StandardId::new(messages::node::Node::SensorBoard.into()).unwrap(),
mask: ecan::StandardId::ZERO,
})
.unwrap_or_else(|_| panic!("Sensor filter"));
Expand Down
6 changes: 3 additions & 3 deletions boards/camera/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
Some(air) => match air.altitude {
Some(altitude) => altitude > HEIGHT_MIN,
None => false,
}
},
None => false,
}
}
Expand Down Expand Up @@ -105,19 +105,19 @@
match self.air.as_ref() {
Some(air) => match air.altitude {
Some(altitude) => altitude < MAIN_HEIGHT,
None => false
}
None => false,
},
None => false,
}
}
pub fn handle_data(&mut self, data: Message) {
match data.data {
messages::Data::Sensor(sensor) => match sensor.data {
messages::sensor::SensorData::Air(air_data) => {
self.air = Some(air_data);
}
_ => {}
},

Check warning on line 120 in boards/camera/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> boards/camera/src/data_manager.rs:115:47 | 115 | messages::Data::Sensor(sensor) => match sensor.data { | _______________________________________________^ 116 | | messages::sensor::SensorData::Air(air_data) => { 117 | | self.air = Some(air_data); 118 | | } 119 | | _ => {} 120 | | }, | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try | 115 ~ messages::Data::Sensor(sensor) => if let messages::sensor::SensorData::Air(air_data) = sensor.data { 116 + self.air = Some(air_data); 117 ~ }, |
_ => {}
}

Check warning on line 122 in boards/camera/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> boards/camera/src/data_manager.rs:114:9 | 114 | / match data.data { 115 | | messages::Data::Sensor(sensor) => match sensor.data { 116 | | messages::sensor::SensorData::Air(air_data) => { 117 | | self.air = Some(air_data); ... | 121 | | _ => {} 122 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try | 114 ~ if let messages::Data::Sensor(sensor) = data.data { match sensor.data { 115 + messages::sensor::SensorData::Air(air_data) => { 116 + self.air = Some(air_data); 117 + } 118 + _ => {} 119 + } } |
}
Expand Down
9 changes: 3 additions & 6 deletions boards/communication/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@
}

pub struct CanDevice0 {
pub can: Can<
'static,
Can0,
Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>,
Capacities,
>,

Check warning on line 67 in boards/communication/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> boards/communication/src/communication.rs:62:14 | 62 | pub can: Can< | ______________^ 63 | | 'static, 64 | | Can0, 65 | | Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>, 66 | | Capacities, 67 | | >, | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
line_interrupts: OwnedInterruptSet<Can0, EnabledLine0>,
}

impl CanDevice0 {
pub fn new<S>(
can_rx: Pin<PA23, AlternateI>,
can_tx: Pin<PA22, AlternateI>,
pclk_can: Pclk<Can0, Gclk0Id>,
ahb_clock: AhbClk<Can0>,
peripheral: CAN0,
gclk0: S,
can_memory: &'static mut SharedMemory<Capacities>,
loopback: bool,
) -> (Self, S::Inc)

Check warning on line 81 in boards/communication/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> boards/communication/src/communication.rs:72:5 | 72 | / pub fn new<S>( 73 | | can_rx: Pin<PA23, AlternateI>, 74 | | can_tx: Pin<PA22, AlternateI>, 75 | | pclk_can: Pclk<Can0, Gclk0Id>, ... | 80 | | loopback: bool, 81 | | ) -> (Self, S::Inc) | |_______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default
where
S: Source<Id = Gclk0Id> + Increment,
{
Expand Down Expand Up @@ -120,17 +120,15 @@
can.filters_standard()
.push(Filter::Classic {
action: Action::StoreFifo0,
filter: ecan::StandardId::new(messages::node::Node::RecoveryBoard.into())
.unwrap(),
filter: ecan::StandardId::new(messages::node::Node::RecoveryBoard.into()).unwrap(),
mask: ecan::StandardId::ZERO,
})
.unwrap_or_else(|_| panic!("Recovery filter"));

can.filters_standard()
.push(Filter::Classic {
action: Action::StoreFifo1,
filter: ecan::StandardId::new(messages::node::Node::SensorBoard.into())
.unwrap(),
filter: ecan::StandardId::new(messages::node::Node::SensorBoard.into()).unwrap(),
mask: ecan::StandardId::ZERO,
})
.unwrap_or_else(|_| panic!("Sensor filter"));
Expand All @@ -146,8 +144,7 @@
can.filters_standard()
.push(Filter::Classic {
action: Action::StoreFifo0,
filter: ecan::StandardId::new(messages::node::Node::GroundStation.into())
.unwrap(),
filter: ecan::StandardId::new(messages::node::Node::GroundStation.into()).unwrap(),
mask: ecan::StandardId::ZERO,
})
.unwrap_or_else(|_| panic!("Ground Station filter"));
Expand Down Expand Up @@ -299,16 +296,16 @@
// Do we need the header?
match msg {
mavlink::uorocketry::MavMessage::POSTCARD_MESSAGE(msg) => {
return Ok(postcard::from_bytes::<Message>(&msg.message)?);

Check warning on line 299 in boards/communication/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/communication.rs:299:21 | 299 | return Ok(postcard::from_bytes::<Message>(&msg.message)?); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `#[warn(clippy::needless_return)]` on by default help: remove `return` | 299 - return Ok(postcard::from_bytes::<Message>(&msg.message)?); 299 + Ok(postcard::from_bytes::<Message>(&msg.message)?) |
// weird Ok syntax to coerce to hydra error type.
}
_ => {
herror!(Error, ErrorContext::UnkownPostcardMessage);
return Err(mavlink::error::MessageReadError::Io.into());

Check warning on line 304 in boards/communication/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/communication.rs:304:21 | 304 | return Err(mavlink::error::MessageReadError::Io.into()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 304 - return Err(mavlink::error::MessageReadError::Io.into()); 304 + Err(mavlink::error::MessageReadError::Io.into()) |
}
}
} else {
return Err(mavlink::error::MessageReadError::Io.into());

Check warning on line 308 in boards/communication/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/communication.rs:308:13 | 308 | return Err(mavlink::error::MessageReadError::Io.into()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 308 - return Err(mavlink::error::MessageReadError::Io.into()); 308 + Err(mavlink::error::MessageReadError::Io.into()) |
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions boards/recovery/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@
}

pub struct CanDevice0 {
pub can: Can<
'static,
Can0,
Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>,
Capacities,
>,

Check warning on line 57 in boards/recovery/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> boards/recovery/src/communication.rs:52:14 | 52 | pub can: Can< | ______________^ 53 | | 'static, 54 | | Can0, 55 | | Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>, 56 | | Capacities, 57 | | >, | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
line_interrupts: OwnedInterruptSet<Can0, EnabledLine0>,
}

impl CanDevice0 {
pub fn new<S>(
can_rx: Pin<PA23, AlternateI>,
can_tx: Pin<PA22, AlternateI>,
pclk_can: Pclk<Can0, Gclk0Id>,
ahb_clock: AhbClk<Can0>,
peripheral: CAN0,
gclk0: S,
can_memory: &'static mut SharedMemory<Capacities>,
loopback: bool,
) -> (Self, S::Inc)

Check warning on line 71 in boards/recovery/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> boards/recovery/src/communication.rs:62:5 | 62 | / pub fn new<S>( 63 | | can_rx: Pin<PA23, AlternateI>, 64 | | can_tx: Pin<PA22, AlternateI>, 65 | | pclk_can: Pclk<Can0, Gclk0Id>, ... | 70 | | loopback: bool, 71 | | ) -> (Self, S::Inc) | |_______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default
where
S: Source<Id = Gclk0Id> + Increment,
{
Expand Down Expand Up @@ -111,8 +111,7 @@
can.filters_standard()
.push(Filter::Classic {
action: Action::StoreFifo0,
filter: ecan::StandardId::new(messages::node::Node::SensorBoard.into())
.unwrap(),
filter: ecan::StandardId::new(messages::node::Node::SensorBoard.into()).unwrap(),
mask: ecan::StandardId::ZERO,
})
.unwrap_or_else(|_| panic!("Sensor Board filter"));
Expand Down
14 changes: 7 additions & 7 deletions boards/recovery/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl DataManager {
Some(air) => match air.altitude {
Some(altitude) => altitude > HEIGHT_MIN,
None => false,
}
},
None => false,
}
}
Expand Down Expand Up @@ -120,7 +120,7 @@ impl DataManager {
Some(air) => match air.altitude {
Some(altitude) => altitude < MAIN_HEIGHT,
None => false,
}
},
None => false,
}
}
Expand All @@ -132,11 +132,11 @@ impl DataManager {
messages::Data::Sensor(sensor) => match sensor.data {
messages::sensor::SensorData::Air(air_data) => {
/*
NOTE!!!
There should be added a counter to check how many times
the alt is dropped, if the number is high switch to
the on board barometer.
*/
NOTE!!!
There should be added a counter to check how many times
the alt is dropped, if the number is high switch to
the on board barometer.
*/

if let Some(alt) = air_data.altitude {
let tup_data: (f32, u32) = (alt, air_data.time_stamp);
Expand Down
6 changes: 2 additions & 4 deletions boards/sensor/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@
}

pub struct CanDevice0 {
pub can: Can<
'static,
Can0,
Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>,
Capacities,
>,

Check warning on line 59 in boards/sensor/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> boards/sensor/src/communication.rs:54:14 | 54 | pub can: Can< | ______________^ 55 | | 'static, 56 | | Can0, 57 | | Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>, 58 | | Capacities, 59 | | >, | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
line_interrupts: OwnedInterruptSet<Can0, EnabledLine0>,
}

impl CanDevice0 {
pub fn new<S>(
can_rx: Pin<PA23, AlternateI>,
can_tx: Pin<PA22, AlternateI>,
pclk_can: Pclk<Can0, Gclk0Id>,
ahb_clock: AhbClk<Can0>,
peripheral: CAN0,
gclk0: S,
can_memory: &'static mut SharedMemory<Capacities>,
loopback: bool,
) -> (Self, S::Inc)

Check warning on line 73 in boards/sensor/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> boards/sensor/src/communication.rs:64:5 | 64 | / pub fn new<S>( 65 | | can_rx: Pin<PA23, AlternateI>, 66 | | can_tx: Pin<PA22, AlternateI>, 67 | | pclk_can: Pclk<Can0, Gclk0Id>, ... | 72 | | loopback: bool, 73 | | ) -> (Self, S::Inc) | |_______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default
where
S: Source<Id = Gclk0Id> + Increment,
{
Expand Down Expand Up @@ -121,17 +121,15 @@
can.filters_standard()
.push(Filter::Classic {
action: Action::StoreFifo0,
filter: ecan::StandardId::new(messages::node::Node::RecoveryBoard.into())
.unwrap(),
filter: ecan::StandardId::new(messages::node::Node::RecoveryBoard.into()).unwrap(),
mask: ecan::StandardId::ZERO,
})
.unwrap_or_else(|_| panic!("Recovery filter"));

can.filters_standard()
.push(Filter::Classic {
action: Action::StoreFifo1,
filter: ecan::StandardId::new(messages::node::Node::GroundStation.into())
.unwrap(),
filter: ecan::StandardId::new(messages::node::Node::GroundStation.into()).unwrap(),
mask: ecan::StandardId::ZERO,
})
.unwrap_or_else(|_| panic!("Ground Station filter"));
Expand Down
3 changes: 2 additions & 1 deletion boards/sensor/src/data_manager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::app::sleep_system;
use common_arm::{spawn, HydraError};
use messages::sensor::{
Air, EkfNav1, EkfNav2, EkfQuat, GpsPos1, GpsPos2, GpsVel, Imu1, Imu2, SensorData, UtcTime, EkfNavAcc, GpsPosAcc, GpsVelAcc,
Air, EkfNav1, EkfNav2, EkfNavAcc, EkfQuat, GpsPos1, GpsPos2, GpsPosAcc, GpsVel, GpsVelAcc,
Imu1, Imu2, SensorData, UtcTime,
};
use messages::Message;

Expand Down
4 changes: 3 additions & 1 deletion libraries/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ impl Message {

#[cfg(test)]
mod test {
use crate::{Message, MAX_HEALTH_SIZE, MAX_COMMAND_SIZE, MAX_LOG_SIZE, MAX_SENSOR_SIZE, MAX_STATE_SIZE};
use crate::{
Message, MAX_COMMAND_SIZE, MAX_HEALTH_SIZE, MAX_LOG_SIZE, MAX_SENSOR_SIZE, MAX_STATE_SIZE,
};
use proptest::prelude::*;

proptest! {
Expand Down
79 changes: 52 additions & 27 deletions libraries/sbg-rs/src/data_conversion.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::bindings::{
SbgLogAirData, SbgLogEkfNavData, SbgLogEkfQuatData, SbgLogGpsVel, SbgLogImuData, SbgLogUtcData, SbgLogGpsPos,
SbgLogAirData, SbgLogEkfNavData, SbgLogEkfQuatData, SbgLogGpsPos, SbgLogGpsVel, SbgLogImuData,
SbgLogUtcData,
};
use bitflags::Flags;
use messages::sensor::{Air, EkfNav1, EkfNav2, EkfNavAcc, EkfQuat, GpsVel, Imu1, Imu2, UtcTime, GpsPos1, GpsPos2, GpsPosAcc, GpsVelAcc};
use messages::sensor::{
Air, EkfNav1, EkfNav2, EkfNavAcc, EkfQuat, GpsPos1, GpsPos2, GpsPosAcc, GpsVel, GpsVelAcc,
Imu1, Imu2, UtcTime,
};
use messages::sensor_status::{
AirFlags, AirStatus, EkfFlags, EkfStatus, GpsVelStatus, GpsVelStatusE, ImuFlags, ImuStatus,
UtcStatus, UtcTimeStatus, GpsPositionStatus, GpsPositionStatusE
AirFlags, AirStatus, EkfFlags, EkfStatus, GpsPositionStatus, GpsPositionStatusE, GpsVelStatus,
GpsVelStatusE, ImuFlags, ImuStatus, UtcStatus, UtcTimeStatus,
};

/// Simple helper function to work with the flags structure and set the fields as needed.
Expand All @@ -23,40 +27,63 @@ where
impl From<SbgLogGpsPos> for (GpsPos1, GpsPos2, GpsPosAcc) {
fn from(value: SbgLogGpsPos) -> Self {
let status = GpsPositionStatus::new(value.status);

let valid = matches!(status.get_status(), Some(GpsPositionStatusE::SolComputed));

(
GpsPos1 {
latitude: if valid {Some(value.latitude)} else {None},
longitude: if valid {Some(value.longitude)} else {None},
latitude: if valid { Some(value.latitude) } else { None },
longitude: if valid { Some(value.longitude) } else { None },
},
GpsPos2 {
altitude: if valid {Some(value.altitude)} else {None},
undulation: if valid {Some(value.undulation)} else {None},
time_of_week: if valid {Some(value.timeOfWeek)} else {None},
altitude: if valid { Some(value.altitude) } else { None },
undulation: if valid { Some(value.undulation) } else { None },
time_of_week: if valid { Some(value.timeOfWeek) } else { None },
},
GpsPosAcc {
status,
time_stamp: value.timeStamp,
latitude_accuracy: if valid {Some(value.latitudeAccuracy)} else {None},
longitude_accuracy: if valid {Some(value.longitudeAccuracy)} else {None},
altitude_accuracy: if valid {Some(value.altitudeAccuracy)} else {None},
num_sv_used: if valid {Some(value.numSvUsed)} else {None},
base_station_id: if valid {Some(value.baseStationId)} else {None},
differential_age: if valid {Some(value.differentialAge)} else {None},
}
latitude_accuracy: if valid {
Some(value.latitudeAccuracy)
} else {
None
},
longitude_accuracy: if valid {
Some(value.longitudeAccuracy)
} else {
None
},
altitude_accuracy: if valid {
Some(value.altitudeAccuracy)
} else {
None
},
num_sv_used: if valid { Some(value.numSvUsed) } else { None },
base_station_id: if valid {
Some(value.baseStationId)
} else {
None
},
differential_age: if valid {
Some(value.differentialAge)
} else {
None
},
},
)
}
}

impl From<SbgLogUtcData> for UtcTime {
fn from(value: SbgLogUtcData) -> Self {
let status = UtcTimeStatus::new(value.status);
let valid = matches!(status.get_utc_status(), Some(UtcStatus::Valid | UtcStatus::NoLeapSec));
let valid = matches!(
status.get_utc_status(),
Some(UtcStatus::Valid | UtcStatus::NoLeapSec)
);

Self {
time_stamp: value.timeStamp, // not convinced this is matched valid to the Utc Status bitmask.
time_stamp: value.timeStamp, // not convinced this is matched valid to the Utc Status bitmask.
status,
year: if valid { Some(value.year) } else { None },
month: if valid { Some(value.month) } else { None },
Expand Down Expand Up @@ -114,7 +141,6 @@ impl From<SbgLogEkfNavData> for (EkfNav1, EkfNav2, EkfNavAcc) {
EkfNav1 {
time_stamp: value.timeStamp,
velocity: check(&flags, EkfFlags::VelocityValid, value.velocity),

},
EkfNav2 {
undulation: check(&flags, EkfFlags::AttitudeValid, value.undulation),
Expand All @@ -124,7 +150,7 @@ impl From<SbgLogEkfNavData> for (EkfNav1, EkfNav2, EkfNavAcc) {
velocity_std_dev: check(&flags, EkfFlags::VelocityValid, value.velocityStdDev),
position_std_dev: check(&flags, EkfFlags::PositionValid, value.positionStdDev),
status,
}
},
)
}
}
Expand All @@ -142,7 +168,7 @@ impl From<SbgLogImuData> for (Imu1, Imu2) {
accelerometers: check(&flags, ImuFlags::AccelsInRange, value.accelerometers),
},
Imu2 {
temperature: Some(value.temperature), // we cannot check since no flag exists. Keep in option for uniformity.
temperature: Some(value.temperature), // we cannot check since no flag exists. Keep in option for uniformity.
delta_velocity: check(&flags, ImuFlags::AccelsInRange, value.deltaVelocity),
delta_angle: check(&flags, ImuFlags::GyrosInRange, value.deltaAngle),
},
Expand All @@ -159,16 +185,15 @@ impl From<SbgLogGpsVel> for (GpsVel, GpsVelAcc) {
(
GpsVel {
time_stamp: value.timeStamp,
time_of_week: if valid {Some(value.timeOfWeek) } else {None},
time_of_week: if valid { Some(value.timeOfWeek) } else { None },
status,
velocity: if valid { Some(value.velocity) } else { None },
course: if valid { Some(value.course) } else { None },
},
},
GpsVelAcc {
velocity_acc: if valid { Some(value.velocityAcc) } else { None },
course_acc: if valid { Some(value.courseAcc) } else { None },
}

},
)
}
}
Loading