Port upload
This commit is contained in:
parent
25571023a3
commit
8fd7e82951
20
radio.c
20
radio.c
@ -81,26 +81,6 @@ void radio_print_version(radio_device_t* dev, FILE *out)
|
|||||||
dev->print_version(dev, out);
|
dev->print_version(dev, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Write firmware image to the device.
|
|
||||||
//
|
|
||||||
void radio_upload(radio_device_t* dev, int cont_flag)
|
|
||||||
{
|
|
||||||
// Check for compatibility.
|
|
||||||
if (! dev->is_compatible(dev)) {
|
|
||||||
fprintf(stderr, "Incompatible image - cannot upload.\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
if (! trace_flag) {
|
|
||||||
fprintf(stderr, "Write device: ");
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
dev->upload(dev, cont_flag);
|
|
||||||
|
|
||||||
if (! trace_flag)
|
|
||||||
fprintf(stderr, " done.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read firmware image from the binary file.
|
// Read firmware image from the binary file.
|
||||||
//
|
//
|
||||||
|
@ -98,7 +98,7 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int
|
|||||||
let device = radio::connect();
|
let device = radio::connect();
|
||||||
radio::read_image(&matches.free[0]);
|
radio::read_image(&matches.free[0]);
|
||||||
radio::print_version(&device);
|
radio::print_version(&device);
|
||||||
radio::upload(&device, 0);
|
radio::upload(&device, 0, trace_flag);
|
||||||
radio::disconnect();
|
radio::disconnect();
|
||||||
} else if config_flag {
|
} else if config_flag {
|
||||||
let conf_args = matches.free.len();
|
let conf_args = matches.free.len();
|
||||||
@ -127,7 +127,7 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int
|
|||||||
radio::save_image(&device, "device.img");
|
radio::save_image(&device, "device.img");
|
||||||
radio::parse_config(&device, &config_filename);
|
radio::parse_config(&device, &config_filename);
|
||||||
radio::verify_config(&device);
|
radio::verify_config(&device);
|
||||||
radio::upload(&device, 1);
|
radio::upload(&device, 1, trace_flag);
|
||||||
radio::disconnect();
|
radio::disconnect();
|
||||||
}
|
}
|
||||||
} else if verify_flag {
|
} else if verify_flag {
|
||||||
|
33
src/radio.rs
33
src/radio.rs
@ -12,14 +12,13 @@ pub struct Radio {
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct radio_tab_t {
|
pub struct radio_tab_t {
|
||||||
ident: *const c_char,
|
ident: *const c_char,
|
||||||
device: *const radio_device_t,
|
device: *mut radio_device_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
|
|
||||||
fn set_active_device(device: *const radio_device_t);
|
fn set_active_device(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_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);
|
||||||
fn radio_print_config(device: *const radio_device_t, file: *const libc::FILE, verbose: c_int);
|
fn radio_print_config(device: *const radio_device_t, file: *const libc::FILE, verbose: c_int);
|
||||||
@ -99,7 +98,7 @@ pub fn connect() -> Radio {
|
|||||||
println!("Connect to {}", name);
|
println!("Connect to {}", name);
|
||||||
|
|
||||||
set_active_device(device);
|
set_active_device(device);
|
||||||
return Radio { ptr: device };
|
return Radio { ptr: device as *mut radio_device_t };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +118,7 @@ pub fn disconnect() {
|
|||||||
/// Read firmware image from the device
|
/// Read firmware image from the device
|
||||||
pub fn download(radio: &Radio, trace: bool) {
|
pub fn download(radio: &Radio, trace: bool) {
|
||||||
|
|
||||||
let device = radio.ptr;
|
let device = radio.ptr as *mut radio_device_t;
|
||||||
|
|
||||||
if !trace {
|
if !trace {
|
||||||
eprint!("Read device: ");
|
eprint!("Read device: ");
|
||||||
@ -127,8 +126,7 @@ pub fn download(radio: &Radio, trace: bool) {
|
|||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let download_fn = (*device).download.unwrap();
|
let download_fn = (*device).download.unwrap();
|
||||||
let device_mut = device as *mut radio_device_t;
|
download_fn(device);
|
||||||
download_fn(device_mut);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !trace {
|
if !trace {
|
||||||
@ -137,10 +135,25 @@ pub fn download(radio: &Radio, trace: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write firmware image to the device.
|
/// Write firmware image to the device.
|
||||||
pub fn upload(radio: &Radio, cont_flag: c_int) {
|
pub fn upload(radio: &Radio, cont_flag: c_int, trace: bool) {
|
||||||
let device = radio.ptr;
|
let device = radio.ptr as *mut radio_device_t;
|
||||||
unsafe {
|
unsafe {
|
||||||
radio_upload(device, cont_flag)
|
let is_compatible_fn = (*device).is_compatible.unwrap();
|
||||||
|
if is_compatible_fn(device) == 0 {
|
||||||
|
eprintln!("Incompatible image - cannot upload.");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !trace {
|
||||||
|
eprint!("Write device: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
let upload_fn = (*device).upload.unwrap();
|
||||||
|
upload_fn(device, cont_flag);
|
||||||
|
|
||||||
|
if !trace {
|
||||||
|
eprintln!(" done.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +193,7 @@ pub fn read_image(filename: &str) -> Radio {
|
|||||||
let ptr = unsafe {
|
let ptr = unsafe {
|
||||||
radio_read_image(filename.as_ptr())
|
radio_read_image(filename.as_ptr())
|
||||||
};
|
};
|
||||||
Radio { ptr }
|
Radio { ptr: ptr as *mut radio_device_t }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Save firmware image to the binary file.
|
/// Save firmware image to the binary file.
|
||||||
|
Loading…
Reference in New Issue
Block a user