]> rtime.felk.cvut.cz Git - tiny-bt.git/commitdiff
Version from David Plotek's bachelor thesis CD
authorMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 22 Jun 2009 14:43:21 +0000 (16:43 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 22 Jun 2009 14:43:21 +0000 (16:43 +0200)
src2/testapp.c
src2/testcon.c [new file with mode: 0644]
src2/testcon.h [new file with mode: 0644]
src2/tiny_bt_hci_cmd.c
src2/tiny_bt_hci_core.c

index 7404cbdb9e7e99e146944903795a27e4a3999965..ed6e11e2fce1a9210d76fed7c3c016d69d57f82e 100644 (file)
@@ -7,7 +7,7 @@
 * Author: root <root@ubuntu>, (C) 2008
 *
 * Copyright: See COPYING file that comes with this distribution
-*
+* TODO: this function is only for testing now, it will be replaced by L2CAP state machine.
 */
 
 #include <unistd.h>
diff --git a/src2/testcon.c b/src2/testcon.c
new file mode 100644 (file)
index 0000000..f355cbd
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+*  C Implementation: testapp
+*
+* Description: 
+*
+*
+* Author: root <root@ubuntu>, (C) 2008
+*
+* Copyright: See COPYING file that comes with this distribution
+*
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdint.h>
+#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;
+}
+
diff --git a/src2/testcon.h b/src2/testcon.h
new file mode 100644 (file)
index 0000000..3ed076b
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * C++ Interface: testapp
+ *
+ * Description: 
+ *
+ *
+ * Author: root <root@ubuntu>, (C) 2008
+ *
+ * Copyright: See COPYING file that comes with this distribution
+ */
+
+#ifndef __TESTCON
+#define __TESTCON
+
+extern void callback_app_read_bd_addr(bt_address *p_address);
+extern void callback_app_read_local_name(char *p_name);
+extern void callback_app_connection_request(bt_address *p_address);
+extern void callback_app_connection_complete(__u16 *p_handle);
+extern void callback_app_disconnect(__u16 *p_handle, __u8 *p_reason);
+
+#endif
+
index 76bf09f080a230bc981c7500183838cdd874d892..05e5c5bfde90812e438860bb6c1925c105d75691 100644 (file)
@@ -10,6 +10,7 @@
 #include "bt_hw.h"
 
 /************************** hci command functions**************************/
+/*these functions serve only for command assembling and sending*/
 int send_hci_inquiry_cmd(void)
 {
        inquiry_cp cmdp, *p_cmdp = &cmdp;
@@ -34,7 +35,7 @@ int send_hci_inquiry_cmd(void)
        }
        return 0;
 }
-/* fill up the input parameter address pointer by one address*/
+
 int send_hci_read_bd_addr_cmd(void)
 {
        hci_cmd_request creq, *p_creq = &creq;
index 85117392e3e0eacfaa545e0796cb891125bd9a31..6f9ff6e9a6e5b85facd78efbfbd54638dd359d5b 100644 (file)
@@ -23,7 +23,10 @@ static int evt_id;
 static int global_index;
 extern connection_hci connection;
 /******************************HCI callback functions*********************/
-
+/*when propriate event has occured and this event was registered in evt_array
+* these callback_hci..... are callled , they explore event's data field and call 
+* propriate upper protocol(or application) callback and also deliver, parameters
+* which has occured with inbound event */
 static void callback_hci_all_commands(void *p_arg, void *p_recbuf) 
 {
        evt_cmd_status *p_rp;
@@ -33,7 +36,9 @@ static void callback_hci_all_commands(void *p_arg, void *p_recbuf)
                perror("command status error\n");
                tiny_bt_finish();
                //return -1;
-               /*TODO call some app_callback and do something with error state */
+               /*TODO call some app_callback and do something with error state
+               * I only write out the inbound opcode , if any problem has occured
+               * it is not solve here yet. */
                exit(1); // !!!!!!!!!!!!!!!!
        }