From 61544fd23fbcb8412ab2b069af7e86a3e7d8e58d Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 1 Mar 2021 00:43:25 -0800 Subject: [PATCH] Move download to rust --- radio.c | 16 ---------------- src/lib.rs | 6 ++++-- src/radio.rs | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/radio.c b/radio.c index f54ece7..4ed3555 100644 --- a/radio.c +++ b/radio.c @@ -81,22 +81,6 @@ void radio_print_version(radio_device_t* dev, FILE *out) dev->print_version(dev, out); } -// -// Read firmware image from the device. -// -void radio_download(radio_device_t* dev) -{ - if (! trace_flag) { - fprintf(stderr, "Read device: "); - fflush(stderr); - } - - dev->download(dev); - - if (! trace_flag) - fprintf(stderr, " done.\n"); -} - // // Write firmware image to the device. // diff --git a/src/lib.rs b/src/lib.rs index 413b9bf..de343d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,6 +72,8 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int } }; + let trace_flag = matches.opt_present("t"); + let list_flag = matches.opt_present("l"); let verify_flag = matches.opt_present("v"); let read_flag = matches.opt_present("r"); @@ -120,7 +122,7 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int } else { // Update device from text config file. let device = radio::connect(); - radio::download(device); + radio::download(device, trace_flag); radio::print_version(device); radio::save_image(device, "device.img"); radio::parse_config(device, &config_filename); @@ -144,7 +146,7 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int // Dump device to image file. let device = radio::connect(); - radio::download(device); + radio::download(device, trace_flag); radio::print_version(device); radio::disconnect(); radio::save_image(device, "device.img"); diff --git a/src/radio.rs b/src/radio.rs index db8147d..07229f3 100644 --- a/src/radio.rs +++ b/src/radio.rs @@ -15,9 +15,6 @@ extern { fn set_active_device(device: *const radio_device_t); - //fn radio_connect() -> *const radio_device_t; - - fn radio_download(device: *const radio_device_t); fn radio_upload(device: *const radio_device_t, cont_flag: c_int); fn radio_verify_config(device: *const radio_device_t); fn radio_print_version(device: *const radio_device_t, stdout: *const libc::FILE); @@ -116,9 +113,20 @@ pub fn disconnect() { } /// Read firmware image from the device -pub fn download(device: *const radio_device_t) { +pub fn download(device: *const radio_device_t, trace: bool) { + + if !trace { + eprint!("Read device: "); + } + unsafe { - radio_download(device) + let download_fn = (*device).download.unwrap(); + let device_mut = device as *mut radio_device_t; + download_fn(device_mut); + } + + if !trace { + eprintln!(" done."); } }