Skip to content

Commit

Permalink
Improve PGN testing
Browse files Browse the repository at this point in the history
  • Loading branch information
acmorrow authored Feb 4, 2025
1 parent fc41626 commit 4ab0be2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ upload: cargo-ver
cargo +esp espflash flash --package micro-rdk-server --monitor --partition-table micro-rdk-server/esp32/partitions.csv --baud 460800 -f 80mhz --bin micro-rdk-server-esp32 --target=xtensa-esp32-espidf -Zbuild-std=std,panic_abort

test:
cargo test -p micro-rdk --lib --features native,ota
cargo test --workspace --tests --no-fail-fast --features native,ota

clippy-native:
cargo clippy -p micro-rdk --no-deps --features native,ota -- -Dwarnings
Expand Down
17 changes: 12 additions & 5 deletions micro-rdk-nmea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ mod tests {
messages::{
message::Message,
pgns::{
GnssPositionData, GnssSatsInView, TemperatureExtendedRange, WaterDepth,
MESSAGE_DATA_OFFSET,
GnssPositionData, NmeaMessage, NmeaMessageBody, TemperatureExtendedRange,
WaterDepth, MESSAGE_DATA_OFFSET,
},
},
parse_helpers::{
Expand Down Expand Up @@ -157,10 +157,17 @@ mod tests {
let res = general_purpose::STANDARD.decode_vec(msg_str, &mut data);
assert!(res.is_ok());

let cursor = DataCursor::new(data[MESSAGE_DATA_OFFSET..].to_vec());
let message = GnssSatsInView::from_cursor(cursor);
assert!(message.is_ok());
let nmea_message = NmeaMessage::try_from(data);
assert!(nmea_message.is_ok());

let nmea_message = nmea_message.unwrap();
let message = match nmea_message.data {
NmeaMessageBody::GnssSatsInView(val) => Some(val),
_ => None,
};
assert!(message.is_some());
let message = message.unwrap();

println!("message: {:?}", message);

let source_id = message.source_id();
Expand Down
14 changes: 5 additions & 9 deletions micro-rdk-nmea/src/messages/pgns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub struct GnssSatsInView {
}

macro_rules! define_pgns {
( $(($pgndef:ident, $pgn:expr)),* ) => {
( $($pgndef:ident),* ) => {
#[derive(Clone, Debug)]
pub enum NmeaMessageBody {
$($pgndef($pgndef)),*,
Expand All @@ -143,7 +143,7 @@ macro_rules! define_pgns {

pub fn from_bytes(pgn: u32, bytes: Vec<u8>) -> Result<Self, crate::parse_helpers::errors::NmeaParseError> {
Ok(match pgn {
$($pgn => {
$($pgndef::PGN => {
let cursor = DataCursor::new(bytes);
Self::$pgndef($pgndef::from_cursor(cursor)?)
}),*,
Expand All @@ -163,15 +163,11 @@ macro_rules! define_pgns {

pub const MESSAGE_DATA_OFFSET: usize = 32;

define_pgns!(
(WaterDepth, 128267),
(TemperatureExtendedRange, 130316),
(GnssSatsInView, 129540)
);
define_pgns!(WaterDepth, TemperatureExtendedRange, GnssSatsInView);

pub struct NmeaMessage {
metadata: NmeaMessageMetadata,
data: NmeaMessageBody,
pub metadata: NmeaMessageMetadata,
pub data: NmeaMessageBody,
}

impl TryFrom<Vec<u8>> for NmeaMessage {
Expand Down
1 change: 1 addition & 0 deletions micro-rdk/src/common/conn/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl IncomingConnectionManager {
Self { connections }
}

#[allow(dead_code)]
pub(crate) fn max_connections(&self) -> usize {
self.connections.len()
}
Expand Down
1 change: 1 addition & 0 deletions micro-rdk/src/common/robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ impl LocalRobot {
}

pub fn get_periodic_app_client_tasks(&mut self) -> Vec<Box<dyn PeriodicAppClientTask>> {
#[allow(unused_mut)]
let mut tasks = Vec::<Box<dyn PeriodicAppClientTask>>::new();

#[cfg(feature = "data")]
Expand Down
3 changes: 1 addition & 2 deletions micro-rdk/src/common/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ pub(crate) fn register_models(registry: &mut ComponentRegistry) {
}
}

pub type GenericReadingsResult =
::std::collections::HashMap<::prost::alloc::string::String, google::protobuf::Value>;
pub type GenericReadingsResult = HashMap<::prost::alloc::string::String, google::protobuf::Value>;

#[cfg(feature = "data")]
impl From<GenericReadingsResult> for Data {
Expand Down

0 comments on commit 4ab0be2

Please sign in to comment.