From 7bba34d17e89271e60704576535f9ff5eca9d646 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Mon, 1 Aug 2011 11:52:27 +0000 Subject: [PATCH] use bd_addr_to_str instead of print_bd_addr - and provide compat-svn.c to deal with fact that bd_addr_to_str is not in current Cydia release of BTstack --- example/compat-svn.c | 14 ++++++++++++++ example/inquiry.c | 24 ++++++++++-------------- example/l2cap-server.c | 19 ++++++++----------- example/l2cap-throughput.c | 17 +++++++---------- example/rfcomm-cat.c | 7 ++++--- example/rfcomm-echo.c | 7 ++++--- example/rfcomm-test.c | 7 ++++--- example/test.c | 13 ++++++------- 8 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 example/compat-svn.c diff --git a/example/compat-svn.c b/example/compat-svn.c new file mode 100644 index 000000000..7a27eabb4 --- /dev/null +++ b/example/compat-svn.c @@ -0,0 +1,14 @@ +/** + */ + +#include +#include + + +static char new_bd_addr_to_str_buffer[6*3]; // 12:45:78:01:34:67\0 +static char * new_bd_addr_to_str(bd_addr_t addr){ + sprintf(new_bd_addr_to_str_buffer, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); + return (char *) new_bd_addr_to_str_buffer; +} + +#define bd_addr_to_str(x) new_bd_addr_to_str(x) diff --git a/example/inquiry.c b/example/inquiry.c index 371f9a128..b0ddc131f 100644 --- a/example/inquiry.c +++ b/example/inquiry.c @@ -42,6 +42,9 @@ #include +// until next BTstack Cydia update +#include "compat-svn.c" + #define MAX_DEVICES 10 struct device { bd_addr_t address; @@ -85,9 +88,7 @@ void next(void){ if (devices[i].state == 1){ found = 1; devices[i].state = 2; - printf("Get remote name of "); - print_bd_addr(devices[i].address); - printf("...\n"); + printf("Get remote name of %s...\n", bd_addr_to_str(devices[i].address)); bt_send_cmd(&hci_remote_name_request, devices[i].address, devices[i].pageScanRepetitionMode, 0, devices[i].clockOffset | 0x8000); break; @@ -141,10 +142,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint devices[deviceCount].clockOffset = READ_BT_16(packet, 3 + numResponses*(6+1+1+1+3) + i*2) & 0x7fff; devices[deviceCount].rssi = 0; devices[deviceCount].state = 1; - printf("Device found: "); - print_bd_addr(addr); - printf(" with COD: 0x%06x, pageScan %u, clock offset 0x%04x\n", devices[deviceCount].classOfDevice, - devices[deviceCount].pageScanRepetitionMode, devices[deviceCount].clockOffset); + printf("Device found: %s with COD: %x, pageScan %u, clock offset %x\n", bd_addr_to_str(addr), devices[deviceCount].classOfDevice, + devices[deviceCount].pageScanRepetitionMode, devices[deviceCount].clockOffset); deviceCount++; } break; @@ -161,19 +160,16 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint devices[deviceCount].clockOffset = READ_BT_16(packet, 3 + numResponses*(6+1+1+3) + i*2) & 0x7fff; devices[deviceCount].rssi = packet [3 + numResponses*(6+1+1+3+2) + i*1]; devices[deviceCount].state = 1; - printf("Device found: "); - print_bd_addr(addr); - printf(" with COD: 0x%06x, pageScan %u, clock offset 0x%04x, rssi 0x%02x\n", devices[deviceCount].classOfDevice, - devices[deviceCount].pageScanRepetitionMode, devices[deviceCount].clockOffset, devices[deviceCount].rssi); + printf("Device found: %s with COD: 0x%06x, pageScan %u, clock offset 0x%04x, rssi 0x%02x\n", bd_addr_to_str(addr), + devices[deviceCount].classOfDevice, devices[deviceCount].pageScanRepetitionMode, + devices[deviceCount].clockOffset, devices[deviceCount].rssi); deviceCount++; } break; case BTSTACK_EVENT_REMOTE_NAME_CACHED: bt_flip_addr(addr, &packet[3]); - printf("Cached remote name for "); - print_bd_addr(addr); - printf(": %s\n", &packet[9]); + printf("Cached remote name for %s: '%s'\n", bd_addr_to_str(addr), &packet[9]); break; case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: diff --git a/example/l2cap-server.c b/example/l2cap-server.c index da00a68ab..90c9371f8 100644 --- a/example/l2cap-server.c +++ b/example/l2cap-server.c @@ -44,6 +44,9 @@ #include #include +// until next BTstack Cydia update +#include "compat-svn.c" + hci_con_handle_t con_handle; uint16_t hid_control = 0; @@ -90,10 +93,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint psm = READ_BT_16(packet, 10); local_cid = READ_BT_16(packet, 12); remote_cid = READ_BT_16(packet, 14); - printf("L2CAP_EVENT_INCOMING_CONNECTION "); - print_bd_addr(event_addr); - printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", - handle, psm, local_cid, remote_cid); + printf("L2CAP_EVENT_INCOMING_CONNECTION %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", + bd_addr_to_str(event_addr), handle, psm, local_cid, remote_cid); // accept bt_send_cmd(&l2cap_accept_connection, local_cid); @@ -125,10 +126,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint local_cid = READ_BT_16(packet, 13); handle = READ_BT_16(packet, 9); if (packet[2] == 0) { - printf("Channel successfully opened: "); - print_bd_addr(event_addr); - printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", - handle, psm, local_cid, READ_BT_16(packet, 15)); + printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", + bd_addr_to_str(event_addr), handle, psm, local_cid, READ_BT_16(packet, 15)); if (psm == PSM_HID_CONTROL){ hid_control = local_cid; @@ -140,9 +139,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint bt_send_cmd(&hci_switch_role_command, &event_addr, 0); } } else { - printf("L2CAP connection to device "); - print_bd_addr(event_addr); - printf(" failed. status code %u\n", packet[2]); + printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]); exit(1); } break; diff --git a/example/l2cap-throughput.c b/example/l2cap-throughput.c index ef229ee9b..38799a875 100644 --- a/example/l2cap-throughput.c +++ b/example/l2cap-throughput.c @@ -43,6 +43,9 @@ #include #include +// until next BTstack Cydia update +#include "compat-svn.c" + #define PSM_TEST 0xdead #define PACKET_SIZE 1000 @@ -126,9 +129,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint psm = READ_BT_16(packet, 10); local_cid = READ_BT_16(packet, 12); remote_cid = READ_BT_16(packet, 14); - printf("L2CAP_EVENT_INCOMING_CONNECTION "); - print_bd_addr(event_addr); - printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x\n", handle, psm, local_cid); + printf("L2CAP_EVENT_INCOMING_CONNECTION %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x\n", bd_addr_to_str(event_addr), handle, psm, local_cid); // accept bt_send_cmd(&l2cap_accept_connection, local_cid); break; @@ -160,14 +161,10 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint local_cid = READ_BT_16(packet, 13); handle = READ_BT_16(packet, 9); if (packet[2] == 0) { - printf("Channel successfully opened: "); - print_bd_addr(event_addr); - printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", - handle, psm, local_cid, READ_BT_16(packet, 15)); + printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", + bd_addr_to_str(event_addr), handle, psm, local_cid, READ_BT_16(packet, 15)); } else { - printf("L2CAP connection to device "); - print_bd_addr(event_addr); - printf(" failed. status code %u\n", packet[2]); + printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]); } break; diff --git a/example/rfcomm-cat.c b/example/rfcomm-cat.c index b18cb5e8d..36ccbe6b6 100644 --- a/example/rfcomm-cat.c +++ b/example/rfcomm-cat.c @@ -50,6 +50,9 @@ #include #include +// until next BTstack Cydia update +#include "compat-svn.c" + // input from command line arguments bd_addr_t addr = { }; uint16_t con_handle; @@ -164,9 +167,7 @@ int main (int argc, const char * argv[]){ } bt_register_packet_handler(packet_handler); - printf("Trying connection to "); - print_bd_addr(addr); - printf(" channel %d\n", rfcomm_channel); + printf("Trying to connect to %s, channel %d\n", bd_addr_to_str(addr), rfcomm_channel); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); run_loop_execute(); diff --git a/example/rfcomm-echo.c b/example/rfcomm-echo.c index ccdfc4d73..801916b83 100644 --- a/example/rfcomm-echo.c +++ b/example/rfcomm-echo.c @@ -46,6 +46,9 @@ #include #include +// until next BTstack Cydia update +#include "compat-svn.c" + // input from command line arguments bd_addr_t addr = { }; uint16_t con_handle; @@ -196,9 +199,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint bt_flip_addr(event_addr, &packet[2]); rfcomm_channel_nr = packet[8]; rfcomm_channel_id = READ_BT_16(packet, 9); - printf("RFCOMM channel %u requested for ", rfcomm_channel_nr); - print_bd_addr(event_addr); - printf("\n"); + printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(addr)); bt_send_cmd(&rfcomm_accept_connection, rfcomm_channel_id); break; diff --git a/example/rfcomm-test.c b/example/rfcomm-test.c index 1e18ba4a4..745e5d76d 100644 --- a/example/rfcomm-test.c +++ b/example/rfcomm-test.c @@ -46,6 +46,9 @@ #include #include +// until next BTstack Cydia update +#include "compat-svn.c" + // input from command line arguments bd_addr_t addr = { }; uint16_t con_handle; @@ -199,9 +202,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint bt_flip_addr(event_addr, &packet[2]); rfcomm_channel_nr = packet[8]; rfcomm_channel_id = READ_BT_16(packet, 9); - printf("RFCOMM channel %u requested for ", rfcomm_channel_nr); - print_bd_addr(event_addr); - printf("\n"); + printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr)); bt_send_cmd(&rfcomm_accept_connection, rfcomm_channel_id); break; diff --git a/example/test.c b/example/test.c index ab51089b3..32da33967 100644 --- a/example/test.c +++ b/example/test.c @@ -43,6 +43,9 @@ #include #include +// until next BTstack Cydia update +#include "compat-svn.c" + // bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard // bd_addr_t addr = {0x00, 0x19, 0x1d, 0x90, 0x44, 0x68 }; // WiiMote bd_addr_t addr = {0x76, 0x6d, 0x62, 0xdb, 0xca, 0x73 }; // iPad @@ -111,10 +114,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint uint16_t source_cid = READ_BT_16(packet, 13); con_handle = READ_BT_16(packet, 9); if (packet[2] == 0) { - printf("Channel successfully opened: "); - print_bd_addr(event_addr); - printf(", handle 0x%02x, psm 0x%02x, source cid 0x%02x, dest cid 0x%02x\n", - con_handle, psm, source_cid, READ_BT_16(packet, 15)); + printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, source cid 0x%02x, dest cid 0x%02x\n", + bd_addr_to_str(event_addr), con_handle, psm, source_cid, READ_BT_16(packet, 15)); if (psm == 0x13) { source_cid_interrupt = source_cid; @@ -130,9 +131,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint // bt_send_l2cap( source_cid, setLEDs, sizeof(setLEDs)); } } else { - printf("L2CAP connection to device "); - print_bd_addr(event_addr); - printf(" failed. status code %u\n", packet[2]); + printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]); exit(1); } break;