Skip to content

Commit

Permalink
add error handling for delete operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
liamhays committed Feb 15, 2024
1 parent 0cd0308 commit a22e2de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/flipper_ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,10 @@ impl FlipperBle {

if pb_response.1.command_status == flipper_pb::flipper::CommandStatus::OK.into() {
Ok(())
} else if pb_response.1.command_status == flipper_pb::flipper::CommandStatus::ERROR_STORAGE_INVALID_NAME.into() {
Err("Invalid name specified!".into())
} else {
info!("received response {:?}", pb_response.1.command_id);
Err("".into())
Err(format!("Flipper returned unexpected response: {:?}", pb_response).into())
}
}

Expand All @@ -456,7 +457,9 @@ impl FlipperBle {
let pb_response = ProtobufCodec::parse_response(&response)?;
debug!("response received: {:?}", pb_response);

// TODO: what is the response if you try to open a nonexistent file in a correctly named app?
// If you try to load a nonexistent file in an app, the app is
// the one that displays an error. No error is relayed back
// over RPC.
if pb_response.1.command_status == flipper_pb::flipper::CommandStatus::OK.into() {
Ok(())
} else if pb_response.1.command_status == flipper_pb::flipper::CommandStatus::ERROR_INVALID_PARAMETERS.into() {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async fn main() {
},

Commands::Launch { app, args } => {
println!("running with args {:?}", args);
//println!("running with args {:?}", args);
match flipper.launch(app, args).await {
Ok(()) => {
info!("launched app successfully");
Expand Down Expand Up @@ -161,7 +161,7 @@ async fn main() {
info!("deleted file successfully");
},
Err(e) => {
error!("failed to send file: {}", e);
error!("failed to delete file: {}", e);
}
};
},
Expand Down
8 changes: 5 additions & 3 deletions src/protobuf_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::flipper_pb;
//
// This number also affects things like lag, and 350 is a good number
// that seems to just work.
pub const PROTOBUF_BLE_MTU_SIZE: usize = 350;

//const PROTOBUF_BLE_MTU_SIZE: usize = 350;
pub const PROTOBUF_BLE_MTU_SIZE: usize = 25;
// number of file bytes to write per cycle
const PROTOBUF_FILE_WRITE_CHUNK_SIZE: usize = 512;

Expand Down Expand Up @@ -344,7 +344,9 @@ impl ProtobufCodec {
/// Returns a Vec<u8> of an encoded SetDatetimeRequest with the
/// datetime arguments set to the fields in `datetime`. No need
/// for chunking, this command is always the same size.
pub fn create_set_datetime_request_packet(&mut self, datetime: chrono::DateTime<chrono::FixedOffset>) -> Result<Vec<u8>, Box<dyn Error>> {
pub fn create_set_datetime_request_packet(
&mut self,
datetime: chrono::DateTime<chrono::FixedOffset>) -> Result<Vec<u8>, Box<dyn Error>> {

// SetDatetimeRequest is a thin wrapper around
// FuriHalRtcDateTime which itself is a thin wrapper around
Expand Down

0 comments on commit a22e2de

Please sign in to comment.