rashmi v / Mbed 2 deprecated SS_SensePOC2P0_12Dec2017_USERPID

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of SS_SensePOC2P0_11Dec2017_USERPID by rashmi v

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bt.cpp Source File

bt.cpp

00001 #include "mbed.h"
00002 #include "sdcard.h"
00003 #include "struct.h"
00004 #include "eeprom_pgm.h"
00005 #include "main.h"
00006  
00007 #define ACK 0x00                                /// changed //16/06 #define all the values removing structure 
00008 #define START_OF_FILE       0x01
00009 #define END_OF_FILE         0x02
00010 #define DATA_TRFR           0x03
00011 #define NACK                0xFF
00012 #define SOS                 0xc0
00013 #define EOS                 0xc0
00014 #define NO_OF_SAMPLES       600                   //changed the buffer size from 150- 22/7/17- suhasini
00015 #define CHKSUM              0x80 
00016 #define STRUCTURE_LENGTH    26
00017 #define POC2P0_BT_RX_MSG_LEN 0x05U
00018 
00019 typedef struct __attribute__((__packed__))
00020 {
00021     uint8_t     sos;
00022     uint8_t     cmd;
00023     uint8_t     length;
00024     uint8_t     eos;
00025     uint8_t     chksum;
00026 
00027 }poc2p0_bluetooth_msg_request;
00028 
00029 poc2p0_bluetooth_msg_request poc2p0_bt_msg_req = {0};
00030 //static void poc2p0_ascii_to_hex(const uint8_t input_buffer[], uint8_t len);
00031 static void poc2p0_ascii_to_hex(const uint8_t input_buf[], uint8_t len_ip_buf, uint8_t output_buf[], uint8_t len_op_buf);
00032 static void hex_to_char(const char input_buffer[]);
00033 
00034 
00035 BLEMsg_info *bt_file;
00036 Point *myBleMsg;
00037  
00038 Serial mc(USBTX,USBRX);                  // serial terminal
00039 Serial blue(PTC4,PTC3);                 // communicating bluetooth through serial 
00040                  
00041 static uint32_t total_samples=0;        // variable to hold total number of samples
00042 Point b;                                // structure copy
00043 BLEMsg_info bt_file1;                   // structure copy
00044 static uint32_t total_file_size=0;      // to determine the size of the file 
00045 static uint32_t total_file_size_sent=0; 
00046 static uint32_t file_start=0;           // variable for 'for loop'
00047 //static uint32_t j=0;
00048 uint8_t count_send=0; 
00049 static uint32_t file_pointer_position=0;
00050 static uint32_t counter=0;
00051 static  uint32_t v1[NO_OF_SAMPLES];  
00052 uint8_t file=0;
00053 static uint32_t bt_pid = 0; 
00054 static char user_pid[10] = {0}; 
00055 
00056 
00057  
00058 uint8_t bt_send(uint8_t state_tx)
00059 {
00060     mc.format();   
00061     mc.baud(115200);
00062     blue.baud(115200);                  // baud rate of bluetooth
00063     bt_file=&bt_file1;                      
00064     myBleMsg=&b; 
00065     int8_t check_sum=0;
00066     uint8_t state_rx =0;
00067  
00068   switch(state_tx)
00069           {
00070  
00071        case 1:    
00072                   state_tx =0; 
00073                   counter=0;
00074                   total_file_size_sent=0; 
00075                   file_start=0;           
00076                   count_send=0;  total_samples=0;  
00077                   file_pointer_position=0;
00078                   bt_pid = get_btpid()+1;                           //added on 22/09/2017 nikita
00079                  //mc.printf("bt_pid = %d\n",get_btpid());
00080                 if(get_filepid()>=bt_pid)                           //check for pid and bluetooth pid by reading from file// modified to send till the current pid, 3rd nov// 
00081                 {
00082                     send_initial_string(); 
00083                     blue.printf("\n"); 
00084                     file=sd_open_read(bt_pid);                         // open the file for reading
00085                     total_file_size=file_size();                           // determined the file size 
00086                     state_rx = 1;  
00087                 }
00088                          
00089                 else 
00090                 {
00091                     state_rx =0;                                        //no files to send
00092                     //mc.printf("no file to send\n");  
00093                 }       
00094                 break;
00095                          
00096                    
00097        case 2:   total_samples=0; 
00098                  //file=sd_open_read(get_btpid());  
00099                 // total_file_size=file_size() ;                           // determined the file size 
00100                  sd_read1(bt_file1);                                    // read the sd card file
00101                  //mc.printf("sd file opened to read data in it\n");
00102                  myBleMsg->bt_msg=bt_file1;                              //copy the contents to the structure
00103                  send_structure();                                       // send the structure string
00104                  blue.printf("\n");   
00105                  //mc.printf("sent initial string\n");                    
00106                  total_samples= myBleMsg->bt_msg.num_samples.num_sample_ppg_dummy+myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp;
00107                  state_tx =0;
00108                  state_rx =2;
00109                  count_send=0;
00110                  total_file_size_sent=file_size1();
00111                  break;                 
00112  
00113  
00114         case 3:    
00115                 counter=0;
00116                 if(count_send<(total_samples/NO_OF_SAMPLES))
00117                 {
00118                     sd_read(v1,NO_OF_SAMPLES);      
00119                     counter=NO_OF_SAMPLES;               //read 1500 samples
00120                     send_data_str1(); 
00121                     for(file_start=0;file_start<(NO_OF_SAMPLES);file_start++)
00122                     {     
00123                        
00124                         blue.printf("%08x", v1[file_start]);
00125                            
00126                     }
00127                           
00128                     check_sum=checksum_rawdata((uint8_t *)v1,counter);               // calculating checksum            // calculating checksum
00129                     state_tx =0;
00130                     state_rx =3;
00131                     send_data_str2(check_sum);            // send the remaining part of the string
00132                   
00133                 }
00134                
00135                 else 
00136                 {
00137                     for(uint16_t l=0;l<NO_OF_SAMPLES;l++)
00138                     {    
00139                         v1[l]=NULL;
00140                     }
00141                             counter=(total_samples-( NO_OF_SAMPLES*count_send));
00142                             send_data_str1();
00143                             sd_read(v1,(total_samples-( NO_OF_SAMPLES*count_send)));
00144                        
00145                         for(file_start=0;file_start<(total_samples-( NO_OF_SAMPLES*count_send));file_start++)
00146                           {     
00147                              blue.printf("%08x", v1[file_start]);
00148                             
00149                            }
00150                                                                    
00151                           state_tx=0;
00152                           state_rx=4;
00153                           check_sum=checksum_rawdata((uint8_t *)v1,counter);               // calculating checksum
00154                           send_data_str2(check_sum);
00155                     }   
00156                      
00157                         total_file_size_sent=file_size1();
00158                         blue.printf("\n");  
00159                   break;        
00160                
00161          
00162         case 4:  // total_file_size_sent=file_size1();
00163                  if(total_file_size_sent==total_file_size)          // if the total file size is same as total file size
00164                      {                                         // then there is no more data to send in that particular file
00165                     
00166                         state_rx=5;
00167                         send_last_string();
00168                         blue.printf("\n"); 
00169                   
00170                      }
00171                 else   
00172                        {
00173                         
00174                          total_samples=0;   
00175                          sd_read1(bt_file1);               // read the sd card file
00176                        //  mc.printf("sd file opened to read data in it\n");
00177                          myBleMsg->bt_msg=bt_file1;         //copy the contents to the structure
00178                          send_structure();                                // send the initial string
00179                          blue.printf("\n");   
00180                        //  mc.printf("sent initial string\n");                    
00181                          total_samples= myBleMsg->bt_msg.num_samples.num_sample_ppg_dummy+myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp;
00182                          state_tx =0;
00183                          state_rx =2;
00184                          count_send=0;
00185                          total_file_size_sent=file_size1();
00186                                 
00187                         }   
00188                        
00189    
00190  
00191  
00192          }
00193  
00194    return state_rx;     
00195         
00196   }           
00197  
00198  
00199  
00200  
00201 uint8_t bt_receive (uint8_t state_rx)
00202 {
00203        
00204 unsigned char state_tx =1;                                                      //state for transmitting 
00205 uint8_t string_length_rx=0;
00206 char ack_rx[2];                                                                 // varibale to receive ack from the bluetooth 
00207 char chksum_rx[3]; 
00208 char btdata_received[17];
00209  
00210  
00211 while (blue.readable()!= NULL)                                                    // reading string from bluetooth app
00212    {
00213        blue.scanf("%17s", btdata_received);
00214        //mc.printf("%s\r\n", btdata_received);
00215 
00216     }                                 
00217    
00218         string_length_rx = strlen(btdata_received);                                // storing the length of the string received
00219         memcpy(ack_rx, btdata_received+1, 2);                                       // reading the ack received
00220         memcpy(chksum_rx, btdata_received+(string_length_rx-2), 3);                  // reading the checksum received
00221         //mc.printf("%s\r\n",ack_rx);
00222         //mc.printf("%s\r\n",chksum_rx);
00223     
00224      switch(state_rx)
00225          {
00226                 
00227           case 1:                                                                   // wait for the ack
00228                       state_rx=0;
00229                       myBleMsg->proto=ACK;
00230                  if ((strcmp(ack_rx ,"00") == NULL ) && (strcmp(chksum_rx ,"80" ) == NULL))                             // check for ack and checksum
00231                
00232                      {
00233                        
00234                        state_tx=2;
00235                       }
00236                     
00237                     else 
00238                     
00239                       { 
00240                        
00241                         state_tx=1;
00242                         sd_close();
00243                       }
00244                    break;                 
00245  
00246          case 2:      state_rx =0;                        //wait for the ack
00247                   
00248                    if ((strcmp(ack_rx ,"00") == NULL ) && (strcmp(chksum_rx ,"80" ) == NULL))  
00249                         {
00250                 
00251                           state_tx=3;
00252                           file_pointer_position=total_file_size_sent;
00253                         }
00254                     
00255                     else 
00256                     
00257                         { 
00258                       
00259                         state_tx=2;
00260                         setpos1(file_pointer_position);
00261                         //sd_close();                                                     //file closed which was opened earlier because it opens again in bt_send case 1
00262              
00263                         }
00264                     //blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx);
00265                     break;
00266  
00267                 
00268      case 3:       
00269                    state_rx =0;
00270                 if ((strcmp(ack_rx ,"00") == NULL ) && (strcmp(chksum_rx ,"80" ) == NULL))  
00271                       {
00272                      
00273                          state_tx=3;
00274                          count_send=count_send+1;
00275                          file_pointer_position=total_file_size_sent;
00276                       }
00277                     
00278                   else 
00279                     
00280                       { 
00281                        
00282                         state_tx=3;
00283                         file_start=file_start- NO_OF_SAMPLES;
00284                         setpos1(file_pointer_position);
00285                       }
00286                
00287                    break;    
00288                                             
00289      case 4:       
00290                    state_rx =0;
00291                if ((strcmp(ack_rx ,"00") == NULL ) && (strcmp(chksum_rx ,"80" ) == NULL))  
00292                       {
00293                          state_tx=4;
00294                          count_send=count_send+1;
00295                          file_pointer_position=total_file_size_sent;
00296                       }
00297                     
00298                   else 
00299                     
00300                       { 
00301                        
00302                         state_tx=3;
00303                         file_start=file_start- NO_OF_SAMPLES;
00304                         setpos1(file_pointer_position);
00305                       } 
00306                    break;                
00307                  
00308  
00309       case 5:      state_rx = 0;
00310                if ((strcmp(ack_rx ,"00") == NULL ) && (strcmp(chksum_rx ,"80" ) == NULL))  
00311                 {
00312                     sd_close();
00313                     increment_btpid();                // increment the bluetooth pid and write in the file
00314                     //mc.printf("next file");   
00315                     //mc.printf("bt_pid = %d\n",get_btpid());    
00316                     state_tx=1;
00317                           
00318                 }
00319                        
00320                 else 
00321                 {
00322                     state_tx = 4;   
00323                        
00324                 }           
00325                 break;
00326  
00327   }
00328  
00329    return state_tx;          
00330   }           
00331    
00332  
00333  
00334  
00335  
00336  
00337              
00338 void send_structure()                                 // function to send the structure to bluetooth
00339 {
00340     myBleMsg->start_of_string=SOS;
00341     myBleMsg->length_file = STRUCTURE_LENGTH;
00342     myBleMsg->proto=DATA_TRFR;                      // data transfer mode
00343     blue.printf("%02x",myBleMsg->start_of_string); 
00344     blue.printf("%02x",myBleMsg->proto);
00345     blue.printf("%08x",myBleMsg->length_file);      //changed the sequence 
00346     blue.printf("%08x",myBleMsg->bt_msg.length); 
00347     blue.printf("%02x",myBleMsg->bt_msg.device_id); 
00348     //blue.printf("%08x",myBleMsg->bt_msg.patient_id);                            //changed to 10 
00349     for (uint8_t i = 0; i < sizeof(myBleMsg->bt_msg.patient_id); i++)
00350     {
00351         blue.printf("%02x",myBleMsg->bt_msg.patient_id[i]);
00352         mc.printf("%02x",myBleMsg->bt_msg.patient_id[i]);
00353     }
00354     blue.printf("%02x",myBleMsg->bt_msg.date_time.date);     
00355     blue.printf("%02x",myBleMsg->bt_msg.date_time.month);  
00356     blue.printf("%02x",myBleMsg->bt_msg.date_time.year);  
00357     blue.printf("%02x",myBleMsg->bt_msg.date_time.hour);      
00358     blue.printf("%02x",myBleMsg->bt_msg.date_time.mins);  
00359     blue.printf("%02x",myBleMsg->bt_msg.date_time.sec);  
00360     blue.printf("%02x",myBleMsg->bt_msg.test_type);   
00361     blue.printf("%04x",myBleMsg->bt_msg.sampling_freq); 
00362     blue.printf("%04x",myBleMsg->bt_msg.num_samples. num_sample_ppg_dummy); 
00363     blue.printf("%04x",myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp); 
00364     blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_sbp_dummy);   
00365     blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp); 
00366     myBleMsg->end_of_string=EOS;  
00367     myBleMsg->chk_sum = checksum_struct((uint8_t *)myBleMsg, sizeof(Point));
00368     blue.printf("%02x",myBleMsg->end_of_string);
00369     blue.printf("%02x",myBleMsg->chk_sum);
00370                
00371     
00372     }
00373     
00374 void send_initial_string()                // function to send the initial string at the start f communication to bluetooth
00375 {              
00376  
00377     uint8_t sum_init=0  ;               
00378     myBleMsg->start_of_string=SOS;
00379     myBleMsg->length_file=0;
00380     myBleMsg->proto=START_OF_FILE;
00381     sum_init=checksum_init();
00382     myBleMsg->chk_sum=sum_init;
00383     blue.printf("%02x",myBleMsg->start_of_string);
00384     blue.printf("%02x",myBleMsg->proto); 
00385     blue.printf("%08x",myBleMsg->length_file);     // chnged
00386     myBleMsg->end_of_string=EOS;  
00387     blue.printf("%02x",myBleMsg->end_of_string);
00388     blue.printf("%02x",myBleMsg->chk_sum);
00389     
00390     }
00391   
00392    
00393 uint8_t checksum_init()          // function to calculate the checksum for the initial string
00394  {
00395   
00396   uint32_t sum = 0;
00397   uint8_t chksum_init = 0;
00398   sum=SOS+EOS+START_OF_FILE; 
00399   chksum_init = sum & 0x000000FF;
00400   return chksum_init;
00401   }
00402  
00403 uint8_t checksum_last()        // function to calculate the checksum for the last string
00404  {
00405   
00406   uint32_t sum = 0;
00407   uint8_t chksum_last = 0;
00408   sum=SOS+EOS+END_OF_FILE; // changed //16/06 #define all the values removing structure 
00409   chksum_last=sum & 0x000000FF;
00410   return chksum_last;
00411   }    
00412     
00413 void send_last_string()                 // function to send the last string to the bluetooth // which determines the end of file
00414 {
00415     uint8_t sum_last=0;
00416     myBleMsg->start_of_string = SOS;
00417     myBleMsg->length_file = 0;
00418     myBleMsg->proto=END_OF_FILE;
00419     sum_last=checksum_last();
00420     myBleMsg->chk_sum=sum_last;
00421     blue.printf("%02x",myBleMsg->start_of_string);
00422     blue.printf("%02x",myBleMsg->proto); 
00423     blue.printf("%08x",myBleMsg->length_file);     // chnged
00424     myBleMsg->end_of_string=EOS;  
00425     blue.printf("%02x",myBleMsg->end_of_string);
00426     blue.printf("%02x",myBleMsg->chk_sum);
00427                 
00428 }
00429        
00430 void send_data_str1()       // function to send a part of the structure // after this raw data is sent//
00431 {
00432     myBleMsg->start_of_string=SOS;
00433     myBleMsg->length_file=(counter*4);
00434     myBleMsg->proto=DATA_TRFR;
00435     blue.printf("%02x",myBleMsg->start_of_string); 
00436     blue.printf("%02x",myBleMsg->proto);                   // chnaged
00437     blue.printf("%08x",myBleMsg->length_file);
00438  
00439 }
00440     
00441     
00442     
00443 void send_data_str2(uint8_t check_sum)          // after raw data// this last part of structure is sent
00444 {          
00445     myBleMsg->chk_sum=check_sum;
00446     myBleMsg->end_of_string=EOS;  
00447     blue.printf("%02x",myBleMsg->end_of_string);
00448     blue.printf("%02x",myBleMsg->chk_sum);
00449     
00450 }
00451     
00452  
00453 uint8_t checksum_struct(const uint8_t data[], uint16_t numBytes)         // calculating checksum for 
00454 {
00455     uint32_t chksum_struct = 0;
00456     uint16_t index = 0;
00457     
00458     for (index=0U; index < (numBytes-1); index++)
00459     {
00460           chksum_struct += data[index];  
00461           //mc.printf("data=%02x\n",data[index]);
00462         
00463     }
00464   // blue.printf("%08x\n",chksum_struct);  
00465   return chksum_struct;
00466 }
00467  
00468  
00469 uint8_t checksum_rawdata(const uint8_t data[], uint32_t numBytes)          // this function to calculate the checksum for the raw data
00470 {
00471  
00472     uint32_t sum=0;
00473     uint8_t  chksum_datatrfr=0;
00474     uint32_t index = 0;
00475     uint32_t index1 = 0;
00476     sum += SOS;
00477     sum += DATA_TRFR;  
00478     index1=(numBytes*4);
00479     sum +=(index1>>(8*0))&0xFF;
00480     sum +=(index1>>(8*1))&0xFF; 
00481  
00482     for (index=0U; index<(numBytes*4); index++)
00483     { 
00484     sum += data[index];
00485     }
00486  
00487     sum+=EOS;
00488  
00489     chksum_datatrfr = sum & 0x000000FF;
00490  //mc.printf("chksum_datatrfr=%02x\n",chksum_datatrfr);
00491     return chksum_datatrfr;
00492 }
00493  
00494 
00495 // this function checks bluetooth command and if any byte received it process
00496 // that command and assigned and return touch state
00497 uint8_t poc2p0_bt_receive (uint8_t curr_touch_state)
00498 { 
00499     uint8_t bt_rx_buffer[31] = {0};
00500     uint8_t usr_pid_hex[15] = {0};
00501     uint8_t cal_chksum = 0xFFu;
00502     uint8_t touch_state = 0x00u;
00503     char user_pid_char[20];
00504     //const char *ptr = user_pid_char;
00505     //uint8_t ch = 0 ;
00506     //uint8_t n = 0;
00507     //uint8_t buff_index = 0;
00508     uint8_t usr_pid_chksum = 0;
00509         
00510     //if (mc.readable()!= NULL)                                                 // reading string from putty
00511     if (blue.readable()!= NULL)                                                 // reading string from bluetooth
00512     {
00513         //wait_ms(50);                                                          //commented on 16-NOV rashmi
00514         blue.scanf("%31s",bt_rx_buffer);
00515         //mc.scanf("%31s",bt_rx_buffer);
00516               
00517         mc.printf("\n\r Command =");
00518         mc.printf("%s\r\n", bt_rx_buffer); 
00519         
00520         //poc2p0_ascii_to_hex ((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer));
00521         poc2p0_ascii_to_hex((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer), (uint8_t *)&poc2p0_bt_msg_req, sizeof(poc2p0_bt_msg_req));
00522           
00523     }  
00524     
00525     if(poc2p0_bt_msg_req.cmd == TEST_SCREEN_REQ)
00526     { 
00527         memcpy(user_pid_char,bt_rx_buffer+6,20); 
00528         hex_to_char((const char *)user_pid_char);
00529         mc.printf("User pid = %s\n",user_pid_char);
00530         /*while ( *ptr )
00531         {
00532             if ( sscanf(ptr, "%2x%n", &ch, &n) != 1 )                             //ch -> holds data ; n-> no. of characters read
00533             {
00534                 break;
00535             }
00536             ptr += n;
00537             user_pid[buff_index++] = char(ch);
00538         }
00539         mc.printf("User pid after copy = %s\n",user_pid);
00540         */
00541         
00542         poc2p0_ascii_to_hex((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer), (uint8_t *)usr_pid_hex, sizeof(usr_pid_hex));
00543         usr_pid_chksum = usr_pid_hex[14];
00544         mc.printf("usr_pid_chksumksum = %02x\n",usr_pid_chksum);
00545         cal_chksum = checksum_struct((uint8_t *)usr_pid_hex+1, (sizeof(usr_pid_hex)-1));
00546           
00547     }
00548     else
00549     {
00550        cal_chksum = checksum_struct((uint8_t *)&poc2p0_bt_msg_req.cmd, (sizeof(poc2p0_bt_msg_req)-1));
00551     }
00552     
00553     //if ((cal_chksum == poc2p0_bt_msg_req.chksum) || (cal_chksum == usr_pid_chksum))
00554     //{
00555         switch (poc2p0_bt_msg_req.cmd)
00556         {
00557         case STRT_BP_TEST_REQ:
00558             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00559             touch_state = TOUCH_STATE_BP_TEST_SCREEN;
00560             break;
00561 
00562         case STRT_BG_FBS_TEST_REQ:
00563             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00564             eprom_write_16(20,0);                                               //added on 14-Nov by rashmi
00565             touch_state = TOUCH_STATE_BG_TEST_SCREEN;
00566             break;
00567 
00568         case STRT_BG_PP_TEST_REQ:
00569             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00570             eprom_write_16(20,1);                                               //added on 14-Nov by rashmi 
00571             touch_state = TOUCH_STATE_BG_TEST_SCREEN;
00572             break;
00573 
00574         case STRT_BG_RAN_TEST_REQ:
00575             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00576             eprom_write_16(20,2);                                               //added on 14-Nov by rashmi
00577             touch_state = TOUCH_STATE_BG_TEST_SCREEN;
00578             break;
00579 
00580         case STRT_ECG_TEST_REQ:
00581             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00582             touch_state = TOUCH_STATE_ECG_SCREEN;
00583             break;
00584 
00585         case DATA_SYNC_REQ:
00586             //poc2p0_send_device_msg_res(DATA_SYNC_MSG_ACCEPTED_RES);
00587             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00588             touch_state = 12 ;                                                  //TOUCH_STATE_DATA_SYNC_SCREEN
00589             break;
00590 
00591         case HEARTBEAT_REQ:
00592             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00593             mc.printf("curr_touch_state: %2x\n",curr_touch_state);
00594             if ((curr_touch_state == TOUCH_STATE_HOME_SCREEN)||(curr_touch_state == TOUCH_STATE_TEST_SCREEN))
00595             {
00596                 poc2p0_send_device_heartbeat_msg_res(curr_touch_state);
00597             }
00598             break;
00599 
00600         case HOME_SCREEN_REQ:
00601             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00602             touch_state = TOUCH_STATE_HOME_SCREEN;
00603             poc2p0_send_device_msg_res(HOME_SCREEN_MSG_ACCEPTED_RES);
00604             break;
00605 
00606         case TEST_SCREEN_REQ:
00607             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00608             touch_state = TOUCH_STATE_TEST_SCREEN;
00609             poc2p0_send_device_msg_res(TEST_SCREEN_MSG_ACCEPTED_RES);
00610             break;
00611         
00612         case SD_READ_REQ:
00613             mc.printf("\n\r cal_chksum = %2x\n", cal_chksum); 
00614             touch_state = 15;           
00615             break;    
00616             
00617 
00618         default:
00619             break;
00620         }
00621     //}
00622   
00623      memset((void *)bt_rx_buffer,0x00,sizeof(bt_rx_buffer));
00624      memset((void *)&poc2p0_bt_msg_req,0x00,sizeof(poc2p0_bt_msg_req));              //to clear the structure else the command would be in the loop
00625      return touch_state;
00626 }
00627 
00628 // this function use to convert data from ascii to hex
00629 /*static void poc2p0_ascii_to_hex(const uint8_t input_buf[], uint8_t len)
00630 {
00631     uint8_t i = 0;
00632     uint8_t j = 0;
00633     uint8_t temp_ms_nibble = 0;
00634     uint8_t temp_ls_nibble = 0;
00635     uint8_t temp_buf[len];
00636 
00637     for (i = 0,j = 0; i < len; i+=2, ++j)
00638     {
00639         temp_ms_nibble = input_buf[i] > '9' ? (input_buf[i]|32) - 'a' + 10 : input_buf[i] - '0';      
00640         temp_ls_nibble = input_buf[i+1] > '9' ? (input_buf[i+1]|32) - 'a' + 10 : input_buf[i+1] - '0';
00641         temp_buf[j] = (temp_ms_nibble << 4) | temp_ls_nibble;
00642         mc.printf("\n\r msg_SOS = %2x", temp_buf[j]);
00643     }
00644     
00645     memcpy(&poc2p0_bt_msg_req, &temp_buf, sizeof(poc2p0_bt_msg_req));
00646     
00647     return;
00648 } */
00649   
00650 
00651 char* get_userpid(void)
00652 {
00653     return user_pid;
00654 }
00655 
00656 
00657 
00658 
00659 static void poc2p0_ascii_to_hex(const uint8_t input_buf[], uint8_t len_ip_buf, uint8_t output_buf[], uint8_t len_op_buf)
00660 {
00661     uint8_t i = 0;
00662     uint8_t j = 0;
00663     uint8_t temp_ms_nibble = 0;
00664     uint8_t temp_ls_nibble = 0;
00665     uint8_t temp_buf[len_ip_buf];
00666 
00667     for (i = 0,j = 0; i < len_ip_buf; i+=2, ++j)
00668     {
00669         temp_ms_nibble = input_buf[i] > '9' ? (input_buf[i]|32) - 'a' + 10 : input_buf[i] - '0';      
00670         temp_ls_nibble = input_buf[i+1] > '9' ? (input_buf[i+1]|32) - 'a' + 10 : input_buf[i+1] - '0';
00671         temp_buf[j] = (temp_ms_nibble << 4) | temp_ls_nibble;
00672         //mc.printf("\n\r msg_SOS = %2x", temp_buf[j]);
00673     }
00674     
00675     memcpy(output_buf, &temp_buf, len_op_buf);
00676     
00677     return;
00678 } 
00679 
00680 
00681 static void hex_to_char(const char input_buffer[])
00682 {
00683     const char *ptr = input_buffer;
00684     uint8_t ch = 0 ;
00685     uint8_t n = 0;
00686     uint8_t buff_index = 0;
00687     
00688     while ( *ptr )
00689     {
00690             if ( sscanf(ptr, "%2x%n", &ch, &n) != 1 )                           //ch -> holds data ; n-> no. of characters read
00691             {                                                                   //sscanf returns 1 when the format matches,there is no data
00692                 break;
00693             }
00694             ptr += n;
00695             user_pid[buff_index++] = char(ch);
00696     }
00697     mc.printf("User pid after copy = %s\n",user_pid);
00698             
00699 }
00700 
00701 
00702 
00703 
00704 
00705 
00706 
00707    
00708