Put radio table into rust
This commit is contained in:
parent
4f082277d8
commit
ad5b0547e4
4
radio.c
4
radio.c
@ -57,10 +57,6 @@ static radio_tab_t radio_tab[] = {
|
|||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
radio_tab_t* get_radio_tab() {
|
|
||||||
return radio_tab;
|
|
||||||
}
|
|
||||||
|
|
||||||
static radio_device_t *active_device; // Device-dependent interface
|
static radio_device_t *active_device; // Device-dependent interface
|
||||||
|
|
||||||
radio_device_t* get_active_device() {
|
radio_device_t* get_active_device() {
|
||||||
|
25
src/radio.rs
25
src/radio.rs
@ -10,13 +10,6 @@ pub struct Radio {
|
|||||||
ptr: *const radio_device_t
|
ptr: *const radio_device_t
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct radio_tab_t {
|
|
||||||
ident: *const c_char,
|
|
||||||
device: *mut radio_device_t,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static mut RADIO_TABLE: [(&'static str, &'static radio_device_t); 16] = unsafe {
|
static mut RADIO_TABLE: [(&'static str, &'static radio_device_t); 16] = unsafe {
|
||||||
[
|
[
|
||||||
("DR780", &radio_md380), // TYT MD-380, Retevis RT3, RT8
|
("DR780", &radio_md380), // TYT MD-380, Retevis RT3, RT8
|
||||||
@ -58,8 +51,6 @@ extern {
|
|||||||
fn serial_init(vid: c_int, pid: c_int) -> c_int;
|
fn serial_init(vid: c_int, pid: c_int) -> c_int;
|
||||||
fn serial_identify() -> *const c_char;
|
fn serial_identify() -> *const c_char;
|
||||||
fn serial_close();
|
fn serial_close();
|
||||||
|
|
||||||
fn get_radio_tab() -> *const radio_tab_t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Connect to the radio via the serial port.
|
/// Connect to the radio via the serial port.
|
||||||
@ -92,20 +83,12 @@ pub fn connect() -> Radio {
|
|||||||
let ident_str = CStr::from_ptr(ident).to_str().unwrap();
|
let ident_str = CStr::from_ptr(ident).to_str().unwrap();
|
||||||
|
|
||||||
let mut device: *const radio_device_t = std::ptr::null();
|
let mut device: *const radio_device_t = std::ptr::null();
|
||||||
let mut radio_tab_ptr = get_radio_tab();
|
|
||||||
loop {
|
for (table_ident, device_ptr) in RADIO_TABLE.iter() {
|
||||||
let ident_ptr = (*radio_tab_ptr).ident;
|
if ident_str == *table_ident {
|
||||||
if ident_ptr.is_null() {
|
device = *device_ptr as *const radio_device_t;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let table_ident = CStr::from_ptr(ident_ptr).to_str().unwrap();
|
|
||||||
if ident_str.eq_ignore_ascii_case(table_ident) {
|
|
||||||
device = (*radio_tab_ptr).device;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
radio_tab_ptr = radio_tab_ptr.offset(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if device.is_null() {
|
if device.is_null() {
|
||||||
|
Loading…
Reference in New Issue
Block a user