@@ -7,7 +7,10 @@ use std::{
7
7
} ;
8
8
9
9
use clap:: Parser ;
10
- use flipperzero_tools:: { serial, storage} ;
10
+ use flipperzero_tools:: {
11
+ proto:: { pb, pb_app, RpcSession } ,
12
+ serial, storage,
13
+ } ;
11
14
use rand:: { thread_rng, Rng } ;
12
15
13
16
#[ derive( Parser ) ]
@@ -62,17 +65,10 @@ impl From<io::Error> for Error {
62
65
}
63
66
}
64
67
65
- fn wait_for_idle ( serial_cli : & mut serial:: SerialCli ) -> io:: Result < ( ) > {
66
- loop {
67
- serial_cli. send_and_wait_eol ( "loader info" ) ?;
68
- if serial_cli
69
- . consume_response ( ) ?
70
- . contains ( "No application is running" )
71
- {
72
- break Ok ( ( ) ) ;
73
- }
74
- thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
75
- }
68
+ fn wait_for_idle ( session : & mut RpcSession ) -> io:: Result < ( ) > {
69
+ // TODO: need equivalent of "loader info" CLI command.
70
+ thread:: sleep ( Duration :: from_millis ( 2000 ) ) ;
71
+ Ok ( ( ) )
76
72
}
77
73
78
74
fn main ( ) -> Result < ( ) , Error > {
@@ -95,8 +91,8 @@ fn main() -> Result<(), Error> {
95
91
. timeout ( Duration :: from_secs ( 30 ) )
96
92
. open ( )
97
93
. map_err ( Error :: FailedToOpenSerialPort ) ?;
98
- let mut store = storage :: FlipperStorage :: new ( port ) ;
99
- store . start ( ) . map_err ( Error :: FailedToStartSerialInterface ) ?;
94
+ let mut store =
95
+ storage :: FlipperStorage :: new ( port ) . map_err ( Error :: FailedToStartSerialInterface ) ?;
100
96
101
97
// Upload the FAP to a temporary directory.
102
98
let dest_dir =
@@ -109,31 +105,38 @@ fn main() -> Result<(), Error> {
109
105
. send_file ( & cli. fap , & dest_file)
110
106
. map_err ( Error :: FailedToUploadFap ) ?;
111
107
112
- let serial_cli = store. cli_mut ( ) ;
108
+ let session = store. session_mut ( ) ;
113
109
114
110
// Wait for no application to be running.
115
- wait_for_idle ( serial_cli ) ?;
111
+ wait_for_idle ( session ) ?;
116
112
117
113
// Run the FAP.
118
- serial_cli. send_and_wait_eol ( & format ! ( "loader open {} {}" , dest_file, cli. args. join( " " ) ) ) ?;
114
+ session. request (
115
+ 0 ,
116
+ pb:: main:: Content :: AppStartRequest ( pb_app:: StartRequest {
117
+ name : dest_file. to_string ( ) ,
118
+ args : cli. args . join ( " " ) ,
119
+ } ) ,
120
+ |resp| match resp {
121
+ pb:: main:: Content :: Empty ( _) => Ok ( ( ) ) ,
122
+ r => Err ( r) ,
123
+ } ,
124
+ ) ?;
119
125
120
126
// Wait for the FAP to finish.
121
- wait_for_idle ( serial_cli ) ?;
127
+ wait_for_idle ( session ) ?;
122
128
123
129
// Download and print the output file, if present.
124
130
let output_file = storage:: FlipperPath :: from ( "/ext/flipperzero-rs-stdout" ) ;
125
131
if store. exist_file ( & output_file) ? {
126
132
let output = store. read_file ( & output_file) ?;
127
133
io:: stdout ( ) . write_all ( output. as_ref ( ) ) ?;
128
- store. remove ( & output_file) ?;
134
+ store. remove ( & output_file, false ) ?;
129
135
}
130
136
131
137
// Remove the FAP and temporary directory.
132
138
store
133
- . remove ( & dest_file)
134
- . map_err ( |e| Error :: RemoveFailed ( dest_file, e) ) ?;
135
- store
136
- . remove ( & dest_dir)
139
+ . remove ( & dest_dir, true )
137
140
. map_err ( |e| Error :: RemoveFailed ( dest_dir, e) ) ?;
138
141
139
142
Ok ( ( ) )
0 commit comments