radio_save_image port
This commit is contained in:
parent
ca27d4035f
commit
c921cc54d6
17
radio.c
17
radio.c
@ -157,23 +157,6 @@ radio_device_t* radio_read_image(const char *filename)
|
||||
return dev;
|
||||
}
|
||||
|
||||
//
|
||||
// Save firmware image to the binary file.
|
||||
//
|
||||
void radio_save_image(radio_device_t* device, const char *filename)
|
||||
{
|
||||
FILE *img;
|
||||
|
||||
fprintf(stderr, "Write codeplug to file '%s'.\n", filename);
|
||||
img = fopen(filename, "wb");
|
||||
if (! img) {
|
||||
perror(filename);
|
||||
exit(-1);
|
||||
}
|
||||
device->save_image(device, img);
|
||||
fclose(img);
|
||||
}
|
||||
|
||||
//
|
||||
// Read the configuration from text file, and modify the firmware.
|
||||
//
|
||||
|
17
src/radio.rs
17
src/radio.rs
@ -20,10 +20,8 @@ extern {
|
||||
|
||||
fn set_active_device(device: *const radio_device_t);
|
||||
|
||||
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_read_image(filename: *const c_char) -> *const radio_device_t;
|
||||
fn radio_save_image(device: *const radio_device_t, filename: *const c_char);
|
||||
fn radio_parse_config(device: *const radio_device_t, filename: *const c_char);
|
||||
fn radio_write_csv(device: *const radio_device_t, filename: *const c_char);
|
||||
|
||||
@ -202,10 +200,19 @@ pub fn read_image(filename: &str) -> Radio {
|
||||
|
||||
/// Save firmware image to the binary file.
|
||||
pub fn save_image(radio: &Radio, filename: &str) {
|
||||
let device = radio.ptr;
|
||||
let filename = CString::new(filename.to_string()).unwrap();
|
||||
|
||||
eprintln!("Write codeplug to file '{}'.", filename);
|
||||
|
||||
let device = radio.ptr as *mut radio_device_t;
|
||||
let file = std::fs::File::create(filename).unwrap();
|
||||
let fd = file.as_raw_fd();
|
||||
let mode = CString::new("wb").unwrap();
|
||||
|
||||
unsafe {
|
||||
radio_save_image(device, filename.as_ptr())
|
||||
let file = libc::fdopen(fd, mode.as_ptr());
|
||||
let save_image_fn = (*device).save_image.unwrap();
|
||||
save_image_fn(device, file);
|
||||
libc::fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user