Transfer print_version, verify_config
This commit is contained in:
parent
8fd7e82951
commit
ca27d4035f
1
build.rs
1
build.rs
@ -19,6 +19,7 @@ fn main() {
|
||||
// included header files changed.
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||
.whitelist_type("radio_device_t")
|
||||
.blacklist_type("FILE")
|
||||
// Finish the builder and generate the bindings.
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure.
|
||||
|
19
radio.c
19
radio.c
@ -73,14 +73,6 @@ void set_active_device(radio_device_t* d) {
|
||||
|
||||
unsigned char radio_mem [1024*1024*2]; // Radio memory contents, up to 2 Mbytes
|
||||
|
||||
//
|
||||
// Print a generic information about the device.
|
||||
//
|
||||
void radio_print_version(radio_device_t* dev, FILE *out)
|
||||
{
|
||||
dev->print_version(dev, out);
|
||||
}
|
||||
|
||||
//
|
||||
// Read firmware image from the binary file.
|
||||
//
|
||||
@ -287,17 +279,6 @@ void radio_print_config(radio_device_t* device, FILE *out, int verbose)
|
||||
device->print_config(device, out, verbose);
|
||||
}
|
||||
|
||||
//
|
||||
// Check the configuration is correct.
|
||||
//
|
||||
void radio_verify_config(radio_device_t* device)
|
||||
{
|
||||
if (!device->verify_config(device)) {
|
||||
// Message should be already printed.
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Update contacts database on the device.
|
||||
//
|
||||
|
17
src/radio.rs
17
src/radio.rs
@ -3,6 +3,7 @@ use libc::{c_char, c_int, c_uint};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::process::exit;
|
||||
|
||||
use libc::FILE;
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
pub struct Radio {
|
||||
@ -19,7 +20,6 @@ extern {
|
||||
|
||||
fn set_active_device(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_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;
|
||||
@ -179,11 +179,15 @@ pub fn list() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Check the configuration.
|
||||
/// Check that the configuration is correct.
|
||||
pub fn verify_config(radio: &Radio) {
|
||||
let device = radio.ptr;
|
||||
let device = radio.ptr as *mut radio_device_t;
|
||||
unsafe {
|
||||
radio_verify_config(device);
|
||||
let verify_fn = (*device).verify_config.unwrap();
|
||||
if verify_fn(device) == 0 {
|
||||
// Message should be already printed.
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,10 +247,11 @@ pub fn print_config_to_stdout(radio: &Radio) {
|
||||
|
||||
/// Print generic information about the device.
|
||||
pub fn print_version(radio: &Radio) {
|
||||
let device = radio.ptr;
|
||||
let device = radio.ptr as *mut radio_device_t;
|
||||
let mode = CString::new("w").unwrap();
|
||||
unsafe {
|
||||
radio_print_version(device, libc::fdopen(libc::STDOUT_FILENO, mode.as_ptr()));
|
||||
let print_version_fn = (*device).print_version.unwrap();
|
||||
print_version_fn(device, libc::fdopen(libc::STDOUT_FILENO, mode.as_ptr()));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user