]> rtime.felk.cvut.cz Git - mirosot.git/blobdiff - bluetooth/bth_main.c
Comments translated to english
[mirosot.git] / bluetooth / bth_main.c
index b48e8de99c1ff171f71e603ec989ed9531ca02db..69e95b1067657d99ed76ae198bc1db7151d45f35 100644 (file)
@@ -61,18 +61,21 @@ void  *bth_pole_adrr_check_packet[LENCOMMAND]={NULL,NULL,NULL,NULL,NULL,NULL,NUL
 bths_command_buf_info bth_check_buf_info={LENCOMMAND,0,0};
 /***********************************************************************************/
 
-/*kontroluje synchoronizaci prijimanych dat pomoci TPU jednotky*/
+/*FIXME this check synchronisation of received data using TPU unit of CPU*/
 uint8_t bth_controll_flag=0;
 
 
 /**-------------------------------------------------------------------------------*/
-/*----- odeslani command prikazu, pokud je local bluetooth volny k odeslani------*/
-/*  0 = data presunuta do SCI bufferu = budou odeslana, bluetooth zarizeni je volne
-    1 = prikaz se nepovedlo presunout do SCI bufferu, ale bluet device je volne
-    2 = bluetooth zarizeni je zamestnane, tj. data se nepresunula do bufferu
-    3 = v potvrzovacim zasobniku neni uz misto*/
+/*FIXME ----- sending of command, if the local bluetooth is free (ready to send)------*/
+/*  0 = data moved to SCI buffer = they will be sent, bluetooth device is free
+    1 = it wasn't possible to move tha command to SCI bufferu, but bluet device is free
+    2 = bluetooth device is busy, ie. data were not moved to the bufferu
+    3 = there is no space left in confirmation queue*/
 
 /**
+ * After this function is called, the packet, which is in the command queue, is sent. If there is no new 
+ * packet or the device is busy, nothing is done.
+ *
  * Po zavolani funkce, se odesle paket, ktery je zarazen ve fronte paketu k odeslani (bth zazizeni je
  * volne), pokud neni novy paket nebo zazizeni neni volne, nic se nevykona
 */
@@ -81,22 +84,22 @@ int  bth_send_queue(void)
   int i;
   int hp_size;
   if(bth_local_info.busy!=0)
-    {return 1;}; //zarizeni neni volne
+    {return 1;}; //device is busy
   if(bth_com_buf_info.aktual==bth_com_buf_info.sent) //PRAVDEPODOBNE neni co odesilat
   {
     if(bth_com_buf_info.sent<(LENCOMMAND-2))
     {
       if(bth_pole_adrr_comm_packet[bth_com_buf_info.sent+1]==NULL)
-      {return 1;}; //URCITE neni co odesilat
+      {return 1;}; //There is certainly nothing to send
     }
     else
     {
       if(bth_pole_adrr_comm_packet[0]==NULL)
-      {return 1;}; //URCITE neni co odesilat
+      {return 1;}; //There is certainly nothing to send
     };
   };
     
-  /*bth_send_packet(AdrOdkud,kolikBytu;)*/
+  /*bth_send_packet(AdrFrom,howmanyBytes;)*/
     switch(*(uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.sent])
     {
       case HCI_ACLDATA_PKT:
@@ -116,14 +119,14 @@ int  bth_send_queue(void)
       case HCI_COMMAND_PKT:
         hp_size=((uint16_t)*(((uint8_t*)bth_pole_adrr_comm_packet[bth_com_buf_info.sent])+HCI_PKT_SIZE+2)+HCI_COMMAND_HDR_SIZE+HCI_PKT_SIZE);
         if(!(bth_send_packet(bth_pole_adrr_comm_packet[bth_com_buf_info.sent],hp_size)))
-        {/*odeslano - zaradim prikaz k moznosti potvrzeni*/
+        {/*sent - add the command to allow confirmation*/
           for(i=0; i<LENCOMMAND; i++)
           {
             if(bth_pole_adrr_check_packet[i]==NULL)
             {
               bth_pole_adrr_check_packet[i]=bth_pole_adrr_comm_packet[bth_com_buf_info.sent];
               bth_pole_adrr_comm_packet[bth_com_buf_info.sent]=NULL;
-              /*nastavim adresu pro pristi command prikaz - princip kruhove zasobniku*/
+              /*set the address for the next command - principle of ring buffer*/
               if(bth_com_buf_info.sent<(LENCOMMAND-2)){bth_com_buf_info.sent++;}
               else{ bth_com_buf_info.sent=0;};
               return 0;
@@ -138,10 +141,14 @@ int  bth_send_queue(void)
 
 
 /**
- * Pomocna funkce
- * Prevod hexa znaku do tisknutelne podoby. V tomto tvaru se odesle po seriov. rozhranni do PC
+ * Auxiliary function
+ * Convert hexadecimal character to ASCII. It is then sent to serial line
  */
-
+//*************************** bth_conv_char_text *****************************
+// used to convers int into ascii letter and print it on serial
+// INPUT zn: interger to convert and print
+// OUTPUT :none
+//*************************************************************************** 
 void bth_conv_char_text(uint8_t zn)
 { uint8_t map_leters[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
   uint8_t val;
@@ -157,12 +164,13 @@ void bth_conv_char_text(uint8_t zn)
 
 
 /**
- *Funkce odesle data o velikosti hp_size od adresy hp do bth (UART)
+  //FIXME
+ *Sends data of the size hp_size from address hp to the bluetooth device (UART)
  */
 int bth_send_packet(uint8_t *hp, uint16_t hp_size)
 {  
   int zn,i;
-  /*je bluetooth zarizeni volne, nebo zamestnano predchozim prikazem?*/
+  /*is bluetooth device free, or is it busy by the previous command?*/
   if(bth_local_info.busy==0)
   {
 #ifndef BTH_LX
@@ -177,32 +185,33 @@ int bth_send_packet(uint8_t *hp, uint16_t hp_size)
     };
 #endif
     bth_local_info.busy=1;
-    return(0);    //vsechno odeslano ==== OK =====
+    return(0);    //everything sent ==== OK =====
   }
   else
   {
-    return 2;    //zamestnane
+    return 2;    //busy
   };
 };
 
 /**
- *Funkce vlozi znak do fronty
+ *Inserts a character to the queue
  */
 
 inline int bth_que_put(bth_que_t *q, int c)
 {
   uint8_t *p;
-  p=q->ip;                       //nastav se na aktual pozici v souboru
-  *(p++)=c;                      //na nasledujici pam. bunku uloz znak
-  if(p==q->buf_end) return -1;//buffer neni kruhovy p=q->buf_beg;
+  p=q->ip;                       //FIXME set us to the actual position in the file
+  *(p++)=c;                      //store the character to the next byte
+  if(p==q->buf_end) return -1;//this is not the ring buffer p=q->buf_beg;
 //  if(p==q->op) return -1;
   q->ip=p;
-  return 0;                      //pokud nejsou problemy, vrat znak, jinak -1
+  return 0;                      //in case of success return the character, otherwise -1
 }
 
 
 /**
- *prijaty HCI datovy paket je zaslan jako point to point
+//FIXME
+ *received HCI data packet is sent as point to point
 */
 
 int bth_pkt_type_pointopoint(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p, uint16_t size)
@@ -233,11 +242,11 @@ int bth_pkt_type_pointopoint(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p
           case 0x02:
             return(0);
         };
-        /*skutecna nefalcovana data ...*/
-        /*musim najit kanal s cislem cid pro zarizeni bth_dev_num*/
+        /*FIXME real data ...*/
+        /*We have to find the channel with the CID number for device bth_dev_num*/
         if(bth_find_chanal(bth_dev_num, bth_l2cap_packet.cid)>-1)
         {
-          /*TADY JSOU DOSLA DATA, KTERA UZ NEJSOU KONFIGURACNI*/
+          /*here are the received data, which are not used for confguration */
 
           
           bth_data=(uint8_t*)bth_p+L2CAP_HDR_SIZE;
@@ -253,7 +262,7 @@ int bth_pkt_type_pointopoint(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p
 //              VypisHexa((void*)((uint8_t*)bth_data+i),1);
             }else
             {
-              /*zasobnik plny, neni schopen prijmout dalsi znaky*/
+              /*queue is full, neni schopen prijmout dalsi znaky*/
 //              sci_rs232_sendch('.',sci_rs232_chan_default); //do PC
             };
           };
@@ -264,7 +273,7 @@ int bth_pkt_type_pointopoint(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p
         return(-5);
       };
       return(-1);
-    case 0x40: return(-3);  /*next data packet L2CAP*/ /*funkce neni rozepsana, prijmam jen 1pkt zpravy*/
+    case 0x40: return(-3);  /*next data packet L2CAP*/ /*function is not written, I receive only one pakcet of the message*/
     case 0x30: return (-4); /*Reserved for future use*/
     case 0x00: return (-4); /*Reserved for future use*/
   };
@@ -273,7 +282,7 @@ int bth_pkt_type_pointopoint(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p
 
 
 /**
- *prijaty HCI datovy paket je zaslan jako broadcast (nedopsana funkce)
+ *Received HCI data packet is sent as broadcast (not finished function)
  */
 int bth_pkt_type_broadcast(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p, uint16_t size)
 {
@@ -291,7 +300,7 @@ int bth_pkt_type_broadcast(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p,
 
 
 /**
- *prijaty HCI datovy paket je zaslan vramci picosite (nedopsana funkce)
+ *Received HCI data packet is send to piconet (not finished function)
  */
 int bth_pkt_type_piconet(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p, uint16_t size)
 {
@@ -309,7 +318,7 @@ int bth_pkt_type_piconet(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p, ui
 
 
 /**
- *budouci vyuziti (nedopsana funkce)
+ *Reserved for future (not finished)
  */
 int bth_pkt_type_reserved(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p, uint16_t size)
 {
@@ -321,7 +330,7 @@ int bth_pkt_type_reserved(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p, u
 /****************************************************************************/
 
 /**
- *pointry na funkce. Funkce jsou volany podle prijateho datoveho HCI peketu
+ *pointers to functions. Functions are called according to the received HCI pakcet
  */
 typedef int (*bth_kind_pkt)(uint16_t handle, uint8_t bound_flag, uint8_t *bth_p, uint16_t size);
 bth_kind_pkt bth_char_pkt_fce[]={
@@ -330,7 +339,7 @@ bth_kind_pkt bth_char_pkt_fce[]={
 
 
 /**
- *pointry na funkce. Funkce jsou volany podle event codu, dekodovaneho z  prijateho event HCI peketu
+ *pointrs to functions. Functions are called according to the event code, decoded from the received HCI packet
  */
 typedef int (*bth_p_ivent_fce)(uint8_t *bth_p, uint8_t size);
 bth_p_ivent_fce bth_event_array_fce[]={bth_evt_none,bth_evt_inquiry_complete, bth_evt_inquiry_result,
@@ -353,8 +362,7 @@ bth_p_ivent_fce bth_event_array_fce[]={bth_evt_none,bth_evt_inquiry_complete, bt
 
 
 /**
- *Hlavni funkce, ktera ulozi prijaty znak "c" (od bth) ulozi ho do vstupni fronty, zkontroluje zda-li
- * je paekt cely a pokud ano, tak zavola funkce pro jeho zpracovani (pro ACL HCI a pro Event HCI)
+ *The main function, which stores the received character "c" (from bth) to the input queue, checks if there is the whole pakcet in the queue and if so, it calls functions for processing the packet. (for ACL HCI and for Event HCI)
  */
 int bth_recieve_packet(int c)
 {
@@ -383,12 +391,12 @@ int bth_recieve_packet(int c)
   VypisHexa((uint8_t*)&c,1);
 #endif
   //VypisHexa((uint8_t*)&c,1);
-  bth_que_put(&bth_rs232_que_in, c); //ulozim prijaty znak do zasobniku
-  typ_paket=((uint8_t*)bth_rs232_que_in.buf_beg); //zjistim tzp paketu ACL, Even, SCO ...
+  bth_que_put(&bth_rs232_que_in, c); //store the received character to the queue
+  typ_paket=((uint8_t*)bth_rs232_que_in.buf_beg); //determine the type of the pakcet ACL, Even, SCO ...
   switch(*typ_paket)
   {
   case HCI_EVENT_PKT:
-    /*naplnim strukturu "hci_event_hdr" ze zasobniku - po bytech*/
+    /*fill in structure "hci_event_hdr" from the queue (bye by byte)*/
     store16(bth_event_packet.evt,  *(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE));
     store16(bth_event_packet.plen, *(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE+1));
 
@@ -403,22 +411,22 @@ int bth_recieve_packet(int c)
         };
         /*******/
     
-        /*pointer na fci prislusenijici  even codu*/
-        if(bth_event_packet.evt<EV_SUM_FC) //overeni existence fce
+        /*pointer to the function matching the event code*/
+        if(bth_event_packet.evt<EV_SUM_FC) //check whether the function exists
         {
           data_ad=(uint8_t*)(bth_rs232_que_in.buf_beg+HCI_EVENT_HDR_SIZE+HCI_PKT_SIZE);
           error_code=(*bth_event_array_fce[bth_event_packet.evt])(data_ad,bth_event_packet.plen);
-          bth_rs232_que_in.ip=bth_rs232_que_in.buf_beg;  //nastav se na zacatek, pro pristi event
+          bth_rs232_que_in.ip=bth_rs232_que_in.buf_beg;  //set to the beginning for the next event
         }else{
           bth_rs232_que_in.ip=bth_rs232_que_in.buf_beg;  //nastav se na zacatek, pro pristi event
           return (-1);
         };
         if(error_code>=0)
         {
-          // bth_error_detect_status((uint8_t)error_code); //error vypisy
+          // bth_error_detect_status((uint8_t)error_code); //error msg
         }
         else
-        {//bth_error_detect_event((uint8_t)(-error_code)); //error vypisy
+        {//bth_error_detect_event((uint8_t)(-error_code)); //error msg
         };
       };
     };
@@ -432,7 +440,7 @@ int bth_recieve_packet(int c)
         if((bth_rs232_que_in.ip-bth_rs232_que_in.buf_beg) == ((bth_acl_packet.dlen)+HCI_ACL_HDR_SIZE+HCI_PKT_SIZE))
         {
           
-          /*  **** kontrola sousednosti dvou znaku TPU3 ****   */
+          /*  **** check the adjacency of two characters TPU3 ****   */
           if(bth_controll_flag!=0)
           {
             bth_stop_TPU_counter();
@@ -442,25 +450,24 @@ int bth_recieve_packet(int c)
           __bthtomc16((uint8_t*)&(bth_acl_packet.handle),(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE+HCI_ACL_HDR____handle));
           bth_acl_packet.handle=bth_acl_packet.handle & 0x0fff;
           
-          /*prom 'char_acl_pkt' vyjadruje vlastnosti paketu, if point to point nebo broadcast, or char. L2CAP*/
+          /*variable 'char_acl_pkt' stores the properties of the packet, if it is point to point or broadcast, or char. L2CAP*/
           store16(char_acl_pkt, (0xf0&*(((uint8_t*)bth_rs232_que_in.buf_beg)+HCI_PKT_SIZE+HCI_ACL_HDR____handle+1)));
           
-          /*rozhodnuti o jaky paket se jedna (PtP,Piconet,broat...) a o jaky typ komunikace se zarizenim (L2CAP, HCI)*/
+          /*decide which packet is this (PtP,Piconet,broat...) and the type of communication (L2CAP, HCI)*/
           data_ad=(uint8_t*)bth_rs232_que_in.buf_beg+HCI_PKT_SIZE+HCI_ACL_HDR_SIZE;
           com_pr=char_acl_pkt&0xc0;
-          if(com_pr<COM_PROT_SUM_FC) //fce existuje
+          if(com_pr<COM_PROT_SUM_FC) //func exists
           {
             bth_char_pkt_fce[com_pr]
                 (bth_acl_packet.handle, char_acl_pkt&0x30, data_ad,bth_acl_packet.dlen);
           }
           else
           {
-            /*HCI data - nikoliv L2CAP - obsluha ani nahravani do
-            datoveho zas. neni napsano - predpoklada se zasilani dat pres L2CAP
-            viz. if pred timto else */
+            /*HCI data - not L2CAP - neither handling nor loading to data queue is not implemented. It is assumed
+              sending of data using L2CAP. See if before this else. */
           };
           bth_rs232_que_in.ip=bth_rs232_que_in.buf_beg;
-//        sci_rs232_sendch('\n',sci_rs232_chan_default); //do PC
+//        sci_rs232_sendch('\n',sci_rs232_chan_default); //to PC
         };
 
       };
@@ -470,7 +477,7 @@ int bth_recieve_packet(int c)
 
 
 /**
- * Funkce vola funkce, ktere jsou potrebne pro nastaveni zarizeni do slave rezimu
+ * Calls functions, which are necessary for setting the device to the slave mode.
 */
 void bth_parametr_slave(void)
 {
@@ -483,8 +490,8 @@ void bth_parametr_slave(void)
 
 
 /**
- * Funkce nastavi MC, aby mohl zasilat HCI pakety do bth zarizeni
- * Pokud jsou inicializovany TPU kanal, tak ho vynuluje a zastavi
+ * Sets the MCU up, so it can send HCI packets to bth device
+ * If TPU channels are initialized, it resets and stop it
 */
 void bth_start(void)
 {
@@ -502,7 +509,7 @@ void bth_start(void)
 
 
 /**
- * nastaveni zasobniku - inicializacni funkce
+ * Setting of the queue - initialization function
 */
 void bth_init(void)
 {
@@ -517,7 +524,7 @@ void bth_init(void)
 /****************************************************************************/
 
 /**
- * Pomocna funce, ktera slouzi k prevodum znaku an tisknutelne znaky
+ * Auxiliary function, which converts characetrs to the printable form
 */
 int VypisHexa(uint8_t *s, int delka)
 {
@@ -531,8 +538,8 @@ int VypisHexa(uint8_t *s, int delka)
     printf("%c",tisk[((zn>>4)&0x000F)]);
     printf("%c",tisk[zn & 0x000F]);
 #else
-    sci_rs232_sendch(tisk[(zn&0xf0)>>4],sci_rs232_chan_default); //do PC
-    sci_rs232_sendch(tisk[(zn&0x0f)],sci_rs232_chan_default); //do PC
+    sci_rs232_sendch(tisk[(zn&0xf0)>>4],sci_rs232_chan_default); //to PC
+    sci_rs232_sendch(tisk[(zn&0x0f)],sci_rs232_chan_default); //to PC
 #endif
   };