Move ident manipulation into isolated block
This commit is contained in:
parent
9015d9f8e0
commit
23fc703abd
17
src/radio.rs
17
src/radio.rs
@ -64,23 +64,23 @@ unsafe fn set_active_device(d: *const radio_device_t) {
|
||||
/// Connect to the radio via the serial port.
|
||||
/// and identify the type of device.
|
||||
pub fn connect() -> Radio {
|
||||
unsafe {
|
||||
|
||||
let ident_str = {
|
||||
let mut ident: *const c_char;
|
||||
// Try TYT MD family.
|
||||
ident = dfu_init(0x0483, 0xdf11);
|
||||
ident = unsafe { dfu_init(0x0483, 0xdf11) };
|
||||
if ident.is_null() {
|
||||
// Try RD-5R, DM-1801 and GD-77.
|
||||
if hid_init(0x15a2, 0x0073) >= 0 {
|
||||
ident = hid_identify();
|
||||
if unsafe { hid_init(0x15a2, 0x0073) } >= 0 {
|
||||
ident = unsafe { hid_identify() };
|
||||
}
|
||||
}
|
||||
|
||||
if ident.is_null() {
|
||||
// Try AT-D868UV.
|
||||
let trace_flag = false; //TODO fix
|
||||
if let Some(device_path) = crate::serial::serial_init(0x28e9, 0x018a, trace_flag) {
|
||||
let ptr = device_path.as_ptr() as *mut c_char;
|
||||
ident = serial_identify(ptr);
|
||||
ident = unsafe { serial_identify(ptr) };
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +90,10 @@ pub fn connect() -> Radio {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
let ident_str = CStr::from_ptr(ident).to_str().unwrap();
|
||||
unsafe { CStr::from_ptr(ident).to_str().unwrap().to_string() }
|
||||
};
|
||||
|
||||
unsafe {
|
||||
|
||||
let mut device: *const radio_device_t = std::ptr::null();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user