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

[CONSULT-469] - add more PGN definitions and create sensors #413

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

gvaradarajan
Copy link
Member

  • Added missing unit conversions (m/s to knots, meters to nautical miles)
  • I've included a feature for inclusion in the micro-rdk-ffi for internal organization reasons
  • Implements a variety of sensors using the NMEA parsing logic on raw data including
    • Depth Sensor
    • Boat Movement Sensor
    • Message Sensor (displaying data from specific PGNs)
    • Debug Sensor (includes all raw and parsed data)

@gvaradarajan gvaradarajan requested a review from acmorrow February 6, 2025 15:23
@gvaradarajan gvaradarajan requested a review from a team as a code owner February 6, 2025 15:23
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of small comments and questions, but I'm still trying to make sense of sensors.rs.

@@ -35,6 +35,21 @@ extern "C" {
pub static g_spiram_ok: bool;
}

macro_rules! generate_register_modules {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love duplicating this, but I agree we don't have a better way right now. Could you please file a follow-up ticket to revisit the module registration system and hopefully eliminate the duplication of this macro and the build.rs boilerplate as well?

let result = (result as f64) * 1.94384;
},
Self::MetersToNauticalMiles => quote! {
let result = (result as f64) * 0.539957;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversion looks off to me. One meter isn't ~1/2 a nautical mile. I think this is doing kilometers to nautical miles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, my bad

errors::NmeaParseError,
parsers::{DataCursor, FieldSet, NmeaMessageMetadata},
};

#[derive(PgnMessageDerive, Clone, Debug)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know these are, ultimately, going to be generated. However, until they are, I think having them be readable matters.

Can we separate the fields with blank lines:

pub struct Speed {
    #[pgn = 128259]
    _pgn: PhantomData<u32>,

    source_id: u8,

    #[scale = 0.01]
    #[unit = "knots"]
    speed_water_referenced: u16,

    #[scale = 0.01]
    speed_ground_referenced: u16,

    #[lookup]
    #[bits = 8]
    speed_water_referenced_type: WaterReference,

    #[bits = 4]
    speed_direction: u8,
}

For this and all the others in this file?

Comment on lines +260 to +270
define_pgns!(
WaterDepth,
TemperatureExtendedRange,
GnssSatsInView,
CogSog,
PositionRapidUpdate,
VesselHeading,
Attitude,
Speed,
DistanceLog
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's sort these

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you want them sorted?


pub struct NmeaMessage {
pub metadata: NmeaMessageMetadata,
pub data: NmeaMessageBody,
pub(crate) metadata: NmeaMessageMetadata,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Comment on lines +14 to +15
esp32 = ['micro-rdk/esp32']
native = ['micro-rdk/native']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the NMEA library need to know about esp32 vs native?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because micro-rdk needs to, see https://viam.atlassian.net/browse/RSDK-9710

@@ -25,11 +22,11 @@ pub fn register_models(registry: &mut ComponentRegistry) -> Result<(), RegistryE
}

#[derive(DoCommand)]
pub struct MoistureSensor {
reader: AnalogReaderType<u16>,
pub struct MoistureSensor<T: AnalogReader<u16, Error = AnalogError>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this is now needed because clippy is worked up. It concludes that it doesn't know if AnalogReaderType is Send because of the dyn AnalogReader.

Would it just be easier to declare AnalogReaderType as pub type AnalogReaderType<W, E = AnalogError> = Arc<Mutex<dyn AnalogReader<W, Error = E> + Send>>;?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I was already doing that to Sensor and I wanted to keep the PR small

raw_pgn_sensor.ok_or(SensorError::ConfigError("missing dependent raw pgn sensor"))
}

const DEPTH_PGN: u32 = 128267;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to get these PGN's out from the constants? Isn't this just WaterDepth::PGN, which is a CONST so should be useable here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since those structs (and their names) will be auto-generated in the future, the true constant is the PGN

Comment on lines +7 to +12
//! "1FD0A-16": "Cv0BAHg+gD8voKFnAAAAAIdQAwAAAAAACAD/ABYAAgBbAADgeg8A/w==",
//! "1FD0C-23": "DP0BAHg+gD8voKFnAAAAAL+PAwAAAAAACAD/ACMAAgD/AABQkAT//w==",
//! "1FD06-16": "Bv0BAHg+gD8voKFnAAAAAFpOAwAAAAAACAD/ABYAAgBb//////YD/w==",
//! "1FD06-23": "Bv0BAHg+gD8voKFnAAAAAL1FBAAAAAAACAD/ACMAAgD/1HT//////w==",
//! "1FD07-16": "B/0BAHg+gD8voKFnAAAAANNOBAAAAAAACAD/ABYAAgBb/////3/2Aw==",
//! "1FD07-23": "B/0BAHg+gD8voKFnAAAAAI9kAwAAAAAACAD/ACMAAgD/wNR0/3///w=="
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very specific framing of the data. What in the codebase is providing it to us like that? How and why did base64 enter the picture?

}
}

const POSITION_PGN: u32 = 129025;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto constants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants