Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 4 additions & 4 deletions swiftnav/src/coords/ecef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ impl ECEF {
let p = (self.x() * self.x() + self.y() * self.y()).sqrt();

// Compute longitude first, this can be done exactly.
let longitude = if p != 0.0 {
self.y().atan2(self.x())
} else {
let longitude = if p == 0.0 {
0.0
} else {
self.y().atan2(self.x())
};

// If we are close to the pole then convergence is very slow, treat this is a
Expand Down Expand Up @@ -171,7 +171,7 @@ impl ECEF {
/// Rotate this ECEF vector into NED coordinates, at a given
/// reference point. This is approporiate for converting velocity vectors.
///
/// This is the inverse of [NED::ecef_vector_at].
/// This is the inverse of [`NED::ecef_vector_at`].
#[must_use]
pub fn ned_vector_at(&self, point: &ECEF) -> NED {
let m = math::ecef2ned_matrix(point.to_llh());
Expand Down
1 change: 1 addition & 0 deletions swiftnav/src/coords/llh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl LLHRadians {
///
/// Uses the [`WGS84`] Ellipsoid
#[must_use]
#[allow(clippy::many_single_char_names)] // It's math, whatyagonnado?
Copy link

Choose a reason for hiding this comment

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

I think we should use expect here (which will throw an error if someone comes in and fixes the lint, and thus, can be removed). You can also add reasons into both the expect and allow macros 😄

Suggested change
#[allow(clippy::many_single_char_names)] // It's math, whatyagonnado?
#[expect(clippy::many_single_char_names, reason = "It's math, whatyagonnado?")]

Copy link

Choose a reason for hiding this comment

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

nice i didn't know this existed!

pub fn to_ecef(&self) -> ECEF {
let d = WGS84::E * (self.latitude()).sin();
let n = WGS84::A / (1. - d * d).sqrt();
Expand Down
13 changes: 9 additions & 4 deletions swiftnav/src/coords/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
//! Coordinates and conversions
//!
//! These four coordinates types are defined:
//! * [LLHDegrees]/[LLHRadians] - Geodetic coordinates, Latitude Lontitude Height
//! * [ECEF] - Cartesian coordinates, Earth Centered, Earth Fixed
//! * [NED] - Local direction coordinates, North East Down
//! * [AzimuthElevation] - Relative direction coordinates, Azimith Elevation
//! * [`LLHDegrees`]/[`LLHRadians`] - Geodetic coordinates, Latitude Lontitude Height
//! * [`ECEF`] - Cartesian coordinates, Earth Centered, Earth Fixed
//! * [`NED`] - Local direction coordinates, North East Down
//! * [`AzimuthElevation`] - Relative direction coordinates, Azimith Elevation
//!
//! # Geodetic to Cartesian
//!
Expand Down Expand Up @@ -242,6 +242,11 @@ impl Coordinate {
}

/// Transform the coordinate from into a new reference frame
///
/// # Errors
///
/// An error is returned if a transformation from the coordinate's reference frame to the requested
/// reference frame could not be found.
pub fn transform_to(&self, new_frame: ReferenceFrame) -> Result<Self, TransformationNotFound> {
get_transformation(self.reference_frame, new_frame)
.map(|transformation| transformation.transform(self))
Expand Down
2 changes: 1 addition & 1 deletion swiftnav/src/coords/ned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl NED {
/// Rotate a local [`NED`] vector into a [`ECEF`] vector, at a given
/// reference point. This is approporiate for converting velocity vectors.
///
/// This is the inverse of [ECEF::ned_vector_at].
/// This is the inverse of [`ECEF::ned_vector_at`].
#[must_use]
pub fn ecef_vector_at(&self, ref_ecef: &ECEF) -> ECEF {
let m = math::ecef2ned_matrix(ref_ecef.to_llh());
Expand Down
291 changes: 259 additions & 32 deletions swiftnav/src/edc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,262 @@
//! ```

const CRC24Q_TABLE: [u32; 256] = [
0x000000, 0x864CFB, 0x8AD50D, 0x0C99F6, 0x93E6E1, 0x15AA1A, 0x1933EC, 0x9F7F17, 0xA18139,
0x27CDC2, 0x2B5434, 0xAD18CF, 0x3267D8, 0xB42B23, 0xB8B2D5, 0x3EFE2E, 0xC54E89, 0x430272,
0x4F9B84, 0xC9D77F, 0x56A868, 0xD0E493, 0xDC7D65, 0x5A319E, 0x64CFB0, 0xE2834B, 0xEE1ABD,
0x685646, 0xF72951, 0x7165AA, 0x7DFC5C, 0xFBB0A7, 0x0CD1E9, 0x8A9D12, 0x8604E4, 0x00481F,
0x9F3708, 0x197BF3, 0x15E205, 0x93AEFE, 0xAD50D0, 0x2B1C2B, 0x2785DD, 0xA1C926, 0x3EB631,
0xB8FACA, 0xB4633C, 0x322FC7, 0xC99F60, 0x4FD39B, 0x434A6D, 0xC50696, 0x5A7981, 0xDC357A,
0xD0AC8C, 0x56E077, 0x681E59, 0xEE52A2, 0xE2CB54, 0x6487AF, 0xFBF8B8, 0x7DB443, 0x712DB5,
0xF7614E, 0x19A3D2, 0x9FEF29, 0x9376DF, 0x153A24, 0x8A4533, 0x0C09C8, 0x00903E, 0x86DCC5,
0xB822EB, 0x3E6E10, 0x32F7E6, 0xB4BB1D, 0x2BC40A, 0xAD88F1, 0xA11107, 0x275DFC, 0xDCED5B,
0x5AA1A0, 0x563856, 0xD074AD, 0x4F0BBA, 0xC94741, 0xC5DEB7, 0x43924C, 0x7D6C62, 0xFB2099,
0xF7B96F, 0x71F594, 0xEE8A83, 0x68C678, 0x645F8E, 0xE21375, 0x15723B, 0x933EC0, 0x9FA736,
0x19EBCD, 0x8694DA, 0x00D821, 0x0C41D7, 0x8A0D2C, 0xB4F302, 0x32BFF9, 0x3E260F, 0xB86AF4,
0x2715E3, 0xA15918, 0xADC0EE, 0x2B8C15, 0xD03CB2, 0x567049, 0x5AE9BF, 0xDCA544, 0x43DA53,
0xC596A8, 0xC90F5E, 0x4F43A5, 0x71BD8B, 0xF7F170, 0xFB6886, 0x7D247D, 0xE25B6A, 0x641791,
0x688E67, 0xEEC29C, 0x3347A4, 0xB50B5F, 0xB992A9, 0x3FDE52, 0xA0A145, 0x26EDBE, 0x2A7448,
0xAC38B3, 0x92C69D, 0x148A66, 0x181390, 0x9E5F6B, 0x01207C, 0x876C87, 0x8BF571, 0x0DB98A,
0xF6092D, 0x7045D6, 0x7CDC20, 0xFA90DB, 0x65EFCC, 0xE3A337, 0xEF3AC1, 0x69763A, 0x578814,
0xD1C4EF, 0xDD5D19, 0x5B11E2, 0xC46EF5, 0x42220E, 0x4EBBF8, 0xC8F703, 0x3F964D, 0xB9DAB6,
0xB54340, 0x330FBB, 0xAC70AC, 0x2A3C57, 0x26A5A1, 0xA0E95A, 0x9E1774, 0x185B8F, 0x14C279,
0x928E82, 0x0DF195, 0x8BBD6E, 0x872498, 0x016863, 0xFAD8C4, 0x7C943F, 0x700DC9, 0xF64132,
0x693E25, 0xEF72DE, 0xE3EB28, 0x65A7D3, 0x5B59FD, 0xDD1506, 0xD18CF0, 0x57C00B, 0xC8BF1C,
0x4EF3E7, 0x426A11, 0xC426EA, 0x2AE476, 0xACA88D, 0xA0317B, 0x267D80, 0xB90297, 0x3F4E6C,
0x33D79A, 0xB59B61, 0x8B654F, 0x0D29B4, 0x01B042, 0x87FCB9, 0x1883AE, 0x9ECF55, 0x9256A3,
0x141A58, 0xEFAAFF, 0x69E604, 0x657FF2, 0xE33309, 0x7C4C1E, 0xFA00E5, 0xF69913, 0x70D5E8,
0x4E2BC6, 0xC8673D, 0xC4FECB, 0x42B230, 0xDDCD27, 0x5B81DC, 0x57182A, 0xD154D1, 0x26359F,
0xA07964, 0xACE092, 0x2AAC69, 0xB5D37E, 0x339F85, 0x3F0673, 0xB94A88, 0x87B4A6, 0x01F85D,
0x0D61AB, 0x8B2D50, 0x145247, 0x921EBC, 0x9E874A, 0x18CBB1, 0xE37B16, 0x6537ED, 0x69AE1B,
0xEFE2E0, 0x709DF7, 0xF6D10C, 0xFA48FA, 0x7C0401, 0x42FA2F, 0xC4B6D4, 0xC82F22, 0x4E63D9,
0xD11CCE, 0x575035, 0x5BC9C3, 0xDD8538,
0x0000_0000,
0x0086_4CFB,
0x008A_D50D,
0x000C_99F6,
0x0093_E6E1,
0x0015_AA1A,
0x0019_33EC,
0x009F_7F17,
0x00A1_8139,
0x0027_CDC2,
0x002B_5434,
0x00AD_18CF,
0x0032_67D8,
0x00B4_2B23,
0x00B8_B2D5,
0x003E_FE2E,
0x00C5_4E89,
0x0043_0272,
0x004F_9B84,
0x00C9_D77F,
0x0056_A868,
0x00D0_E493,
0x00DC_7D65,
0x005A_319E,
0x0064_CFB0,
0x00E2_834B,
0x00EE_1ABD,
0x0068_5646,
0x00F7_2951,
0x0071_65AA,
0x007D_FC5C,
0x00FB_B0A7,
0x000C_D1E9,
0x008A_9D12,
0x0086_04E4,
0x0000_481F,
0x009F_3708,
0x0019_7BF3,
0x0015_E205,
0x0093_AEFE,
0x00AD_50D0,
0x002B_1C2B,
0x0027_85DD,
0x00A1_C926,
0x003E_B631,
0x00B8_FACA,
0x00B4_633C,
0x0032_2FC7,
0x00C9_9F60,
0x004F_D39B,
0x0043_4A6D,
0x00C5_0696,
0x005A_7981,
0x00DC_357A,
0x00D0_AC8C,
0x0056_E077,
0x0068_1E59,
0x00EE_52A2,
0x00E2_CB54,
0x0064_87AF,
0x00FB_F8B8,
0x007D_B443,
0x0071_2DB5,
0x00F7_614E,
0x0019_A3D2,
0x009F_EF29,
0x0093_76DF,
0x0015_3A24,
0x008A_4533,
0x000C_09C8,
0x0000_903E,
0x0086_DCC5,
0x00B8_22EB,
0x003E_6E10,
0x0032_F7E6,
0x00B4_BB1D,
0x002B_C40A,
0x00AD_88F1,
0x00A1_1107,
0x0027_5DFC,
0x00DC_ED5B,
0x005A_A1A0,
0x0056_3856,
0x00D0_74AD,
0x004F_0BBA,
0x00C9_4741,
0x00C5_DEB7,
0x0043_924C,
0x007D_6C62,
0x00FB_2099,
0x00F7_B96F,
0x0071_F594,
0x00EE_8A83,
0x0068_C678,
0x0064_5F8E,
0x00E2_1375,
0x0015_723B,
0x0093_3EC0,
0x009F_A736,
0x0019_EBCD,
0x0086_94DA,
0x0000_D821,
0x000C_41D7,
0x008A_0D2C,
0x00B4_F302,
0x0032_BFF9,
0x003E_260F,
0x00B8_6AF4,
0x0027_15E3,
0x00A1_5918,
0x00AD_C0EE,
0x002B_8C15,
0x00D0_3CB2,
0x0056_7049,
0x005A_E9BF,
0x00DC_A544,
0x0043_DA53,
0x00C5_96A8,
0x00C9_0F5E,
0x004F_43A5,
0x0071_BD8B,
0x00F7_F170,
0x00FB_6886,
0x007D_247D,
0x00E2_5B6A,
0x0064_1791,
0x0068_8E67,
0x00EE_C29C,
0x0033_47A4,
0x00B5_0B5F,
0x00B9_92A9,
0x003F_DE52,
0x00A0_A145,
0x0026_EDBE,
0x002A_7448,
0x00AC_38B3,
0x0092_C69D,
0x0014_8A66,
0x0018_1390,
0x009E_5F6B,
0x0001_207C,
0x0087_6C87,
0x008B_F571,
0x000D_B98A,
0x00F6_092D,
0x0070_45D6,
0x007C_DC20,
0x00FA_90DB,
0x0065_EFCC,
0x00E3_A337,
0x00EF_3AC1,
0x0069_763A,
0x0057_8814,
0x00D1_C4EF,
0x00DD_5D19,
0x005B_11E2,
0x00C4_6EF5,
0x0042_220E,
0x004E_BBF8,
0x00C8_F703,
0x003F_964D,
0x00B9_DAB6,
0x00B5_4340,
0x0033_0FBB,
0x00AC_70AC,
0x002A_3C57,
0x0026_A5A1,
0x00A0_E95A,
0x009E_1774,
0x0018_5B8F,
0x0014_C279,
0x0092_8E82,
0x000D_F195,
0x008B_BD6E,
0x0087_2498,
0x0001_6863,
0x00FA_D8C4,
0x007C_943F,
0x0070_0DC9,
0x00F6_4132,
0x0069_3E25,
0x00EF_72DE,
0x00E3_EB28,
0x0065_A7D3,
0x005B_59FD,
0x00DD_1506,
0x00D1_8CF0,
0x0057_C00B,
0x00C8_BF1C,
0x004E_F3E7,
0x0042_6A11,
0x00C4_26EA,
0x002A_E476,
0x00AC_A88D,
0x00A0_317B,
0x0026_7D80,
0x00B9_0297,
0x003F_4E6C,
0x0033_D79A,
0x00B5_9B61,
0x008B_654F,
0x000D_29B4,
0x0001_B042,
0x0087_FCB9,
0x0018_83AE,
0x009E_CF55,
0x0092_56A3,
0x0014_1A58,
0x00EF_AAFF,
0x0069_E604,
0x0065_7FF2,
0x00E3_3309,
0x007C_4C1E,
0x00FA_00E5,
0x00F6_9913,
0x0070_D5E8,
0x004E_2BC6,
0x00C8_673D,
0x00C4_FECB,
0x0042_B230,
0x00DD_CD27,
0x005B_81DC,
0x0057_182A,
0x00D1_54D1,
0x0026_359F,
0x00A0_7964,
0x00AC_E092,
0x002A_AC69,
0x00B5_D37E,
0x0033_9F85,
0x003F_0673,
0x00B9_4A88,
0x0087_B4A6,
0x0001_F85D,
0x000D_61AB,
0x008B_2D50,
0x0014_5247,
0x0092_1EBC,
0x009E_874A,
0x0018_CBB1,
0x00E3_7B16,
0x0065_37ED,
0x0069_AE1B,
0x00EF_E2E0,
0x0070_9DF7,
0x00F6_D10C,
0x00FA_48FA,
0x007C_0401,
0x0042_FA2F,
0x00C4_B6D4,
0x00C8_2F22,
0x004E_63D9,
0x00D1_1CCE,
0x0057_5035,
0x005B_C9C3,
0x00DD_8538,
];

/// Calculate Qualcomm 24-bit Cyclical Redundancy Check (CRC-24Q).
Expand All @@ -89,10 +316,10 @@ const CRC24Q_TABLE: [u32; 256] = [
/// Only the lower 24 bits of the initial value are used!
#[must_use]
pub fn compute_crc24q(buf: &[u8], initial_value: u32) -> u32 {
let mut crc = initial_value & 0xFFFFFF;
let mut crc = initial_value & 0x00FF_FFFF;
for &byte in buf {
let index = ((crc >> 16) ^ byte as u32) as usize & 0xFF;
crc = ((crc << 8) & 0xFFFFFF) ^ CRC24Q_TABLE[index];
let index = ((crc >> 16) ^ u32::from(byte)) as usize & 0xFF;
crc = ((crc << 8) & 0x00FF_FFFF) ^ CRC24Q_TABLE[index];
}
crc
}
Expand Down
2 changes: 2 additions & 0 deletions swiftnav/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
//! transform positions in one reference frame into another so you can properly
//! compare positions.

#![warn(clippy::pedantic)]

pub mod coords;
pub mod edc;
mod math;
Expand Down
Loading
Loading