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