]> rtime.felk.cvut.cz Git - tiny-bt.git/blob - src2/testcon.c
Removed files not present and bachelor thesis CD
[tiny-bt.git] / src2 / testcon.c
1 /*
2 *  C Implementation: testapp
3 *
4 * Description: 
5 *
6 *
7 * Author: root <root@ubuntu>, (C) 2008
8 *
9 * Copyright: See COPYING file that comes with this distribution
10 *
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <errno.h>
16 #include <stdint.h>
17 #include "tiny_bt_hci_core.h"
18 #include "tiny_bt_hci_cmd.h"
19 #include "testcon.h"
20
21 bt_address rem_bd_addr_array[HCI_MAX_DEV];
22 bt_address rem_addr;
23 int glob_count = 0;
24 int stop = 0;
25 connection_hci connection,*p_connection=&connection;
26
27 void callback_app_read_bd_addr(bt_address *p_address)
28 {
29         printf("Read address is :");
30         printba(p_address);
31         tiny_bt_read_local_name(&(p_connection->master.name), callback_app_read_local_name);
32 }
33
34 void callback_app_read_local_name(char *p_name)
35 {
36         int i;
37         
38         printf("read name is:");
39         
40         for (i = 0; i < 8; i++) {
41                 printf("%c", *(p_name+i));
42         }
43         printf("\n");
44         printf("waiting for connection\n");
45         tiny_bt_wait_for_connection(&p_connection->slave.bdaddr, callback_app_connection_request);
46 }
47
48 void callback_app_connection_request(bt_address *p_address)
49 {
50         printf("Incoming connection request from:");
51         printba(p_address);
52         printf("for control:");
53         printba(&p_connection->slave.bdaddr);
54         
55         /*TODO some restrictions*/
56         tiny_bt_accept_connection(p_address,&p_connection->handle,callback_app_connection_complete);
57 }
58
59 void callback_app_connection_complete(__u16 *p_handle)
60 {
61         connection_state state = CONNECT;
62         
63         p_connection->con_state = state;
64         
65         printf("Connection complete handle:%d\n", *p_handle);
66         
67         tiny_bt_disconnect_register(callback_app_disconnect);
68 }
69
70 void callback_app_disconnect(__u16 *p_handle, __u8 *p_reason) 
71 {
72         printf("disconnection handle %d was completed\n", *p_handle);
73         tiny_bt_finish();
74         stop = 1;
75 }
76
77
78 int main(int argc, char* argv[])
79 {
80                 
81         if (tiny_bt_init(atoi(argv[1])) < 0) {
82                 perror("device impossible to ititialize\n");
83                 return -1;
84         }
85         printf("%d:in of main\n", atoi(argv[1]));
86         
87         if (tiny_bt_read_bd_addr(&p_connection->master.bdaddr, callback_app_read_bd_addr) < 0) {
88                 perror("tiny_bt_read_bd_addr error\n");
89                 return -1;
90         }
91         
92         while (1) {
93                 if (stop) 
94                         break;
95                 //ii--;
96                 if (tiny_bt_process() < 0) {
97                         perror("process error");
98                         break;
99                 }
100
101         }
102         printf("main finished\n");
103         return 0;
104 }
105