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:
68:41da0a3ba038
Parent:
67:7e07cdb1b150
Child:
69:128e3b467820
--- a/main.cpp	Mon Nov 20 12:23:52 2017 +0000
+++ b/main.cpp	Tue Nov 21 12:47:03 2017 +0000
@@ -66,7 +66,8 @@
     uint8_t                 cmd;                    // this contains error response
     uint8_t                 length;
     uint8_t                 did;
-    uint32_t                pid;
+    char                    pid[10];
+    //uint32_t                pid;
     DateTime_info           date_time;
     //uint32_t                pid;
     //uint8_t                 did;
@@ -89,6 +90,7 @@
 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 uint8_t nstate=0;
 static uint8_t nstate1=0;                                                  
@@ -103,8 +105,9 @@
 void debug_status_monitoring();                                         // debug status monitoring
 static uint32_t pid = 0;                                                    // patient ID    
 static uint8_t state_touch = 1;                                                 //added on 16-NOV rashmi 
-uint8_t buffer_pointer = 0x00u;                                    
-static char usser_pid[10] = {0};
+uint8_t buffer_pointer = 0x00u;   
+                                
+
 int main()
 {
     static DEVICE_MAIN_STATE main_state = GET_TOUCH_DISP_STATE;
@@ -375,7 +378,6 @@
     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
     {
 
@@ -408,11 +410,13 @@
                
       case 3: 
                 DisableTouch();
-                gc.printf("\n\r Enter User PID\n");                             //
-                set_userpid(usser_pid);
-                gc.printf("User pid = %s\n",usser_pid);
+                gc.printf("\n\r Enter User PID\n"); 
+                                           
+                set_userpid(user_pid);
+                gc.printf("User pid = %s\n",user_pid);
+                               
                 gc.printf("pidinit=%d",pid);
-                screen_main_2(usser_pid);     
+                screen_main_2(user_pid);     
                 state1=0;
                 state=3;
                 nstate=state;
@@ -481,7 +485,7 @@
                 eprom_write_8(30,0);
                 nstate=state;  
                 //wait(2);                                                        //added on 16-NOV rashmi
-                screen_main_2(usser_pid);                                       //added on 20-NOV rashmi   
+                screen_main_2(user_pid);                                       //added on 20-NOV rashmi   
                 state_touch = TOUCH_STATE_TEST_SCREEN;                          //added on 16-Nov rashmi    
                 EnableTouch();
                 break;
@@ -499,7 +503,7 @@
                 nstate=state;
                 screen_ecg_bp();
                 //wait(2);                                                        //added on 16-NOV rashmi
-                screen_main_2(usser_pid);                                        //added on 20-NOV rashmi
+                screen_main_2(user_pid);                                        //added on 20-NOV rashmi
                 state_touch = TOUCH_STATE_TEST_SCREEN;                          //added on 16-Nov rashmi
                 EnableTouch();
                 break;
@@ -519,7 +523,7 @@
                 eprom_write_8(30,2);
                 nstate=state;
                 //wait(2);                                                        //added on 16-NOV rashmi
-                screen_main_2(usser_pid);                                       //added on 20-NOV rashmi 
+                screen_main_2(user_pid);                                       //added on 20-NOV rashmi 
                 state_touch = TOUCH_STATE_TEST_SCREEN;                          //added on 16-Nov rashmi
                 EnableTouch();
                  break;
@@ -762,11 +766,15 @@
     // patient ID
     if (curr_touch_state == TOUCH_STATE_TEST_SCREEN)
     {
-        poc2p0_device_heartbeat_res.pid = pid;
+        get_userpid(poc2p0_device_heartbeat_res.pid,user_pid);
+        gc.printf("poc2p0_device_heartbeat_res.pid = %s\n",poc2p0_device_heartbeat_res.pid);
+        ascii_to_hex((const char *)poc2p0_device_heartbeat_res.pid, strlen(poc2p0_device_heartbeat_res.pid));
+        //poc2p0_device_heartbeat_res.pid = pid;
     }
     else
     {
-        poc2p0_device_heartbeat_res.pid = 0x00u;
+        memset((void *)&poc2p0_device_heartbeat_res.pid,0x00,sizeof(poc2p0_device_heartbeat_res.pid));
+        //poc2p0_device_heartbeat_res.pid = {0x00u};
     }
 
     // device current date and time
@@ -845,7 +853,42 @@
     
 }
 
-char *get_userpid(char user_pid[])
+void set_userpid(char *user_pid)
+{
+    //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("%10s",user_pid);
+              
+    }  
+}
+
+void get_userpid(char *output_pid,char input_pid[])
 {
-    return user_pid;
+    strcpy(output_pid,input_pid);
+    gc.printf("Temp User pid = %s\n",output_pid);
+    //return user_pid;
 }
+
+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];
+
+    for (i = 0,j = 0; i < len; i+=2, ++j)
+    {
+        temp_ms_nibble = input_buf[i] > '9' ? (input_buf[i]|32) - 'a' + 10 : input_buf[i] - '0';
+        temp_ls_nibble = input_buf[i+1] > '9' ? (input_buf[i+1]|32) - 'a' + 10 : input_buf[i+1] - '0';
+        temp_buf[j] = (temp_ms_nibble << 4) | temp_ls_nibble;
+        //mc.printf("\n\r msg_SOS = %2x", temp_buf[j]);
+    }
+    
+    memcpy((void *)input_buf,&temp_buf, len);
+    
+    return;
+}