]> rtime.felk.cvut.cz Git - tiny-bt.git/commitdiff
outgoing data packet was modified. Now I can send packet and receive it on second...
authorDavid Plotek <ploted1@fel.cvut.cz>
Sun, 7 Dec 2008 22:20:31 +0000 (23:20 +0100)
committerDavid Plotek <ploted1@fel.cvut.cz>
Sun, 7 Dec 2008 22:20:31 +0000 (23:20 +0100)
src2/Makefile.omk
src2/bt_hw.c
src2/hciembeded.h
src2/testapp.c
src2/tiny_bt_hci_cmd.c
src2/tiny_bt_hci_cmd.h
src2/tiny_bt_hci_core.c
src2/tiny_bt_hci_core.h

index 160ee0d3e3f90041f7ecffc55da73a56493a59d9..6e7e3b7b15a77b077dff8924f7bca8f5752a16c4 100644 (file)
@@ -2,12 +2,12 @@ lib_LIBRARIES = tinybt
 tinybt_SOURCES = tiny_bt_hci_cmd.c tiny_bt_hci_core.c bt_hw.c
 
 
-bin_PROGRAMS = tiny_bt tiny_bt_sl tiny_bt_con
+bin_PROGRAMS = tiny_bt tiny_bt_con
 tiny_bt_SOURCES = testapp.c 
 tiny_bt_LIBS = tinybt
 
-tiny_bt_sl_SOURCES = testslave.c
-tiny_bt_sl_LIBS = tinybt
+#tiny_bt_sl_SOURCES = testslave.c
+#tiny_bt_sl_LIBS = tinybt
 
 tiny_bt_con_SOURCES = testcon.c
 tiny_bt_con_LIBS = tinybt
\ No newline at end of file
index ca59dfdf80d348ae84b4941fd92bb9b76837d0de..af5c1334a74ac6f3b3f0fe46d3b1ec88f6599449 100644 (file)
@@ -67,7 +67,13 @@ close_socket:
 
 int hw_bt_close_dev()
 {
-       return close(hw_dd);
+       while (close(hw_dd) < 0) {
+               perror("file closing interrupted\n");
+               if (errno == EINTR || errno == EIO)
+                       continue;
+               return -1;
+       }
+       return 0;
 }
 
 int hw_bt_write(__u8 *p_array, __u16 length)
index af4cd232fb23486554e70956242c28df76ed5c6d..915653cb6167c52facd1a834804c6f06a1cbf547 100644 (file)
@@ -205,6 +205,7 @@ enum {
 #define HCI_HOST_BUSY_PAIRING                  0x38
 
 /* ACL flags */
+#define ACL_PPP                        0x00
 #define ACL_CONT               0x01
 #define ACL_START              0x02
 #define ACL_ACTIVE_BCAST       0x04
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;
 }
 
index ef11b3dc5ee11cebd8fdb4e7c356e68e43590ff5..76bf09f080a230bc981c7500183838cdd874d892 100644 (file)
@@ -131,13 +131,15 @@ int send_hci_disconnect_cmd(__u16 handle)
        return 0;
 }
 
-int send_hci_data(char *p_data, __u16 lenght, __u16 *p_chandle)
+int send_hci_data(char *p_data, __u16 lenght, __u16 *p_chandle, __u16 PB_flag, __u16 B_flag)
 {
        hci_data_request dreq, *p_dreq = &dreq;
 
        p_dreq->p_data = p_data;
        p_dreq->lenght = lenght;
        p_dreq->p_chandle = p_chandle;
+       p_dreq->PB_flag = PB_flag;
+       p_dreq->B_flag = B_flag;
        
        if (send_data(p_dreq) < 0) {
                perror("hci_accept_conn_req_cmd wasn't sent\n");
@@ -177,12 +179,19 @@ int send_data(hci_data_request *p_dreq)
 {
        int ii;
        __u8 array[p_dreq->lenght + 4];
+       __u16 handle_flags;
        
+       printf("old handle:%d\n", *p_dreq->p_chandle);
+       p_dreq->PB_flag = p_dreq->PB_flag << 12;
+       p_dreq->B_flag = p_dreq->B_flag << 12;
+       handle_flags = *p_dreq->p_chandle | p_dreq->PB_flag | p_dreq->B_flag;
+       printf("new hadle:%d\n", handle_flags);  
        array[0] = HCI_ACLDATA_PKT;
-       memcpy(&array[1], p_dreq->p_chandle, 2);
+       memcpy(&array[1], &handle_flags, 2);
        memcpy(&array[3], &p_dreq->lenght, 2);
        memcpy(&array[5], p_dreq->p_data, p_dreq->lenght);
        
+       printf("Outgoing data:\n");
        for (ii = 0; ii < sizeof(array); ii++) {
                printf(" %x",array[ii]);
        }
index 95a3880cfca2c6629c926730b470b5fa17cb515d..fb72d76a04291c05388c67cd75e9f7f6660534c9 100644 (file)
@@ -66,6 +66,8 @@ typedef struct{
        char *p_data;
        __u16 lenght;
        __u16 *p_chandle;
+       __u16 PB_flag;
+       __u16 B_flag;
 } hci_data_request;
 
 
@@ -83,7 +85,7 @@ extern int send_hci_read_local_name_cmd(void);
 extern int send_hci_create_connection_cmd(bt_address *p_dest_addr);
 extern int send_hci_accept_conn_req_cmd(bt_address *p_address);
 extern int send_hci_disconnect_cmd(__u16 handle);
-extern int send_hci_data(char *p_data, __u16 lenght, __u16 *p_chandle);
+extern int send_hci_data(char *p_data, __u16 lenght, __u16 *p_chandle, __u16 PB_flag, __u16 B_flag);
 
 extern int send_cmd(hci_cmd_request *p_creq);
 extern int send_data(hci_data_request *p_dreq);
index 31abb0be4a93b0566cfeb4a8bfe70a2d1dfe181b..85117392e3e0eacfaa545e0796cb891125bd9a31 100644 (file)
@@ -31,8 +31,10 @@ static void callback_hci_all_commands(void *p_arg, void *p_recbuf)
 
        if (p_rp->status) {
                perror("command status error\n");
+               tiny_bt_finish();
                //return -1;
-               exit(-1); // !!!!!!!!!!!!!!!!
+               /*TODO call some app_callback and do something with error state */
+               exit(1); // !!!!!!!!!!!!!!!!
        }
                
        printf("command status with opcode: %d\n",p_rp->opcode);
@@ -92,7 +94,7 @@ static void callback_hci_create_connection(void *p_arg, void *p_recbuf)
        connection_complete_data *p_data = p_arg;
        evt_conn_complete *p_rp;
 
-       p_rp = (void *) (p_recbuf + 3);
+       p_rp = (void *) (p_recbuf);
        memcpy(p_data->p_handle, &p_rp->handle, 2);
        //memcpy(p_data->p_address,&p_rp->bdaddr,6);
        p_data->callback_app_connection_complete(p_data->p_handle);
@@ -226,6 +228,18 @@ int tiny_bt_init(__u8 dev_id)
        return 0;
 }
 
+int tiny_bt_finish()
+{      
+       int err;
+       
+       if ((err = hw_bt_close_dev()) < 0) {
+               perror("Impossible to close filedes\n");
+               return -1;
+       }
+       printf("filedescriptor was closed\n");
+       return 0;
+}
+
 int tiny_bt_process()
 {
        int len, j, index;
@@ -265,7 +279,16 @@ int tiny_bt_process()
                                        evt_array[index].p_callback(evt_array[index].p_data, p_recbuf);
                                        if (evt_array[index].actual_status != PERMANENT)
                                                evt_array[index].actual_status = DONE;
-                                       
+                               }
+
+                       } else if (p_hdr->evt == EVT_CONN_REQUEST) {
+                               if ((index = look_up_inarray(EVT_CONN_REQUEST, 0)) < 0) {
+                                       err = -1;
+                                       goto no_evt_exit;
+                               } else {
+                                       evt_array[index].p_callback(evt_array[index].p_data, p_recbuf);
+                                       if (evt_array[index].actual_status != PERMANENT)
+                                               evt_array[index].actual_status = DONE;
                                }
 
                        } else if (p_hdr->evt == EVT_MAX_SLOTS_CHANGE || p_hdr->evt == EVT_NUM_COMP_PKTS) {
@@ -307,6 +330,8 @@ int tiny_bt_process()
                                printf("%2.2X ", recbuf[j]);
                        }
                        printf("\n");
+                       /*TODO call some data callback for process data*/
+                       return 1;
                } else 
                        goto packet_wrong; 
        } else 
@@ -325,7 +350,7 @@ packet_wrong:
        return 0;
 
 no_data:
-       printf("There is no data on socket");
+       /*printf("There is no data on socket");*/
        return 0;
 }
 
@@ -563,9 +588,9 @@ int tiny_bt_disconnect(__u16 *p_handle, void(*callback_app_disconnect)(__u16 *p_
 
 }
 
-int tiny_bt_send_data(char *p_data, __u16 lenght, __u16 *p_chandle)
+int tiny_bt_send_data(char *p_data, __u16 lenght, __u16 *p_chandle, __u16 PB_flag, __u16 B_flag)
 {      
-       if (send_hci_data(p_data, lenght, p_chandle) < 0) {
+       if (send_hci_data(p_data, lenght, p_chandle, PB_flag, B_flag) < 0) {
                perror ("send_hci_cmd error\n");
                return -1;
        }
index b724c530f818683fdaa2cedf089ba6c5ac5860bd..398588c6eddb79b512e7416f6d3e88ab92bdeb1b 100644 (file)
@@ -97,6 +97,7 @@ typedef struct{
 extern void add_evt_toarray(expect_evt *p_evt);
 extern int look_up_inarray(__u8 evt_type, __u16 opcode);
 extern int tiny_bt_init(__u8 dev_id);
+extern int tiny_bt_finish();
 extern int tiny_bt_process();
 extern int tiny_bt_read_bd_addr(bt_address *p_dest, void(*callback_app_read_bd_addr)(bt_address *p_address));
 extern int tiny_bt_read_local_name(char *p_name, void(*callback_app_read_local_name)(char *p_name));
@@ -107,6 +108,6 @@ extern void tiny_bt_wait_for_connection(bt_address *p_dest_addr, void(*callback_
 extern int tiny_bt_accept_connection(bt_address *p_dest_addr,__u16 *p_handle, void(*callback_app_connection_complete)(__u16 *p_handle));
 extern void tiny_bt_disconnect_register(void(*callback_app_disconnect)(__u16 *p_handle, __u8 *p_reason));
 extern int tiny_bt_disconnect(__u16 *p_handle, void(*callback_app_disconnect)(__u16 *p_handle, __u8 *p_reason));
-extern int tiny_bt_send_data(char *p_data, __u16 lenght, __u16 *p_chandle);
+extern int tiny_bt_send_data(char *p_data, __u16 lenght, __u16 *p_chandle, __u16 PB_flag, __u16 B_flag);
 
 #endif