@@ -28,7 +28,7 @@ pub enum WeightingMode {
28
28
// alpha in [1.0, 2.0], smoothed over time, scaled up by 1,000,000 to avoid floating-point math
29
29
Dynamic {
30
30
alpha : u64 , // current alpha (fixed-point, 1,000,000–2,000,000)
31
- filter_k : u64 , // default: 611,000
31
+ filter_k : u64 , // default: 611,015
32
32
tc_ms : u64 , // IIR time-constant (ms)
33
33
} ,
34
34
}
@@ -101,8 +101,8 @@ impl PushActiveSet {
101
101
}
102
102
103
103
pub ( crate ) fn apply_cfg ( & mut self , cfg : & WeightingConfig ) {
104
- info ! ( "greg: apply_cfg" ) ;
105
- match ( & mut self . mode , WeightingConfigTyped :: from ( cfg ) ) {
104
+ let config_type = WeightingConfigTyped :: from ( cfg ) ;
105
+ match ( & mut self . mode , config_type ) {
106
106
( WeightingMode :: Static , WeightingConfigTyped :: Static ) => ( ) ,
107
107
( current_mode, WeightingConfigTyped :: Static ) => {
108
108
// Dynamic -> Static: Switch mode
@@ -115,7 +115,6 @@ impl PushActiveSet {
115
115
} ,
116
116
WeightingConfigTyped :: Dynamic { tc } ,
117
117
) => {
118
- info ! ( "greg: apply_cfg dynamic -> dynamic" ) ;
119
118
// Dynamic -> Dynamic: Update parameters if needed
120
119
let new_tc_ms = match tc {
121
120
TimeConstant :: Value ( ms) => ms,
@@ -127,10 +126,9 @@ impl PushActiveSet {
127
126
info ! ( "Recomputed filter K = {} (tc_ms = {})" , * filter_k, * tc_ms) ;
128
127
}
129
128
}
130
- ( WeightingMode :: Static , WeightingConfigTyped :: Dynamic { .. } ) => {
131
- // Static -> Dynamic: Switch mode
132
- info ! ( "Switching mode: Static -> Dynamic" ) ;
133
- self . mode = WeightingMode :: from ( WeightingConfigTyped :: from ( cfg) ) ;
129
+ ( current_mode, WeightingConfigTyped :: Dynamic { .. } ) => {
130
+ info ! ( "Switching mode: {:?} -> Dynamic" , current_mode) ;
131
+ self . mode = WeightingMode :: from ( config_type) ;
134
132
if let WeightingMode :: Dynamic {
135
133
filter_k, tc_ms, ..
136
134
} = self . mode
@@ -771,16 +769,21 @@ mod tests {
771
769
}
772
770
}
773
771
772
+ #[ test]
773
+ fn test_record_size ( ) {
774
+ assert_eq ! (
775
+ bincode:: serialized_size( & WeightingConfig :: default ( ) ) . unwrap( ) ,
776
+ 58
777
+ ) ;
778
+ }
779
+
774
780
#[ test]
775
781
fn test_apply_cfg_static_to_static ( ) {
776
782
// Static -> Static: No change
777
783
let mut active_set = PushActiveSet :: new ( WeightingMode :: Static ) ;
778
784
assert_eq ! ( active_set. mode, WeightingMode :: Static ) ;
779
785
780
- active_set. apply_cfg ( & WeightingConfig {
781
- weighting_mode : WEIGHTING_MODE_STATIC ,
782
- tc_ms : 0 ,
783
- } ) ;
786
+ active_set. apply_cfg ( & WeightingConfig :: new_for_test ( WEIGHTING_MODE_STATIC , 0 ) ) ;
784
787
assert_eq ! ( active_set. mode, WeightingMode :: Static ) ;
785
788
}
786
789
@@ -790,10 +793,7 @@ mod tests {
790
793
let mut active_set = PushActiveSet :: new_dynamic ( ) ;
791
794
assert ! ( matches!( active_set. mode, WeightingMode :: Dynamic { .. } ) ) ;
792
795
793
- active_set. apply_cfg ( & WeightingConfig {
794
- weighting_mode : WEIGHTING_MODE_STATIC ,
795
- tc_ms : 0 ,
796
- } ) ;
796
+ active_set. apply_cfg ( & WeightingConfig :: new_for_test ( WEIGHTING_MODE_STATIC , 0 ) ) ;
797
797
assert_eq ! ( active_set. mode, WeightingMode :: Static ) ;
798
798
}
799
799
@@ -803,10 +803,7 @@ mod tests {
803
803
let mut active_set = PushActiveSet :: new ( WeightingMode :: Static ) ;
804
804
assert_eq ! ( active_set. mode, WeightingMode :: Static ) ;
805
805
806
- let config = WeightingConfig {
807
- weighting_mode : WEIGHTING_MODE_DYNAMIC ,
808
- tc_ms : 0 ,
809
- } ;
806
+ let config = WeightingConfig :: new_for_test ( WEIGHTING_MODE_DYNAMIC , 0 ) ;
810
807
active_set. apply_cfg ( & config) ;
811
808
812
809
match active_set. mode {
@@ -832,10 +829,7 @@ mod tests {
832
829
let mut active_set = PushActiveSet :: new_dynamic ( ) ;
833
830
let original_mode = active_set. mode ;
834
831
835
- let config = WeightingConfig {
836
- weighting_mode : WEIGHTING_MODE_DYNAMIC ,
837
- tc_ms : 0 ,
838
- } ;
832
+ let config = WeightingConfig :: new_for_test ( WEIGHTING_MODE_DYNAMIC , 0 ) ;
839
833
active_set. apply_cfg ( & config) ;
840
834
841
835
// Mode should be unchanged since tc is the same
@@ -849,10 +843,7 @@ mod tests {
849
843
850
844
// Change to a different tc value
851
845
let new_tc_ms = 45_000 ;
852
- let config = WeightingConfig {
853
- weighting_mode : WEIGHTING_MODE_DYNAMIC ,
854
- tc_ms : new_tc_ms,
855
- } ;
846
+ let config = WeightingConfig :: new_for_test ( WEIGHTING_MODE_DYNAMIC , new_tc_ms) ;
856
847
active_set. apply_cfg ( & config) ;
857
848
858
849
match active_set. mode {
@@ -878,37 +869,31 @@ mod tests {
878
869
let mut active_set = PushActiveSet :: new ( WeightingMode :: Static ) ;
879
870
880
871
// Static -> Dynamic
881
- active_set. apply_cfg ( & WeightingConfig {
882
- weighting_mode : WEIGHTING_MODE_DYNAMIC ,
883
- tc_ms : 20_000 ,
884
- } ) ;
872
+ active_set. apply_cfg ( & WeightingConfig :: new_for_test (
873
+ WEIGHTING_MODE_DYNAMIC ,
874
+ 20_000 ,
875
+ ) ) ;
885
876
assert ! ( matches!(
886
877
active_set. mode,
887
878
WeightingMode :: Dynamic { tc_ms: 20_000 , .. }
888
879
) ) ;
889
880
890
881
// Dynamic -> Dynamic (change tc)
891
- active_set. apply_cfg ( & WeightingConfig {
892
- weighting_mode : WEIGHTING_MODE_DYNAMIC ,
893
- tc_ms : 40_000 ,
894
- } ) ;
882
+ active_set. apply_cfg ( & WeightingConfig :: new_for_test (
883
+ WEIGHTING_MODE_DYNAMIC ,
884
+ 40_000 ,
885
+ ) ) ;
895
886
assert ! ( matches!(
896
887
active_set. mode,
897
888
WeightingMode :: Dynamic { tc_ms: 40_000 , .. }
898
889
) ) ;
899
890
900
891
// Dynamic -> Static
901
- active_set. apply_cfg ( & WeightingConfig {
902
- weighting_mode : WEIGHTING_MODE_STATIC ,
903
- tc_ms : 0 ,
904
- } ) ;
892
+ active_set. apply_cfg ( & WeightingConfig :: new_for_test ( WEIGHTING_MODE_STATIC , 0 ) ) ;
905
893
assert_eq ! ( active_set. mode, WeightingMode :: Static ) ;
906
894
907
895
// Static -> Dynamic (with default tc)
908
- active_set. apply_cfg ( & WeightingConfig {
909
- weighting_mode : WEIGHTING_MODE_DYNAMIC ,
910
- tc_ms : 0 ,
911
- } ) ;
896
+ active_set. apply_cfg ( & WeightingConfig :: new_for_test ( WEIGHTING_MODE_DYNAMIC , 0 ) ) ;
912
897
assert ! (
913
898
matches!( active_set. mode, WeightingMode :: Dynamic { tc_ms, .. } if tc_ms == DEFAULT_TC_MS )
914
899
) ;
@@ -922,10 +907,7 @@ mod tests {
922
907
let test_cases = [ 10_000 , 30_000 , 60_000 , 120_000 ] ;
923
908
924
909
for tc_ms in test_cases {
925
- let config = WeightingConfig {
926
- weighting_mode : WEIGHTING_MODE_DYNAMIC ,
927
- tc_ms,
928
- } ;
910
+ let config = WeightingConfig :: new_for_test ( WEIGHTING_MODE_DYNAMIC , tc_ms) ;
929
911
active_set. apply_cfg ( & config) ;
930
912
931
913
let expected_filter_k = lpf:: compute_k ( REFRESH_PUSH_ACTIVE_SET_INTERVAL_MS , tc_ms) ;
0 commit comments