Move download to rust

This commit is contained in:
Greg Shuflin 2021-03-01 00:43:25 -08:00
parent cccbee30a8
commit 61544fd23f
3 changed files with 17 additions and 23 deletions

16
radio.c
View File

@ -81,22 +81,6 @@ void radio_print_version(radio_device_t* dev, FILE *out)
dev->print_version(dev, 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. // Write firmware image to the device.
// //

View File

@ -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 list_flag = matches.opt_present("l");
let verify_flag = matches.opt_present("v"); let verify_flag = matches.opt_present("v");
let read_flag = matches.opt_present("r"); 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 { } else {
// Update device from text config file. // Update device from text config file.
let device = radio::connect(); let device = radio::connect();
radio::download(device); radio::download(device, trace_flag);
radio::print_version(device); radio::print_version(device);
radio::save_image(device, "device.img"); radio::save_image(device, "device.img");
radio::parse_config(device, &config_filename); 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. // Dump device to image file.
let device = radio::connect(); let device = radio::connect();
radio::download(device); radio::download(device, trace_flag);
radio::print_version(device); radio::print_version(device);
radio::disconnect(); radio::disconnect();
radio::save_image(device, "device.img"); radio::save_image(device, "device.img");

View File

@ -15,9 +15,6 @@ extern {
fn set_active_device(device: *const radio_device_t); 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_upload(device: *const radio_device_t, cont_flag: c_int);
fn radio_verify_config(device: *const radio_device_t); fn radio_verify_config(device: *const radio_device_t);
fn radio_print_version(device: *const radio_device_t, stdout: *const libc::FILE); 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 /// 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 { 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.");
} }
} }