radio_save_image port

This commit is contained in:
Greg Shuflin 2021-03-01 02:02:17 -08:00
parent ca27d4035f
commit c921cc54d6
2 changed files with 12 additions and 22 deletions

17
radio.c
View File

@ -157,23 +157,6 @@ radio_device_t* radio_read_image(const char *filename)
return dev; 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. // Read the configuration from text file, and modify the firmware.
// //

View File

@ -20,10 +20,8 @@ extern {
fn set_active_device(device: *const radio_device_t); 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_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_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_parse_config(device: *const radio_device_t, filename: *const c_char);
fn radio_write_csv(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. /// Save firmware image to the binary file.
pub fn save_image(radio: &Radio, filename: &str) { 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 { 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);
} }
} }