@@ -169,17 +169,24 @@ impl UbootShell {
169169
170170 pub fn cmd_without_reply ( & mut self , cmd : & str ) -> Result < ( ) > {
171171 self . tx ( ) . write_all ( cmd. as_bytes ( ) ) ?;
172- self . tx ( ) . write_all ( "\r \ n " . as_bytes ( ) ) ?;
172+ self . tx ( ) . write_all ( "\n " . as_bytes ( ) ) ?;
173173 self . tx ( ) . flush ( ) ?;
174- self . wait_for_reply ( cmd) ?;
175- debug ! ( "cmd ok" ) ;
174+ // self.wait_for_reply(cmd)?;
175+ // debug!("cmd ok");
176176 Ok ( ( ) )
177177 }
178178
179179 pub fn cmd ( & mut self , cmd : & str ) -> Result < String > {
180+ info ! ( "cmd: {cmd}" ) ;
180181 self . cmd_without_reply ( cmd) ?;
181182 let perfix = self . perfix . clone ( ) ;
182- self . wait_for_reply ( & perfix)
183+ let res = self
184+ . wait_for_reply ( & perfix) ?
185+ . trim_end ( )
186+ . trim_end_matches ( self . perfix . as_str ( ) . trim ( ) )
187+ . trim_end ( )
188+ . to_string ( ) ;
189+ Ok ( res)
183190 }
184191
185192 pub fn set_env ( & mut self , name : impl Into < String > , value : impl Into < String > ) -> Result < ( ) > {
@@ -190,18 +197,25 @@ impl UbootShell {
190197 pub fn env ( & mut self , name : impl Into < String > ) -> Result < String > {
191198 let name = name. into ( ) ;
192199 let s = self . cmd ( & format ! ( "echo ${}" , name) ) ?;
193- if s. is_empty ( ) {
194- return Err ( Error :: new (
200+ let sp = s
201+ . split ( "\n " )
202+ . filter ( |s| !s. trim ( ) . is_empty ( ) )
203+ . collect :: < Vec < _ > > ( ) ;
204+ let s = sp
205+ . last ( )
206+ . ok_or ( Error :: new (
195207 ErrorKind :: NotFound ,
196208 format ! ( "env {} not found" , name) ,
197- ) ) ;
198- }
209+ ) ) ?
210+ . to_string ( ) ;
199211 Ok ( s)
200212 }
201213
202214 pub fn env_int ( & mut self , name : impl Into < String > ) -> Result < usize > {
203215 let name = name. into ( ) ;
204216 let line = self . env ( & name) ?;
217+ debug ! ( "env {name} = {line}" ) ;
218+
205219 parse_int ( & line) . ok_or ( Error :: new (
206220 ErrorKind :: InvalidData ,
207221 format ! ( "env {name} is not a number" ) ,
0 commit comments