@@ -109,7 +109,7 @@ macro_rules! calseg_field {
109
109
// Calibration parameter page wrapper for T with modification counter, init and freeze requests
110
110
111
111
#[ derive( Debug , Copy , Clone ) ]
112
- struct CalPage < T : Sized + Send + Sync + Copy + Clone + ' static > {
112
+ struct CalPage < T : CalPageTrait > {
113
113
ctr : u16 ,
114
114
init_request : bool ,
115
115
freeze_request : bool ,
@@ -155,7 +155,7 @@ impl<T> CalPageTrait for T where T: Sized + Send + Sync + Copy + Clone + 'static
155
155
#[ derive( Debug ) ]
156
156
pub struct CalSeg < T >
157
157
where
158
- T : Sized + Send + Sync + Copy + Clone + ' static ,
158
+ T : CalPageTrait ,
159
159
{
160
160
index : usize ,
161
161
default_page : & ' static T ,
@@ -167,7 +167,7 @@ where
167
167
// Impl register_fields for types which implement RegisterFieldsTrait
168
168
impl < T > CalSeg < T >
169
169
where
170
- T : RegisterFieldsTrait ,
170
+ T : CalPageTrait + RegisterFieldsTrait ,
171
171
{
172
172
/// Register all fields of a calibration segment in the registry
173
173
/// Requires the calibration page to implement XcpTypeDescription
@@ -181,7 +181,7 @@ where
181
181
#[ cfg( feature = "serde" ) ]
182
182
impl < T > CalSeg < T >
183
183
where
184
- T : Sized + Send + Sync + Copy + Clone + ' static + serde :: Serialize + serde :: de :: DeserializeOwned ,
184
+ T : CalPageTrait ,
185
185
{
186
186
/// Load a calibration segment from json file
187
187
/// Requires the calibration page type to implement serde::Serialize + serde::de::DeserializeOwned
@@ -313,7 +313,7 @@ where
313
313
314
314
let file = std:: fs:: File :: create ( path) . unwrap ( ) ;
315
315
let mut writer = std:: io:: BufWriter :: new ( file) ;
316
- let s = serde_json:: to_string ( & self . xcp_page . lock ( ) . page )
316
+ let s = serde_json:: to_string ( & xcp_page. page )
317
317
. map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , format ! ( "serde_json::to_string failed: {}" , e) ) )
318
318
. unwrap ( ) ;
319
319
std:: io:: Write :: write_all ( & mut writer, s. as_ref ( ) ) . unwrap ( ) ;
@@ -399,7 +399,7 @@ where
399
399
400
400
impl < T > CalSegTrait for CalSeg < T >
401
401
where
402
- T : Sized + Send + Sync + Copy + Clone + ' static ,
402
+ T : CalPageTrait ,
403
403
{
404
404
fn get_name ( & self ) -> & ' static str {
405
405
Xcp :: get ( ) . get_calseg_name ( self . index )
@@ -463,7 +463,7 @@ where
463
463
464
464
impl < T > Deref for CalSeg < T >
465
465
where
466
- T : Sized + Send + Sync + Copy + Clone + ' static ,
466
+ T : CalPageTrait ,
467
467
{
468
468
type Target = T ;
469
469
@@ -484,7 +484,7 @@ where
484
484
// This is undefined behaviour, because the reference to XCP data page will escape from its mutex
485
485
impl < T > std:: ops:: DerefMut for CalSeg < T >
486
486
where
487
- T : Sized + Send + Sync + Copy + Clone + ' static ,
487
+ T : CalPageTrait ,
488
488
{
489
489
fn deref_mut ( & mut self ) -> & mut Self :: Target {
490
490
warn ! ( "Unsafe deref mut to XCP page of {}, this is undefined behaviour !!" , self . get_name( ) ) ;
@@ -500,7 +500,7 @@ where
500
500
501
501
impl < T > Clone for CalSeg < T >
502
502
where
503
- T : Sized + Send + Sync + Copy + Clone + ' static ,
503
+ T : CalPageTrait ,
504
504
{
505
505
fn clone ( & self ) -> Self {
506
506
CalSeg {
@@ -519,7 +519,7 @@ where
519
519
520
520
// impl<T> Drop for CalSeg<T>
521
521
// where
522
- // T: Sized + Send + Sync + Copy + Clone + 'static ,
522
+ // T: CalPageTrait ,
523
523
// {
524
524
// fn drop(&mut self) {
525
525
// let clone_count = self.get_clone_count();
@@ -546,7 +546,7 @@ where
546
546
/// Send is reimplemented here
547
547
/// Sync stays disabled, because this would allow to call calseg.sync() from multiple threads with references to the same CalSeg
548
548
// @@@@ unsafe - Implementation of Send marker for CalSeg
549
- unsafe impl < T > Send for CalSeg < T > where T : Sized + Send + Sync + Copy + Clone + ' static { }
549
+ unsafe impl < T > Send for CalSeg < T > where T : CalPageTrait { }
550
550
551
551
//----------------------------------------------------------------------------------------------
552
552
// Test
@@ -592,11 +592,13 @@ mod cal_tests {
592
592
Ok ( ( ) )
593
593
}
594
594
595
+ #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
595
596
#[ derive( Debug , Clone , Copy ) ]
596
597
struct CalPage0 {
597
598
stop : u8 ,
598
599
}
599
600
601
+ #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
600
602
#[ derive( Debug , Clone , Copy , XcpTypeDescription ) ]
601
603
struct CalPageTest {
602
604
test : u8 ,
@@ -774,7 +776,7 @@ mod cal_tests {
774
776
save ( & mut_page, "test_cal_seg.json" ) . unwrap ( ) ;
775
777
776
778
// Create a cal_seg with a mut_page from file test_cal_seg.json aka CAL_PAR_RAM, and a default page from CAL_PAR_FLASH
777
- let mut cal_seg = xcp. create_calseg ( "test_cal_seg" , & CAL_PAR_FLASH ) ;
779
+ let cal_seg = xcp. create_calseg ( "test_cal_seg" , & CAL_PAR_FLASH ) ;
778
780
cal_seg. load ( "test_cal_seg.json" ) . unwrap ( ) ;
779
781
780
782
let cal_seg1 = cal_seg. clone ( ) ;
@@ -855,7 +857,7 @@ mod cal_tests {
855
857
let mut_page: CalPage2 = CalPage2 { a : 1 , b : 3 , c : 5 } ;
856
858
save ( & mut_page, "test1.json" ) . unwrap ( ) ;
857
859
save ( & mut_page, "test2.json" ) . unwrap ( ) ;
858
- let mut cal_seg = xcp. create_calseg ( "test1" , & FLASH_PAGE2 ) ;
860
+ let cal_seg = xcp. create_calseg ( "test1" , & FLASH_PAGE2 ) ;
859
861
cal_seg. load ( "test1.json" ) . unwrap ( ) ;
860
862
cal_seg. sync ( ) ;
861
863
assert_eq ! ( xcp. get_ecu_cal_page( ) , XcpCalPage :: Ram , "XCP should be on RAM page here, there is no independant page switching yet" ) ;
@@ -886,11 +888,10 @@ mod cal_tests {
886
888
887
889
//-----------------------------------------------------------------------------
888
890
// Test cal page freeze
889
-
890
891
#[ cfg( feature = "serde" ) ]
891
892
#[ test]
892
893
fn test_cal_page_freeze ( ) {
893
- let xcp = xcp_test:: test_setup ( log:: LevelFilter :: Warn ) ;
894
+ let xcp = xcp_test:: test_setup ( log:: LevelFilter :: Info ) ;
894
895
895
896
assert ! ( std:: mem:: size_of:: <CalPage1 >( ) == 12 ) ;
896
897
assert ! ( std:: mem:: size_of:: <CalPage2 >( ) == 12 ) ;
@@ -900,7 +901,7 @@ mod cal_tests {
900
901
save ( & mut_page1, "test1.json" ) . unwrap ( ) ;
901
902
902
903
// Create calseg1 from def
903
- let mut calseg1 = xcp. create_calseg ( "test1" , & FLASH_PAGE1 ) ;
904
+ let calseg1 = xcp. create_calseg ( "test1" , & FLASH_PAGE1 ) ;
904
905
calseg1. load ( "test1.json" ) . unwrap ( ) ;
905
906
906
907
test_is_mut ! ( calseg1) ;
@@ -912,7 +913,7 @@ mod cal_tests {
912
913
913
914
// Create calseg2 from freeze file test1.json of calseg1
914
915
std:: fs:: copy ( "test1.json" , "test2.json" ) . unwrap ( ) ;
915
- let mut calseg2 = xcp. create_calseg ( "test2" , & FLASH_PAGE2 ) ;
916
+ let calseg2 = xcp. create_calseg ( "test2" , & FLASH_PAGE2 ) ;
916
917
calseg2. load ( "test2.json" ) . unwrap ( ) ;
917
918
918
919
test_is_mut ! ( calseg2) ;
0 commit comments