From 9e62c3bd71cc3305d36c25008ef0129c68364c14 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Mon, 22 Nov 2010 19:29:08 +0000 Subject: [PATCH] try kill BlueTool and BTServer if needed --- src/bt_control_iphone.m | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/bt_control_iphone.m b/src/bt_control_iphone.m index 3a2f2953e..886d0d478 100644 --- a/src/bt_control_iphone.m +++ b/src/bt_control_iphone.m @@ -399,12 +399,40 @@ static int iphone_on (void *transport_config){ if ([systemVersion hasPrefix:@"3."]) os4x = 0; // NSLog(@"OS Version: %@, ox4x = %u", systemVersion, os4x); [pool release]; - - // OS 4.0 + + // set correct BlueTool version, BlueToolH4 on OS 4.0+ char * bluetool = os3xBlueTool; if (os4x) { bluetool = os4xBlueTool; - // basic config + } + + // quick test if Bluetooth UART can be opened - and try to start cleanly + int fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY); + if (fd > 0) { + // everything's fine + close(fd); + } else { + // no way! + fprintf(stderr, "bt_control.c:iphone_on(): Failed to open '%s', trying killall %s\n", hci_uart_config->device_name, bluetool); + sprintf(buffer, "killall %s", bluetool); + system(buffer); + sleep(3); + + // try again + fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY); + if (fd > 0){ + close(fd); + } else { + fprintf(stderr, "bt_control.c:iphone_on(): Failed to open '%s' again, trying killall BTServer and killall %s\n", hci_uart_config->device_name, bluetool); + system("killall BTServer"); + sprintf(buffer, "killall %s", bluetool); + system(buffer); + sleep(3); + } + } + + // basic config on 4.0+ + if (os4x) { sprintf(buffer, "%s -F boot", bluetool); system(buffer); sprintf(buffer, "%s -F init", bluetool);