From 8cbb57e63c1c52e7d5576256a10b432929f44db5 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Wed, 20 May 2009 21:25:20 +0000 Subject: [PATCH] more fixes --- bt_control_iphone.c | 57 ++++++++++++++++++++++++++++----------------- src/hci.c | 3 +++ src/main.c | 5 ++-- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/bt_control_iphone.c b/bt_control_iphone.c index 9e03f8b6b..cc6604ad8 100644 --- a/bt_control_iphone.c +++ b/bt_control_iphone.c @@ -66,30 +66,17 @@ static int iphone_on (void *config){ bzero (&noTime, sizeof(struct timeval)); while (1){ int chars = read(input, &buffer[pos], 1); - - int ready; - do { - fd_set fds; - FD_ZERO(&fds); - FD_SET(output,&fds); - ready=select(output+1,&fds,NULL,NULL,&noTime); - if (ready>0) - { - if (FD_ISSET(output,&fds)) { - char singlechar = fgetc(outputFile); - printf("%c", singlechar); - } - } - } while (ready); - + // end-of-line if (chars == 0 || buffer[pos]=='\n' || buffer[pos]== '\r'){ if (store) { // stored characters write(output, buffer, pos+chars); + write(fileno(stdout), buffer, pos+chars); } if (mirror) { write(output, "\n", 1); + write(fileno(stdout), "\n", 1); } pos = 0; mirror = 0; @@ -104,6 +91,7 @@ static int iphone_on (void *config){ // mirror if (mirror){ write(output, &buffer[pos], 1); + write(fileno(stdout), &buffer[pos], 1); } // store @@ -117,24 +105,49 @@ static int iphone_on (void *config){ store = 0; if (sscanf(buffer, "csr -p 0x%x=0x%x", &pskey, &value) == 2){ if (pskey == 0x01f9) { // UART MODE - write(output, "Skipping: ", 10); - write(output, buffer, pos); - mirror = 1; + // write(output, buffer, pos); + write(fileno(stdout), "Skipping: ", 10); + write(fileno(stdout), buffer, pos); + mirror = 0; } else if (pskey == 0x01be) { // UART Baud - write(output, "Skipping: ", 10); - write(output, buffer, pos); - mirror = 1; + // write(output, buffer, pos); + write(fileno(stdout), "Skipping: ", 10); + write(fileno(stdout), buffer, pos); + mirror = 0; } else { // dump buffer and start forwarding write(output, buffer, pos); + write(fileno(stdout), buffer, pos); mirror = 1; } } else { write(output, buffer, pos); + write(fileno(stdout), buffer, pos); mirror = 1; } } } + // close ports + close(input); + + // log output + int ready; + do { + fd_set fds; + FD_ZERO(&fds); + FD_SET(output,&fds); + ready=select(output+1,&fds,NULL,NULL,&noTime); + if (ready>0) + { + if (FD_ISSET(output,&fds)) { + char singlechar = fgetc(outputFile); + printf("%c", singlechar); + } + } + } while (ready); + + fflush(outputFile); + pclose(outputFile); return 0; } diff --git a/src/hci.c b/src/hci.c index fded70754..b607d5aca 100644 --- a/src/hci.c +++ b/src/hci.c @@ -184,6 +184,9 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){ transport->register_event_packet_handler( event_handler); transport->register_acl_packet_handler( acl_handler); + // turn on + hci_power_control(HCI_POWER_ON); + // open low-level device transport->open(config); } diff --git a/src/main.c b/src/main.c index 70b2d56d5..f91369ae8 100644 --- a/src/main.c +++ b/src/main.c @@ -101,7 +101,7 @@ int main (int argc, const char * argv[]) { bt_control_t * control = NULL; -#if 1 +#if 0 // if (argc <= 1){ printf("HCI Daemon tester. Specify device name for Ericsson ROK 101 007\n"); @@ -114,7 +114,7 @@ int main (int argc, const char * argv[]) { config.flowcontrol = 1; #else // iPhone - config.device_name = "/dev/bluetooth"; + config.device_name = "/dev/tty.bluetooth"; config.baudrate = 115200; config.flowcontrol = 1; control = &bt_control_iphone; @@ -125,7 +125,6 @@ int main (int argc, const char * argv[]) { // init HCI hci_init(transport, &config, control); - hci_power_control(HCI_POWER_ON); // // register callbacks