Move radio_is_compatible to Rust
This commit is contained in:
parent
ad5b0547e4
commit
7a39fd1ae2
20
radio.c
20
radio.c
@ -35,6 +35,7 @@
|
||||
#include "radio.h"
|
||||
#include "util.h"
|
||||
|
||||
/*
|
||||
typedef struct { char* ident; radio_device_t* device; } radio_tab_t;
|
||||
|
||||
static radio_tab_t radio_tab[] = {
|
||||
@ -56,6 +57,7 @@ static radio_tab_t radio_tab[] = {
|
||||
{ "ZN><:", &radio_rt27d }, // Radtel RT-27D
|
||||
{ 0, 0 }
|
||||
};
|
||||
*/
|
||||
|
||||
static radio_device_t *active_device; // Device-dependent interface
|
||||
|
||||
@ -280,21 +282,3 @@ void radio_write_csv(radio_device_t* device, const char *filename)
|
||||
device->write_csv(device, csv);
|
||||
fclose(csv);
|
||||
}
|
||||
|
||||
//
|
||||
// Check for compatible radio model.
|
||||
//
|
||||
int radio_is_compatible(const char *name)
|
||||
{
|
||||
radio_device_t* dev = get_active_device();
|
||||
int i;
|
||||
|
||||
for (i=0; radio_tab[i].ident; i++) {
|
||||
// Radio is compatible when it has the same parse routine.
|
||||
if (dev->parse_parameter == radio_tab[i].device->parse_parameter &&
|
||||
strcasecmp(name, radio_tab[i].device->name) == 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
23
src/radio.rs
23
src/radio.rs
@ -33,6 +33,7 @@ static mut RADIO_TABLE: [(&'static str, &'static radio_device_t); 16] = unsafe {
|
||||
|
||||
extern {
|
||||
|
||||
fn get_active_device() -> *const radio_device_t;
|
||||
fn set_active_device(device: *const radio_device_t);
|
||||
|
||||
fn radio_print_config(device: *const radio_device_t, file: *const libc::FILE, verbose: c_int);
|
||||
@ -294,3 +295,25 @@ pub fn write_csv(radio: &Radio, filename: &str) {
|
||||
radio_write_csv(device, filename.as_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
/// Check for compatible radio model.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn radio_is_compatible(name: *const c_char) -> c_int {
|
||||
unsafe {
|
||||
let name = CStr::from_ptr(name).to_str().unwrap();
|
||||
let dev = get_active_device();
|
||||
|
||||
for (_, device) in RADIO_TABLE.iter() {
|
||||
// Radio is compatible when it has the same parse routine.
|
||||
let same_parse = (*dev).parse_parameter.unwrap() == (*device).parse_parameter.unwrap();
|
||||
let name_ptr = (*device).name;
|
||||
let device_name = CStr::from_ptr(name_ptr).to_str().unwrap();
|
||||
let same_name = name.eq_ignore_ascii_case(device_name);
|
||||
|
||||
if same_parse && same_name {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user