File tree 1 file changed +21
-2
lines changed
1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -97,12 +97,31 @@ impl Ppk2 {
97
97
Ok ( response)
98
98
}
99
99
100
- /// Get the device metadata.
101
- pub fn get_metadata ( & mut self ) -> Result < Metadata > {
100
+ fn try_get_metadata ( & mut self ) -> Result < Metadata > {
102
101
let response = self . send_command ( Command :: GetMetaData ) ?;
103
102
Metadata :: from_bytes ( & response)
104
103
}
105
104
105
+ /// Get the device metadata.
106
+ pub fn get_metadata ( & mut self ) -> Result < Metadata > {
107
+ let mut result: Result < Metadata > = Err ( Error :: Parse ( "Metadata" . to_string ( ) ) ) ;
108
+
109
+ // Retry a few times, as the metadata command sometimes fails
110
+ for _ in 0 ..3 {
111
+ match self . try_get_metadata ( ) {
112
+ Ok ( metadata) => {
113
+ result = Ok ( metadata) ;
114
+ break ;
115
+ }
116
+ Err ( e) => {
117
+ tracing:: warn!( "Error fetching metadata: {:?}. Retrying.." , e) ;
118
+ }
119
+ }
120
+ }
121
+
122
+ result
123
+ }
124
+
106
125
/// Enable or disable the device power.
107
126
pub fn set_device_power ( & mut self , power : DevicePower ) -> Result < ( ) > {
108
127
self . send_command ( Command :: DeviceRunningSet ( power) ) ?;
You can’t perform that action at this time.
0 commit comments