created separate function for hex to char

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of SS_SensePOC2P0_11Dec2017_USERPID by rashmi v

Revision:
76:611154b3b597
Parent:
75:0feb6f993562
--- a/main.cpp	Mon Dec 11 12:24:19 2017 +0000
+++ b/main.cpp	Tue Dec 12 11:13:10 2017 +0000
@@ -87,7 +87,6 @@
 static void battery_status_monitoring();                                     //bluetooth status pin
 uint8_t touch(uint8_t state);                                               // touch state
 uint8_t display(uint8_t state1);                                            //  display state
-static void set_userpid(char *user_pid);
 static void ecg_bp_countdown(void);
 static void read_device_id(void);
 void sd_card_status(void);
@@ -391,14 +390,12 @@
     static uint8_t state=0;
     static uint8_t ecg_flag=0;                                  // ecg_flag to indicate the ecg test is already done for the same pid
     static uint8_t glc_flag=0;                                  // glc_flag to indicate the glc test is already done for the same pid
-    //uint16_t heart_rate=0; 
     
     switch(state1)                                                              // state for display screens
     {
 
       
       case 1: 
-                //DisableTouch();
                 //screen_main();                                                  //  main screen 
                 state1=0;
                 state=1;
@@ -409,17 +406,14 @@
                 //battery_status_display();                                       //Display battery status on LCD
                 pid = get_filepid() + 1;
                 state_touch = TOUCH_STATE_HOME_SCREEN;                          //added on 16-Nov rashmi
-                //EnableTouch();
                 break;
       
       case 2: 
-                //DisableTouch();
                 //screen_main_1();                                // System configration screen 
                 state1=0;
                 state=2;
                 nstate=state;
                 //battery_status_display();                                           //Display battery status on LCD
-                //EnableTouch();
                 // timer_debug.stop();
                 break;
                
@@ -432,11 +426,9 @@
                 nstate=state;
                 //battery_status_display(); 
                 state_touch = TOUCH_STATE_TEST_SCREEN;                          //added on 16-Nov rashmi
-                //EnableTouch();
                 break;
                 
       case 4: 
-                //DisableTouch();
                 if (glc_flag==1)                                // glc_flag=1 when already the reading has been taken 
                 {
                     //screen_again();    
@@ -450,14 +442,11 @@
                     state1=0;
                     state=4;
                     nstate=state;
-                }
-                //EnableTouch();
-                
+                }                
                 break;
      
      
      case 5:     
-               // DisableTouch();
                 if (ecg_flag==1)
                 {
                     //screen_again();
@@ -473,37 +462,29 @@
                     state=5;
                     nstate=state;
                 }
-                //EnableTouch();
                 break;
      
      case 6:   
-                //DisableTouch();
                 //screen_bp();                                                 // bp main screen
                 state1=0;
                 state=8;
-                nstate=state;         
-                //EnableTouch();        
+                nstate=state;                
                 break;
      
-     case 7:    
-                //DisableTouch();     
+     case 7:      
                 glc(pid);                                                       // glc measurement
                 glc_flag=1;
                 state1=0;
-                //screen_glc_2();
                 state=6;
                 eprom_write_8(30,0);
-                nstate=state;  
-                //wait(2);                                                        //added on 16-NOV rashmi
-                //screen_main_2(pid);                                       //added on 20-NOV rashmi   
-                state_touch = TOUCH_STATE_TEST_SCREEN;                          //added on 16-Nov rashmi    
-                //EnableTouch();
+                nstate=state;                                   
+                state_touch = TOUCH_STATE_TEST_SCREEN;                     
+                
                 break;
     
-    case 8:    // DisableTouch();
+    case 8:    
                 // send ECG test in progress messages to mobile application
                 poc2p0_send_device_msg_res(ECG_TEST_IN_PROGRESS_RES);
-                //ecg_countdown();                                                // countdown before ecg capture
                 ecg_bp_countdown();
                 ecg(pid);                                            // capturing ecg
                 state1=0;
@@ -511,31 +492,20 @@
                 state=6;
                 eprom_write_8(30,1);
                 nstate=state;
-                //screen_ecg_bp();
-                //wait(2);                                                        //added on 16-NOV rashmi
-                //screen_main_2(pid);                                        //added on 20-NOV rashmi
-                state_touch = TOUCH_STATE_TEST_SCREEN;                          //added on 16-Nov rashmi
-                //EnableTouch();
+                state_touch = TOUCH_STATE_TEST_SCREEN;                          
                 break;
              
-      case 9:
-                //DisableTouch();
-                //screen_bp2();                                                   // bp main screen
-                
+      case 9:                
                 // send BP test in progress response to mobile application
                 poc2p0_send_device_msg_res(BP_TEST_IN_PROGRESS_RES);
-
-                //bp_countdown();                                                 // countdown for bp 
-                ecg_bp_countdown();
+                                              
+                ecg_bp_countdown();                                             // countdown for bp 
                 bp(pid);                                                        // measuring bp   earlier bp() changed to bp(pid) 28/4/2017
                 state1=0;
                 state=6;
                 eprom_write_8(30,2);
-                nstate=state;
-                //wait(2);                                                        //added on 16-NOV rashmi
-                //screen_main_2(pid);                                       //added on 20-NOV rashmi 
-                state_touch = TOUCH_STATE_TEST_SCREEN;                          //added on 16-Nov rashmi
-                //EnableTouch();
+                nstate=state;                                      
+                state_touch = TOUCH_STATE_TEST_SCREEN;                          
                  break;
  
                           
@@ -546,42 +516,31 @@
                   break;        
                   
       case 11 :    
-                //DisableTouch();
                 //screen_patient_info(get_filepid(), get_btpid());
                 state1=0;
                 state=12;
-                //EnableTouch();
                 break;  
                          
       case 13 :                                                                 //display screen for debug
-               // DisableTouch();
-                //screen_debug();
                 state1=0;
                 state=13;
                 nstate=state;
-               // EnableTouch();
                 break; 
                    
-      case 14 :    
-                //DisableTouch();                                                 //state to delete SD card
-                delete_sdcard();
-                //screen_sdcard_delete();
+      case 14 :                                         
+                delete_sdcard();                                                // delete SD card
                 state1=0;
                 state= 12;
                 nstate=state;
-                //EnableTouch();
                 break;   
                 
         case 15 :    
-               // DisableTouch();
                 gc.printf("Total Patients' data available : %d\n",get_filepid());                                        //state to read SD card
                 gc.printf("Enter the PID number");
                 read_sdcard_file();
-                //screen_sdcard_read();
                 state1=0;
                 state= 12;
                 nstate=state;
-               // EnableTouch();
                 break;                            
        
         default :  
@@ -592,8 +551,6 @@
 
     }            
 
-
-
     return state;       
 
 }
@@ -617,20 +574,13 @@
 
 void increment_filepid (void)                                                       //increment pid if a test is completed
 {
-    //uint32_t filepid_btpid[2] = {};
-    
-    //set_filecreated_status();                                                   //set it to make it append mode
     sd_read(filepid_btpid);                                                     //read pid from sd card
     filepid_btpid[0] = filepid_btpid[0] + 1;                                    //increment it by 1
-    sd_write(filepid_btpid);                                                    //write it back to sd card
-    
+    sd_write(filepid_btpid);                                                    //write it back to sd card  
 } 
 
-void increment_btpid (void)                                                       //increment pid if a test is completed
+void increment_btpid (void)                                                      //increment pid if a test is completed
 {
-    //uint32_t filepid_btpid[2] = {};
-    
-    //set_filecreated_status();                                                 //set it to make it append mode
     sd_read(filepid_btpid);                                                     //read pid from sd card
     filepid_btpid[1] = filepid_btpid[1] + 1;                                    //increment it by 1
     sd_write(filepid_btpid);                                                    //write it back to sd card
@@ -638,8 +588,7 @@
 } 
 
 uint32_t get_filepid(void)
-{
-    //uint32_t filepid_btpid[2] = {};  
+{ 
     uint32_t filepid = 0;    
     
     sd_read(filepid_btpid);                                                           //read pid from sd card
@@ -650,32 +599,26 @@
 
 void store_filepid(uint32_t pid)
 {
-       //uint32_t filepid_btpid[2] = {};
-        sd_read(filepid_btpid);                                                       //read pid from sd card
-        filepid_btpid[0] = pid;                                              
-        sd_write(filepid_btpid);                                                      //write it back to sd card
+    sd_read(filepid_btpid);                                                       //read pid from sd card
+    filepid_btpid[0] = pid;                                              
+    sd_write(filepid_btpid);                                                      //write it back to sd card
                                                         
 } 
 
 uint32_t get_btpid(void)
 {
-    //uint32_t filepid_btpid[2] = {}; 
     uint32_t btpid = 0;    
     
     sd_read(filepid_btpid);                                                           //read pid from sd card
     btpid = filepid_btpid[1];                                  
-    return btpid; 
-    
+    return btpid;  
 }   
 
 void store_btpid(uint32_t bt_pid)
-{
-       //uint32_t filepid_btpid[2] = {};
-    
-        sd_read(filepid_btpid);                                                       //read pid from sd card
-        filepid_btpid[1] = bt_pid;                                              
-        sd_write(filepid_btpid);                                                      //write it back to sd card
-                                                        
+{     
+    sd_read(filepid_btpid);                                                       //read pid from sd card
+    filepid_btpid[1] = bt_pid;                                              
+    sd_write(filepid_btpid);                                                      //write it back to sd card
 } 
 
 
@@ -715,7 +658,7 @@
          
             if (strcmp(debug_message_rx, debug_message) == 0)                   // compare the message with the required one
             {
-                 debug_mode = true;                                                // enable the debug mode status
+                 debug_mode = true;                                             // enable the debug mode status
                  gc.printf("entered into debug mode\n");
                  timer_debug.reset();
                  timer_debug.start();                                           // timer is started in orede
@@ -724,7 +667,7 @@
     
 }  
     
-uint32_t get_timer_debug()                                                         // timer for enabling debug option
+uint32_t get_timer_debug()                                                      // timer for enabling debug option
 {
   if(timer_debug.read_ms()>TIMER_ENABLE_DEBUG_MODE)
     {
@@ -784,9 +727,7 @@
     // patient ID
     if (curr_touch_state == TOUCH_STATE_TEST_SCREEN)
     {
-        memcpy(poc2p0_device_heartbeat_res.pid,get_userpid(),sizeof(poc2p0_device_heartbeat_res.pid));
-        //gc.printf("poc2p0_device_heartbeat_res.pid = %s\n",poc2p0_device_heartbeat_res.pid);
-               
+        memcpy(poc2p0_device_heartbeat_res.pid,get_userpid(),sizeof(poc2p0_device_heartbeat_res.pid));               
     }
     else 
     {
@@ -899,59 +840,6 @@
     gc.printf("\n");  
 }
 
-
-void set_userpid(char *user_pid)
-{
-    char pid_buffer[20];
-    char test_screen_chk[3];
-    
-    //char user_pid_buffer[10] = {0};
-    if (gc.readable()!= '\n')                                                   // reading string from putty
-    //if (blue.readable()!= NULL)                                               // reading string from bluetooth
-    {                                                         
-        //blue.scanf("%10s",user_pid);
-        gc.scanf("%20s",pid_buffer);
-    } 
-    memcpy(test_screen_chk,pid_buffer+1,2);
-    //if(test_screen_chk == "73")
-        memcpy(user_pid,pid_buffer+6,10); 
-    //else
-    //    gc.printf("Not a valid PID\n");
-}
-
-
-
-
-
-
-void ascii_to_hex(const char *input_buf, uint8_t len)
-{
-    uint8_t i = 0;
-    uint8_t j = 0;
-    uint8_t temp_ms_nibble = 0;
-    uint8_t temp_ls_nibble = 0;
-    uint8_t temp_buf[len];
-    gc.printf("\n\r len = %d", len);
-    for (i = 0,j = 0; i < len; i+=1, ++j)
-    {
-        temp_ms_nibble = input_buf[i] > '9' ? (input_buf[i]|32) - 'a' + 10 : input_buf[i] - '0';
-       
-        //gc.printf("\n\r temp_ms_nibble = %2x", temp_ms_nibble);
-        
-        //temp_ls_nibble = input_buf[i+1] > '9' ? (input_buf[i+1]|32) - 'a' + 10 : input_buf[i+1] - '0';
-        //gc.printf("\n\r temp_ls_nibble = %2x", temp_ls_nibble);
-        
-        //temp_buf[j] = ((temp_ms_nibble << 4)) | temp_ls_nibble;
-        temp_buf[j] = temp_ms_nibble ;
-        //gc.printf("\n\r msg_SOS = %02x", temp_buf[j]);
-    }
-    
-    memcpy((void *)input_buf,&temp_buf, len);
-    
-    
-    return;
-}
-
 static void ecg_bp_countdown(void)
 {
     for(uint8_t i = 5; i <= 0; i--)
@@ -963,8 +851,8 @@
 static void read_device_id(void)                                                // reading device id from eeprom
 {
     
-    device_id =  eprom_read_8(12);                                              // reading from eeprom location 
-    gc.printf("device_id = %d\n", device_id);                                                      //read did from eeprom
+    device_id =  eprom_read_8(12);                                              // reading did from eeprom location 
+    gc.printf("device_id = %d\n", device_id);                                                     
     if((get_Error()!= 0) || (device_id == 0xFF))                                // checking for error                               
     {
             device_id = eprom_read_8(12) ; 
@@ -982,7 +870,7 @@
     return  device_id;
 }
 
-void sd_card_status(void)                                                           // checking the status of the sd card initialization
+void sd_card_status(void)                                                       // checking the status of the sd card initialization
 {
  uint8_t error_sd= 0;
  error_sd = dummy_file_create_delete();                                         // creating the dummy file