Move download to rust
This commit is contained in:
parent
cccbee30a8
commit
61544fd23f
16
radio.c
16
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.
|
||||
//
|
||||
|
@ -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");
|
||||
|
18
src/radio.rs
18
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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user