@@ -3,57 +3,59 @@ use core::future::Future;
33use embedded_cfu_protocol:: components:: CfuComponentTraits ;
44use embedded_cfu_protocol:: host:: { CfuHostStates , CfuUpdater } ;
55use embedded_cfu_protocol:: protocol_definitions:: * ;
6- use embedded_cfu_protocol:: { CfuImage , CfuWriter , CfuWriterDefault , CfuWriterError } ;
6+ use embedded_cfu_protocol:: writer:: CfuWriterNop ;
7+ use embedded_cfu_protocol:: {
8+ writer:: { CfuWriterAsync , CfuWriterError } ,
9+ CfuImage ,
10+ } ;
711use heapless:: Vec ;
812
913use crate :: CfuError ;
1014
1115/// All host side Cfu traits, in some cases this will originate from a OS driver for CFU
12- pub trait CfuHost : CfuHostStates {
16+ pub trait CfuHost < W > : CfuHostStates < W > {
1317 /// Get all images
1418 fn get_cfu_images < I : CfuImage > ( & self ) -> impl Future < Output = Result < Vec < I , MAX_CMPT_COUNT > , CfuError > > ;
1519 /// Gets the firmware version of all components
16- fn get_all_fw_versions < T : CfuWriter > (
20+ fn get_all_fw_versions (
1721 self ,
18- writer : & mut T ,
22+ writer : & mut W ,
1923 primary_cmpt : ComponentId ,
2024 ) -> impl Future < Output = Result < GetFwVersionResponse , CfuError > > ;
2125 /// Goes through the offer list and returns a slice of offer responses
22- fn process_cfu_offers < ' a , T : CfuWriter > (
26+ fn process_cfu_offers < ' a > (
2327 offer_commands : & ' a [ FwUpdateOffer ] ,
24- writer : & mut T ,
28+ writer : & mut W ,
2529 ) -> impl Future < Output = Result < & ' a [ FwUpdateOfferResponse ] , CfuError > > ;
2630 /// For a specific component, update its content
27- fn update_cfu_content < T : CfuWriter > (
28- writer : & mut T ,
29- ) -> impl Future < Output = Result < FwUpdateContentResponse , CfuError > > ;
31+ fn update_cfu_content ( writer : & mut W ) -> impl Future < Output = Result < FwUpdateContentResponse , CfuError > > ;
3032 /// For a specific image that was updated, validate its content
3133 fn is_cfu_image_valid < I : CfuImage > ( image : I ) -> impl Future < Output = Result < bool , CfuError > > ;
3234}
3335
34- pub struct CfuHostInstance < I : CfuImage , C : CfuComponentTraits > {
36+ pub struct CfuHostInstance < I : CfuImage , C : CfuComponentTraits , W > {
3537 pub updater : CfuUpdater ,
3638 pub images : heapless:: Vec < I , MAX_CMPT_COUNT > ,
37- pub writer : CfuWriterDefault ,
39+ pub writer : W ,
3840 pub primary_cmpt : C ,
3941 pub host_token : HostToken ,
4042}
4143
42- impl < I : CfuImage , C : CfuComponentTraits > CfuHostInstance < I , C > {
44+ impl < I : CfuImage , C : CfuComponentTraits > CfuHostInstance < I , C , CfuWriterNop > {
4345 #[ allow( unused) ]
4446 fn new ( primary_cmpt : C ) -> Self {
4547 Self {
4648 updater : CfuUpdater { } ,
4749 images : Vec :: new ( ) ,
48- writer : CfuWriterDefault :: default ( ) ,
50+ writer : CfuWriterNop ,
4951 primary_cmpt,
5052 host_token : HostToken :: Driver ,
5153 }
5254 }
5355}
5456
55- impl < I : CfuImage , C : CfuComponentTraits > CfuHostStates for CfuHostInstance < I , C > {
56- async fn start_transaction < T : CfuWriter > ( self , _writer : & mut T ) -> Result < FwUpdateOfferResponse , CfuProtocolError > {
57+ impl < I : CfuImage , C : CfuComponentTraits , W : CfuWriterAsync > CfuHostStates < W > for CfuHostInstance < I , C , W > {
58+ async fn start_transaction ( self , _writer : & mut W ) -> Result < FwUpdateOfferResponse , CfuProtocolError > {
5759 let _mock_cmd = FwUpdateOfferInformation :: new ( OfferInformationComponentInfo :: new (
5860 HostToken :: Driver ,
5961 SpecialComponentIds :: Info ,
@@ -62,10 +64,7 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHostStates for CfuHostInstance<I, C>
6264 let mockresponse = FwUpdateOfferResponse :: default ( ) ;
6365 Ok ( mockresponse)
6466 }
65- async fn notify_start_offer_list < T : CfuWriter > (
66- self ,
67- writer : & mut T ,
68- ) -> Result < FwUpdateOfferResponse , CfuProtocolError > {
67+ async fn notify_start_offer_list ( self , writer : & mut W ) -> Result < FwUpdateOfferResponse , CfuProtocolError > {
6968 // Serialize FwUpdateOfferInformation to bytes
7069 let mock_cmd = FwUpdateOfferInformation :: new ( OfferInformationComponentInfo :: new (
7170 HostToken :: Driver ,
@@ -89,10 +88,7 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHostStates for CfuHostInstance<I, C>
8988 }
9089 }
9190
92- async fn notify_end_offer_list < T : CfuWriter > (
93- self ,
94- writer : & mut T ,
95- ) -> Result < FwUpdateOfferResponse , CfuProtocolError > {
91+ async fn notify_end_offer_list ( self , writer : & mut W ) -> Result < FwUpdateOfferResponse , CfuProtocolError > {
9692 let mock_cmd = FwUpdateOfferInformation :: new ( OfferInformationComponentInfo :: new (
9793 HostToken :: Driver ,
9894 SpecialComponentIds :: Info ,
@@ -128,14 +124,14 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHostStates for CfuHostInstance<I, C>
128124 }
129125}
130126
131- impl < I : CfuImage , C : CfuComponentTraits > CfuHost for CfuHostInstance < I , C > {
127+ impl < I : CfuImage , C : CfuComponentTraits , W : CfuWriterAsync > CfuHost < W > for CfuHostInstance < I , C , W > {
132128 async fn get_cfu_images < T : CfuImage > ( & self ) -> Result < Vec < T , MAX_CMPT_COUNT > , CfuError > {
133129 Err ( CfuError :: BadImage )
134130 }
135131
136- async fn get_all_fw_versions < T : CfuWriter > (
132+ async fn get_all_fw_versions (
137133 self ,
138- _writer : & mut T ,
134+ _writer : & mut W ,
139135 primary_cmpt : ComponentId ,
140136 ) -> Result < GetFwVersionResponse , CfuError > {
141137 let mut component_count: u8 = 0 ;
@@ -172,15 +168,15 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHost for CfuHostInstance<I, C> {
172168 }
173169 }
174170
175- async fn process_cfu_offers < ' a , T : CfuWriter > (
171+ async fn process_cfu_offers < ' a > (
176172 _offer_commands : & ' a [ FwUpdateOffer ] ,
177- _writer : & mut T ,
173+ _writer : & mut W ,
178174 ) -> Result < & ' a [ FwUpdateOfferResponse ] , CfuError > {
179175 // TODO
180176 Err ( CfuError :: BadImage )
181177 }
182178
183- async fn update_cfu_content < T : CfuWriter > ( _writer : & mut T ) -> Result < FwUpdateContentResponse , CfuError > {
179+ async fn update_cfu_content ( _writer : & mut W ) -> Result < FwUpdateContentResponse , CfuError > {
184180 Err ( CfuError :: ProtocolError ( CfuProtocolError :: WriterError (
185181 CfuWriterError :: Other ,
186182 ) ) )
0 commit comments