Skip to content

Conversation

jbangelo
Copy link
Collaborator

@jbangelo jbangelo commented Aug 20, 2025

The second chunk of changes from #122.

This re-implements the GNSS signal related types of functionality in native Rust

What's been changed

  • The signal module has been broken up into multiple files, though these extra files are not visible via the public API
  • The various string conversion functions have been moved to utilize the derive macros from the strum crate, but the actual string values have remained the same
  • Conversions to/from swiftnav-sys integer types has been replaced with conversions to/from native Rust integer types
  • The conversion error types have changed to no longer contain the swiftnav-sys types and instead contain native Rust types
  • The error types use the thiserror crate to reduce boiler plate code

What's been removed

  • Code::sig_count()
  • Code::chip_count()
  • Code::chip_rate()

What's been added

  • The signal::consts module
  • Constellation::sat_count()
  • Constellation::first_prn()
  • Code::get_carrier_frequency()
  • Code::get_glo_channel_frequency()
  • GnssSignal::carrier_frequency()
  • GnssSignal::get_glo_channel_frequency()

@jbangelo jbangelo force-pushed the jbangelo/riir-signal branch 4 times, most recently from da5632c to ceeb98f Compare August 22, 2025 00:40
@jbangelo jbangelo marked this pull request as ready for review August 22, 2025 01:39
@jbangelo jbangelo requested a review from a team as a code owner August 22, 2025 01:39
@jbangelo jbangelo force-pushed the jbangelo/riir-signal branch from ceeb98f to 1a3e6a8 Compare August 22, 2025 01:40
@jbangelo jbangelo force-pushed the jbangelo/riir-signal branch from 1a3e6a8 to 636a4ec Compare August 22, 2025 01:41
Copy link
Contributor

@JADC362 JADC362 left a comment

Choose a reason for hiding this comment

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

Made a first initial review, will continue later

pub const NUM_SIGNALS_QZS_L5: u16 = NUM_SATS_QZS;

/// Total number of signals in the GPS constellation.
pub const NUM_SIGNALS_GPS: u16 = 2 * NUM_SIGNALS_GPS_L1CA
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps should we set the 2 and 3 not a magical numbers but with a formal constant name. Could be:

NUM_COMPONENTS_IQ_SIGNAL = 2;
NUM_COMPONENTS_IQX_SIGNAL = 3;

or something like that. It will make it clear the number of components each signal have by setting a name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if that'll really make it any more clear, especially when it's not going to be uniform and not all of the signal naming schemes use I/Q/X

/// Frequency range between two adjacent GLO channel in Hz for L1 band
pub const GLO_L1_DELTA_HZ: f64 = 5.625e5;
/// Frequency range between two adjacent GLO channel in Hz for L2 band
pub const GLO_L2_DELTA_HZ: f64 = 4.375e5;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've always thought why we don't add somewhere in the documentation of these kind of files from where do we get these constants. It doesn't have to be a really detail reference, but for example at the top of the document put something like:

Information extracted from files:
RTCM version 3.0 ...
BDS reference document...

This way, it's easier for future maintainers to know which files and versions of them have been used to populate all the constants we see here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically all of these come from the constellation ICDs I believe

Copy link
Contributor

@JADC362 JADC362 left a comment

Choose a reason for hiding this comment

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

Perfect! I left some comments mostly related to improve the overall documentation of the modules so it's easy for developers to compile the documentation and easily understand how to use these structs / enums.

@@ -0,0 +1,7 @@
pub(crate) const fn compile_time_max_u16(a: u16, b: u16) -> u16 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I may not understand the purpose of this module and function. Could you add a module documentation and function documentation for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a doc comment. Basically we want to find the constellation with the most number of satellites, so we use this here to find the largest value at compile time.

// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a module documentation with a small inline example? The below one is just an example, perhaps the documentation could contain a description of what the module offers and how to interact with it, using the examples as guidance.

//! Signal module
//!
//! This module provides the `GnssSignal`, `Code` and `Constellation` objects, provided with utility functions for easy handling and manipulation.
//!
//! # Example
//!
//! ```rust
//! // Create new GnssSignal
//! let signal = GnssSignal::new(1, Code::Bds3B5x);
//! println!("{}", signal);
//! ```

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added some explanation and example code.

Hash,
strum::AsRefStr,
strum::Display,
strum::EnumIter,

Choose a reason for hiding this comment

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

It bothers me that this functionality still has not landed in serde yet as it seems like it would be pretty straightfoward to add and many projects end up using both serde and strum

/// The maximum number of satellites in a single constellation
pub const MAX_NUM_SATS: u16 = compile_time_max_u16(
NUM_SATS_GPS,
compile_time_max_u16(

Choose a reason for hiding this comment

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

Interesting way to avoid lazy execution 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems like const traits are still being worked on so there isn't any generic const comparisons in the standard library. I did find a couple of crates which provide this via proc macros, but this seemed the most straight forward option.

@jbangelo jbangelo merged commit 9693bcd into master Aug 26, 2025
6 checks passed
@jbangelo jbangelo deleted the jbangelo/riir-signal branch August 26, 2025 04:06
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.

3 participants