Skip to content

Commit

Permalink
Constants refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhakansson committed Feb 19, 2024
1 parent 6b3ec35 commit 0974870
Show file tree
Hide file tree
Showing 26 changed files with 105 additions and 62 deletions.
24 changes: 12 additions & 12 deletions src/df/dfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ df!(
//TODO: Replace with df_leg_sat_len
//DF006: No. of GPS Satellite Signals Processed
//field_name: satellites_len
df!(
id: df006,
dt: usize,
it: U8,
len: 5,
cap: 31,DF006_CAP,
ord: 0,
);
// df!(
// id: df006,
// dt: usize,
// it: U8,
// len: 5,
// cap: 31,DF006_CAP,
// ord: 0,
// );

//DF007: GPS Divergence-free Smoothing Indicator
//field_name: change to divergence_free_smoothing_flag
Expand Down Expand Up @@ -491,7 +491,7 @@ df!(
dt: usize,
it: U8,
len: 5,
cap: 31, DF053_CAP,
cap: SAT_CAP_1013,
ord: 0,
);

Expand Down Expand Up @@ -3890,7 +3890,7 @@ df!(
dt: usize,
it: U8,
len: 5,
cap: 31,SAT_CAP_LEGACY,
cap: SAT_CAP_LEGACY,
ord: 0,
);

Expand All @@ -3908,7 +3908,7 @@ df!(
//TODO replace for other data fields as well
df_88591_string_with_len!(
id: df_desc_str_w_len,
cap: DESC_CAP, 31,
cap: DESC_CAP,
len_bits: 5,
);

Expand All @@ -3917,7 +3917,7 @@ df_88591_string_with_len!(

df_88591_string_with_len!(
id: df_desc_str_w_len_u8,
cap: DESC_CAP_U8, 31,
cap: DESC_CAP,
len_bits: 8,
);

Expand Down
5 changes: 3 additions & 2 deletions src/df/dfs/df_msg1059_biases.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::df::bit_value::*;
use crate::df::{assembler::Assembler, parser::Parser};
use crate::msg::GpsSigId;
use crate::msg::SAT_CAP_1059;
use crate::rtcm_error::RtcmError;
#[cfg(feature = "test_gen")]
use crate::source_repr::SourceRepr;
Expand Down Expand Up @@ -36,7 +37,7 @@ pub mod export_types {
pub use super::Msg1059CodeBias;
}

pub type DataType = DataVec<Msg1059CodeBias, 390>;
pub type DataType = DataVec<Msg1059CodeBias, SAT_CAP_1059>;

macro_rules! sig_mappings {
[
Expand Down Expand Up @@ -119,7 +120,7 @@ pub fn encode(asm: &mut Assembler, value: &DataType) -> Result<(), RtcmError> {

#[allow(unused)]
pub fn decode(par: &mut Parser) -> Result<DataType, RtcmError> {
let mut value = DataVec::<Msg1059CodeBias, 390>::new();
let mut value = DataVec::<Msg1059CodeBias, SAT_CAP_1059>::new();
let sat_num = par.parse::<U8>(6)?;
for _ in 0..sat_num {
let sat_id = par.parse::<U8>(6)?;
Expand Down
5 changes: 3 additions & 2 deletions src/df/dfs/df_msg1065_biases.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::df::bit_value::*;
use crate::df::{assembler::Assembler, parser::Parser};
use crate::msg::GloSigId;
use crate::msg::SAT_CAP_1065;
use crate::rtcm_error::RtcmError;
#[cfg(feature = "test_gen")]
use crate::source_repr::SourceRepr;
Expand Down Expand Up @@ -36,7 +37,7 @@ pub mod export_types {
pub use super::Msg1065CodeBias;
}

pub type DataType = DataVec<Msg1065CodeBias, 390>;
pub type DataType = DataVec<Msg1065CodeBias, SAT_CAP_1065>;

macro_rules! sig_mappings {
[
Expand Down Expand Up @@ -111,7 +112,7 @@ pub fn encode(asm: &mut Assembler, value: &DataType) -> Result<(), RtcmError> {

#[allow(unused)]
pub fn decode(par: &mut Parser) -> Result<DataType, RtcmError> {
let mut value = DataVec::<Msg1065CodeBias, 390>::new();
let mut value = DataVec::<Msg1065CodeBias, SAT_CAP_1065>::new();
let sat_num = par.parse::<U8>(6)?;
for _ in 0..sat_num {
let sat_id = par.parse::<U8>(5)?;
Expand Down
27 changes: 15 additions & 12 deletions src/df/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ macro_rules! df {
$(res: $res:expr,)?
$(bias: $bias:expr,)?
$(round: $round:literal,)?
$(cap: $cap:expr,$cap_name:ident,)?
$(cap: $cap_name:ident,)?
$(inv: $inv:literal,)?
$(ord: $ord:literal,)?) => {

pub mod $id {
use $crate::df::bit_value::*;
use $crate::df::{assembler::Assembler, parser::Parser};
use $crate::rtcm_error::RtcmError;
#[allow(unused)]
use $crate::msg::*;

pub mod export_types {
$(pub use super::$cap_name;)?
// $(pub use super::$cap_name;)?
}

$(
Expand Down Expand Up @@ -136,9 +138,9 @@ macro_rules! df {
$(
//let it_val = val_gen.len_rng.gen::<<$it as BitValue>::ValueType>() % ($cap + 1);
let it_val = if val_gen.len_rng.gen::<u64>() == u64::MAX {
$cap
$cap_name as <$it as BitValue>::ValueType
} else {
val_gen.len_rng.gen::<<$it as BitValue>::ValueType>() % ($cap + 1)
val_gen.len_rng.gen::<<$it as BitValue>::ValueType>() % ($cap_name as <$it as BitValue>::ValueType + 1)
};
)?
asm.put::<$it>(it_val, $len)?;
Expand All @@ -158,8 +160,8 @@ macro_rules! df {
}
$(
#[allow(unused)]
pub const $cap_name:usize = $cap;
pub use $cap_name as CAP;
// pub const $cap_name:usize = $cap;
pub const CAP:usize = $crate::msg::$cap_name;
)?
}
};
Expand Down Expand Up @@ -241,19 +243,20 @@ macro_rules! df {
macro_rules! df_88591_string_with_len {
(
id: $id:ident,
cap: $cap_name:ident, $cap:literal,
cap: $cap_name:ident,
len_bits: $len_bits:literal,
) => {
pub mod $id {
//use super::*;
use $crate::df::{assembler::Assembler, bit_value::U8, parser::Parser};
use $crate::msg::*;
use $crate::rtcm_error::RtcmError;
use $crate::util::Df88591String;

pub const $cap_name: usize = $cap;
// pub const $cap_name: usize = $cap;

pub mod export_types {
pub use super::$cap_name;
// pub use super::$cap_name;
}
#[allow(unused)]
pub type DataType = Df88591String<$cap_name>;
Expand Down Expand Up @@ -292,9 +295,9 @@ macro_rules! df_88591_string_with_len {
RR: rand::Rng,
{
let len = if val_gen.len_rng.gen::<u64>() == u64::MAX {
$cap
$cap_name as u8
} else {
val_gen.len_rng.gen::<u8>() % ($cap + 1)
val_gen.len_rng.gen::<u8>() % ($cap_name as u8 + 1)
};
asm.put::<U8>(len, $len_bits)?;
let mut value: DataType = Df88591String::new();
Expand All @@ -312,4 +315,4 @@ macro_rules! df_88591_string_with_len {
}

pub mod dfs;
pub use dfs::*;
// pub use dfs::*;
61 changes: 50 additions & 11 deletions src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ macro_rules! msg {
use super::*; //Do not remove

pub mod export_types {
$(pub use super::$frag_id::export_types::*;)+
$(
#[allow(unused)]
pub use super::$frag_id::export_types::*;
)+

pub use super::$type_name;
}
Expand Down Expand Up @@ -108,8 +111,15 @@ macro_rules! msg_len_middle {
use super::*; //Do not remove

pub mod export_types {
$(pub use super::$frag_id1::export_types::*;)+
$(pub use super::$frag_id2::export_types::*;)+
$(
#[allow(unused)]
pub use super::$frag_id1::export_types::*;
)+
$(
#[allow(unused)]
pub use super::$frag_id2::export_types::*;
)+
#[allow(unused)]
pub use super::$len_df_id::export_types::*;
pub use super::$vec_frag_id::export_types::*;

Expand Down Expand Up @@ -219,6 +229,7 @@ macro_rules! frag_vec {
use $crate::util::DataVec;

pub mod export_types {
#[allow(unused)]
pub use super::$frag_id::export_types::*;
}

Expand Down Expand Up @@ -267,20 +278,21 @@ macro_rules! frag_vec_with_len {
(
id: $id:ident,
frag_id: $frag_id:ident,
cap: $cap_name:ident, $cap:literal,
cap: $cap_name:ident,
len_bits: $len_bits:literal,
) => {
pub mod $id {
use super::*;
use $crate::df::bit_value::U16;
use $crate::df::{assembler::Assembler, parser::Parser};
use $crate::msg::*;
use $crate::rtcm_error::RtcmError;
use $crate::util::DataVec;

pub const $cap_name: usize = $cap;
// pub const $cap_name: usize = $cap;

pub mod export_types {
pub use super::$cap_name;
// pub use super::$cap_name;
pub use super::$frag_id::export_types::*;
}

Expand All @@ -296,7 +308,7 @@ macro_rules! frag_vec_with_len {
}
pub fn decode(par: &mut Parser) -> Result<DataType, RtcmError> {
let len = par.parse::<U16>($len_bits)? as usize;
if len > $cap {
if len > $cap_name {
return Err(RtcmError::CapacityExceeded);
}
let mut value = DataVec::new();
Expand All @@ -319,9 +331,9 @@ macro_rules! frag_vec_with_len {
RR: rand::Rng,
{
let len = if val_gen.len_rng.gen::<u64>() == u64::MAX {
$cap
$cap_name
} else {
val_gen.len_rng.gen::<u16>() % ($cap + 1)
val_gen.len_rng.gen::<u16>() % ($cap_name + 1)
};
asm.put::<U16>(len, $len_bits)?;
for _ in 0..len {
Expand Down Expand Up @@ -411,6 +423,7 @@ macro_rules! msm_data_seg_frag {
use $crate::{Deserialize, Serialize};

pub mod export_types {
#[allow(unused)]
pub use super::$sat_id::export_types::*;
pub use super::$sig_id::export_types::*;

Expand Down Expand Up @@ -637,7 +650,10 @@ macro_rules! msm_sat_frag {
use $crate::{Serialize,Deserialize};

pub mod export_types {
$(pub use super::$frag_id::export_types::*;)+
$(
#[allow(unused)]
pub use super::$frag_id::export_types::*;
)+

pub use super::$type_name;
}
Expand Down Expand Up @@ -739,7 +755,10 @@ macro_rules! msm_sig_frag {
use $crate::{Serialize,Deserialize};

pub mod export_types {
$(pub use super::$frag_id::export_types::*;)+
$(
#[allow(unused)]
pub use super::$frag_id::export_types::*;
)+

pub use super::$type_name;
}
Expand Down Expand Up @@ -869,6 +888,26 @@ fn cell_mask_id_vec(
Some((sat_vec, cell_vec))
}

//Common constants
pub const DESC_CAP: usize = 31;
pub const SAT_CAP_LEGACY: usize = 31;
pub const SAT_CAP_MAC: usize = 15;
pub const SAT_CAP_FKP: usize = 31;
pub const SAT_CAP_RES: usize = 31;
pub const SAT_CAP_1013: usize = 31;
pub const SAT_CAP_1057: usize = 60;
pub const SAT_CAP_1058: usize = 63;
pub const SAT_CAP_1059: usize = 390;
pub const SAT_CAP_1060: usize = 39;
pub const SAT_CAP_1061: usize = 63;
pub const SAT_CAP_1062: usize = 63;
pub const SAT_CAP_1063: usize = 60;
pub const SAT_CAP_1064: usize = 63;
pub const SAT_CAP_1065: usize = 390;
pub const SAT_CAP_1066: usize = 39;
pub const SAT_CAP_1067: usize = 63;
pub const SAT_CAP_1068: usize = 63;

#[cfg(any(
feature = "msg1071",
feature = "msg1072",
Expand Down
5 changes: 2 additions & 3 deletions src/msg/msg1013.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

msg!(
id: msg1013_msg_id,
type_name: Msg1013MsgId,
Expand All @@ -12,7 +11,7 @@ msg!(
frag_vec!(
id: msg_1013_msg_id_vec,
frag_id: msg1013_msg_id,
cap_name: DF053_CAP,
cap_name: SAT_CAP_1013,
);

msg!(
Expand All @@ -26,4 +25,4 @@ msg!(
(leap_seconds_gps_utc_s, df054),
(message_id_announcements, msg_1013_msg_id_vec, message_id_announcements_len)
],
);
);
2 changes: 1 addition & 1 deletion src/msg/msg1015.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ msg! (
frag_vec_with_len!(
id: msg1015_sat_vec,
frag_id: msg1015_sat,
cap: SAT_CAP_1015, 15,
cap: SAT_CAP_MAC,
len_bits: 4,
);

Expand Down
2 changes: 1 addition & 1 deletion src/msg/msg1016.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ msg! (
frag_vec_with_len!(
id: msg1016_sat_vec,
frag_id: msg1016_sat,
cap: SAT_CAP_1016, 15,
cap: SAT_CAP_MAC,
len_bits: 4,
);

Expand Down
2 changes: 1 addition & 1 deletion src/msg/msg1017.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ msg! (
frag_vec_with_len!(
id: msg1017_sat_vec,
frag_id: msg1017_sat,
cap: SAT_CAP_1017, 15,
cap: SAT_CAP_MAC,
len_bits: 4,
);

Expand Down
2 changes: 1 addition & 1 deletion src/msg/msg1030.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ msg! (
frag_vec_with_len!(
id: msg1030_sat_vec,
frag_id: msg1030_sat,
cap: SAT_CAP_1030, 31,
cap: SAT_CAP_RES,
len_bits: 5,
);

Expand Down
Loading

0 comments on commit 0974870

Please sign in to comment.