From 504c9121df2418d1b00fc338851c87ed631e7490 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 28 Feb 2010 21:45:22 +0000 Subject: [PATCH] added bt_use_tcp and adapted bt_open --- include/btstack/btstack.h | 1 + src/btstack.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/btstack/btstack.h b/include/btstack/btstack.h index ab70cba76..52f7fa4d6 100644 --- a/include/btstack/btstack.h +++ b/include/btstack/btstack.h @@ -56,6 +56,7 @@ typedef void (*btstack_packet_handler_t) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); // optional: if called before bt_open, TCP socket is used instead of local unix socket +// note: address is not copied and must be valid during bt_open void bt_use_tcp(const char * address, uint16_t port); // init BTstack library diff --git a/src/btstack.c b/src/btstack.c index 748c24eba..cae901c3c 100644 --- a/src/btstack.c +++ b/src/btstack.c @@ -59,13 +59,27 @@ static int btstack_packet_handler(connection_t *connection, uint16_t packet_type /** local globals :) */ static void (*client_packet_handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = dummy_handler; +static const char * daemon_tcp_address = NULL; +static uint16_t daemon_tcp_port = BTSTACK_PORT; + +// optional: if called before bt_open, TCP socket is used instead of local unix socket +// note: address is not copied and must be valid during bt_open +void bt_use_tcp(const char * address, uint16_t port){ + daemon_tcp_address = address; + daemon_tcp_port = port; +} // init BTstack library int bt_open(){ - // BTdaemon socket_connection_register_packet_callback(btstack_packet_handler); - btstack_connection = socket_connection_open_unix(); + + // BTdaemon + if (daemon_tcp_address) { + btstack_connection = socket_connection_open_tcp(daemon_tcp_address,daemon_tcp_port); + } else { + btstack_connection = socket_connection_open_unix(); + } if (!btstack_connection) return -1; return 0;