mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-05 21:59:45 +00:00
added quick test if Bluetooh UART can be opened before running BlueTool. Before Apple's Bluetooth did turn back on after it was turned off in the Settings
This commit is contained in:
parent
32c63dd2ac
commit
ac2e07f8dd
@ -95,10 +95,7 @@ static void iphone_set_pskey(int fd, int key, int value){
|
||||
write(fd, buffer, 21);
|
||||
}
|
||||
|
||||
static int iphone_write_initscript (void *config, int output){
|
||||
|
||||
// get uart config
|
||||
hci_uart_config_t * uart_config = (hci_uart_config_t *) config;
|
||||
static int iphone_write_initscript (hci_uart_config_t *uart_config, int output){
|
||||
|
||||
// calculate baud rate (assume rate is multiply of 100)
|
||||
uint32_t baud_key = (4096 * (uart_config->baudrate/100) + 4999) / 10000;
|
||||
@ -248,12 +245,23 @@ static int iphone_write_initscript (void *config, int output){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iphone_on (void *config){
|
||||
static int iphone_on (void *transport_config){
|
||||
|
||||
// quick test if Bluetooth UART can be opened
|
||||
hci_uart_config_t * hci_uart_config = (hci_uart_config_t*) transport_config;
|
||||
int fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (fd == -1) {
|
||||
perror("init_serialport: Unable to open port ");
|
||||
perror(hci_uart_config->device_name);
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
int err = 0;
|
||||
#if 0
|
||||
// use tmp file for testing
|
||||
int output = open("/tmp/bt.init", O_WRONLY | O_CREAT | O_TRUNC);
|
||||
iphone_write_initscript(config, output);
|
||||
iphone_write_initscript(hci_uart_config, output);
|
||||
close(output);
|
||||
err = system ("BlueTool < /tmp/bt.init");
|
||||
#else
|
||||
@ -261,7 +269,7 @@ static int iphone_on (void *config){
|
||||
FILE * outputFile = popen("BlueTool", "r+");
|
||||
setvbuf(outputFile, NULL, _IONBF, 0);
|
||||
int output = fileno(outputFile);
|
||||
iphone_write_initscript(config, output);
|
||||
iphone_write_initscript(hci_uart_config, output);
|
||||
|
||||
// log output
|
||||
fflush(outputFile);
|
||||
|
@ -268,7 +268,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
||||
// power on
|
||||
int err = hci_stack.control->on(hci_stack.config);
|
||||
if (err){
|
||||
fprintf(stderr, "POWER_ON failed");
|
||||
fprintf(stderr, "POWER_ON failed\n");
|
||||
hci_emit_hci_open_failed();
|
||||
return err;
|
||||
}
|
||||
@ -276,7 +276,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
||||
// open low-level device
|
||||
err = hci_stack.hci_transport->open(hci_stack.config);
|
||||
if (err){
|
||||
fprintf(stderr, "HCI_INIT failed, turning Bluetooth off again");
|
||||
fprintf(stderr, "HCI_INIT failed, turning Bluetooth off again\n");
|
||||
hci_stack.control->off(hci_stack.config);
|
||||
hci_emit_hci_open_failed();
|
||||
return err;
|
||||
|
Loading…
Reference in New Issue
Block a user