From 23fc703abdd717a9ffc3aa354d59440d5be04a99 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 4 Mar 2021 01:25:26 -0800 Subject: [PATCH] Move ident manipulation into isolated block --- src/radio.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/radio.rs b/src/radio.rs index c29976d..20425a0 100644 --- a/src/radio.rs +++ b/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();