Skip to content

Commit

Permalink
format: run cargo fmt (#106)
Browse files Browse the repository at this point in the history
* format: run cargo fmt

* ci:
  • Loading branch information
seofernando25 authored May 11, 2024
1 parent beef059 commit 8f34d7f
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 70 deletions.
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 @@ -9,19 +9,22 @@ use common_arm::SdManager;
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;
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 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
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 @@ -56,11 +59,11 @@ mod app {
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();
let mut red_led = gpioa.pa10.into_push_pull_output();
Expand All @@ -73,12 +76,8 @@ mod app {
Shared {
em: ErrorManager::new(),
data_manager: DataManager::new(),

},
Local {
green_led,
red_led,
},
Local { green_led, red_led },
init::Monotonics(mono),
)
}
Expand All @@ -97,7 +96,7 @@ mod app {
todo!("Send messages over CAN");
}

#[task(capacity = 5)]
#[task(capacity = 5)]
fn send_external(cx: send_external::Context, m: Message) {
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 @@ use messages::node::Node::BeaconBoard;
// -------
// Node ID
// -------
pub static COM_ID: Node = BeaconBoard;
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 @@ -103,8 +103,7 @@ impl CanDevice0 {
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 @@ impl DataManager {
Some(air) => match air.altitude {
Some(altitude) => altitude > HEIGHT_MIN,
None => false,
}
},
None => false,
}
}
Expand Down Expand Up @@ -105,8 +105,8 @@ impl DataManager {
match self.air.as_ref() {
Some(air) => match air.altitude {
Some(altitude) => altitude < MAIN_HEIGHT,
None => false
}
None => false,
},
None => false,
}
}
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 @@ -120,17 +120,15 @@ impl CanDevice0 {
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 @@ impl CanDevice0 {
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
3 changes: 1 addition & 2 deletions boards/recovery/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ impl CanDevice0 {
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 @@ -121,17 +121,15 @@ impl CanDevice0 {
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 },
}

},
)
}
}

0 comments on commit 8f34d7f

Please sign in to comment.