X-Git-Url: http://rtime.felk.cvut.cz/gitweb/tiny-bt.git/blobdiff_plain/e139768c51d9370475578e9476cd5eff3b3d99f5..80bd4dd9f2b4a1e7c7136a655f8aad1d7d73dc98:/src2/testcon.c diff --git a/src2/testcon.c b/src2/testcon.c new file mode 100644 index 0000000..f355cbd --- /dev/null +++ b/src2/testcon.c @@ -0,0 +1,105 @@ +/* +* C Implementation: testapp +* +* Description: +* +* +* Author: root , (C) 2008 +* +* Copyright: See COPYING file that comes with this distribution +* +*/ + +#include +#include +#include +#include +#include "tiny_bt_hci_core.h" +#include "tiny_bt_hci_cmd.h" +#include "testcon.h" + +bt_address rem_bd_addr_array[HCI_MAX_DEV]; +bt_address rem_addr; +int glob_count = 0; +int stop = 0; +connection_hci connection,*p_connection=&connection; + +void callback_app_read_bd_addr(bt_address *p_address) +{ + printf("Read address is :"); + printba(p_address); + tiny_bt_read_local_name(&(p_connection->master.name), callback_app_read_local_name); +} + +void callback_app_read_local_name(char *p_name) +{ + int i; + + printf("read name is:"); + + for (i = 0; i < 8; i++) { + printf("%c", *(p_name+i)); + } + printf("\n"); + printf("waiting for connection\n"); + tiny_bt_wait_for_connection(&p_connection->slave.bdaddr, callback_app_connection_request); +} + +void callback_app_connection_request(bt_address *p_address) +{ + printf("Incoming connection request from:"); + printba(p_address); + printf("for control:"); + printba(&p_connection->slave.bdaddr); + + /*TODO some restrictions*/ + tiny_bt_accept_connection(p_address,&p_connection->handle,callback_app_connection_complete); +} + +void callback_app_connection_complete(__u16 *p_handle) +{ + connection_state state = CONNECT; + + p_connection->con_state = state; + + printf("Connection complete handle:%d\n", *p_handle); + + tiny_bt_disconnect_register(callback_app_disconnect); +} + +void callback_app_disconnect(__u16 *p_handle, __u8 *p_reason) +{ + printf("disconnection handle %d was completed\n", *p_handle); + tiny_bt_finish(); + stop = 1; +} + + +int main(int argc, char* argv[]) +{ + + if (tiny_bt_init(atoi(argv[1])) < 0) { + perror("device impossible to ititialize\n"); + return -1; + } + printf("%d:in of main\n", atoi(argv[1])); + + if (tiny_bt_read_bd_addr(&p_connection->master.bdaddr, callback_app_read_bd_addr) < 0) { + perror("tiny_bt_read_bd_addr error\n"); + return -1; + } + + while (1) { + if (stop) + break; + //ii--; + if (tiny_bt_process() < 0) { + perror("process error"); + break; + } + + } + printf("main finished\n"); + return 0; +} +