]> rtime.felk.cvut.cz Git - tiny-bt.git/blobdiff - src2/testapp.c
outgoing data packet was modified. Now I can send packet and receive it on second...
[tiny-bt.git] / src2 / testapp.c
index 2d44ade465acfd56b0603e322e752c49e2c1dd75..7404cbdb9e7e99e146944903795a27e4a3999965 100644 (file)
@@ -10,6 +10,7 @@
 *
 */
 
+#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -51,6 +52,8 @@ void callback_app_inquiry_RSSI(bt_address *p_address)
        
        if (count == 0) {
                rem_bd_addr_array[0] = *p_address;
+               printf("There is first device:");
+               printba(p_address);
                count++;
        } else {
                for (i = 0; i < count; i++) {
@@ -93,55 +96,69 @@ void callback_app_inquiry_complete(void)
                printf("There is no remote device suitable for connect\n");
                stop=1;
        }
+       /*
+       tiny_bt_finish();
+       stop = 1;
+       printf("Application finished\n");
+       */
 }
 
 void callback_app_connection_complete(__u16 *p_handle)
 {
-       char ar[6] = {"hallo "};
-
+       char ar[11] = {"hallo karel"};
+       char w2[15] = {"second messagee"};    
+       
        connection_state state = CONNECT;
        p_connection->con_state = state;
        printf("Connection complete handle:%d\n", *p_handle);
 
-       if (tiny_bt_send_data(ar, 6, p_handle) < 0) {
+       if (tiny_bt_send_data(ar, 11, p_handle, ACL_START, ACL_PPP) < 0) {
                printf("unable to send data\n");
        }
        
+       if (tiny_bt_send_data(w2, 15, p_handle, ACL_CONT, ACL_PPP) < 0) {
+               printf("unable to send data\n");
+       }
+       sleep(1);
        tiny_bt_disconnect(p_handle, 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(void)
+int main(int argc, char* argv[])
 {
-       int ii = 30000;
+       //int ii = 30000;
        
-       if (tiny_bt_init(0) < 0) {
+       if (tiny_bt_init(atoi(argv[1])) < 0) {
                perror("device impossible to ititialize\n");
-               return -1;
+               tiny_bt_finish();
+               exit(1);
        }
        printf("begin of main\n");
        
        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;
+               tiny_bt_finish();
+               exit(1);
        }
        
        while (1) {
                if (stop) 
-                       return -1;
-               //ii--;
+                       break;
                if (tiny_bt_process() < 0) {
                        perror("process error");
-                       return -1;
+                       tiny_bt_finish();
+                       stop = 1;
                }
 
        }
+       printf("main finished\n");
        return 0;
 }