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:
51:1a4693774b60
Parent:
50:b42238e7f46d
Child:
52:7d9ff7781bdc
--- a/main.cpp	Sat Sep 16 06:54:42 2017 +0000
+++ b/main.cpp	Wed Sep 20 07:48:55 2017 +0000
@@ -17,6 +17,8 @@
 #define BATTERY_SCREEN_NO_CHARGE_CONDITION      3
 #define TIMER_ENTER_DEBUG_MODE                  10000
 
+
+
 Serial gc(USBTX, USBRX);
 DigitalIn q1(PTB11);
 DigitalIn q(PTC5);
@@ -35,8 +37,12 @@
 static uint32_t filepid_btpid[2] = {};
 Timer timer_bt;                                                         // timer for bluetooth 
 Timer timer_battery;                                                     // timer for battery
-uint8_t debug_mode=0;
-
+Timer timer_debug;                                                       // timer for entering the debug mode   
+static bool debug_mode=0;                                               // holds the status of the debug mode "1" indicates the device is in debug mode 
+char debug_message_rx[6];                                               // buffer to receive the debug message data
+char debug_message[6]={"debug"};                                        //debug message to be received
+void debug_status_monitoring();                                         // debug status monitoring
+    
 
 int main()
 {
@@ -45,40 +51,33 @@
     static uint8_t state_touch = 1;
     uint8_t state_t = 1;                                     // state to transmit to bluetooth
     uint8_t state_r = 0;                                     // state to receive from bluetooth
- 
+    
   
   
     DisableTouch();
     gc.baud(115200);
     blue1.baud(115200);
-    init_screen();                                                  //initialize lcd
+    init_screen();                                                              //initialize lcd
     pid = get_filepid();
-    screen_main();                                                  // display of main screen 
+    screen_main();                                                              // display of main screen 
     battery_monitor();                                                          // monitor battery at the start only
     battery_status_display();                                                   // display of main screen
     timer_battery.start();
-    timer_bt.start();
-    gc.printf("Press any key to enter into debug mode\n");
-
-    while(timer_bt.read_ms()<TIMER_ENTER_DEBUG_MODE)
-    {
+    timer_debug.start();
+    gc.printf("enter message to go into debug mode\n");
 
-        if (gc.readable())                                          // checking whether there is any data read 
-        {
-            gc.getc();
-            //getchar();
-            debug_mode = 1;
-            timer_bt.stop();
-            timer_bt.reset();
-            gc.printf("entered debug mode\n");
-            break;
-        }   
-    }
-    
-    timer_bt.stop();
-    timer_bt.reset();
    while(1)
    {
+    
+        if (read_debug_status() == 0)                                            // checking the debug_mode status
+        {   
+            if(timer_debug.read_ms()<TIMER_ENTER_DEBUG_MODE)
+            {
+                debug_status_monitoring();
+            }
+        }   
+      
+        
         battery_status_monitoring();                                            // to  monitior battery status after every 10 min. 
 
         if (get_battery_status() == BATTERY_SCREEN_NO_CHARGE_CONDITION)   // to check battery status and take action 
@@ -89,6 +88,7 @@
         {
 
             EnableTouch();
+             gc.printf("c");  
             switch(main_state)                                             // main state machine
              {
                 case 1:  
@@ -336,7 +336,7 @@
                 clear_filecreated_status();
                 pid = get_filepid();
                 battery_status_display();                          //Display battery status on LCD
-                debug_mode = 0;
+              //  debug_mode = 0;
                 EnableTouch();
                 break;
       
@@ -348,6 +348,7 @@
                 nstate=state;
                 battery_status_display();                                           //Display battery status on LCD
                 EnableTouch();
+                // timer_debug.stop();
                 break;
                
       case 3: 
@@ -474,10 +475,6 @@
                   
       case 11 :    
                 DisableTouch();
-                //sd_read(pid_btpid);                                         //read pid from sd card 
-                //current_test_pid=pid_btpid[0];
-                //bt_file_sent_pid=pid_btpid[1];
-                //screen_patient_info(current_test_pid, bt_file_sent_pid);
                 screen_patient_info(get_filepid(), get_btpid());
                 state1=0;
                 state=12;
@@ -505,12 +502,10 @@
                 
         case 15 :    
                 DisableTouch();
-               // screen_sdcard_read();                                                 //state to delete SD card
+                gc.printf("Total Patients' data available : %d\n",get_filepid());                                        //state to read SD card
                 gc.printf("Enter the PID number");
-               /// gc.scanf("%d", &pid_read);
-               // gc.printf("%d\n",pid_read);
                 read_sdcard_file();
-               // screen_sdcard_read();
+                screen_sdcard_read();
                 state1=0;
                 state= 12;
                 nstate=state;
@@ -626,7 +621,49 @@
     }
 }
 
-uint8_t read_debug_status()
+bool read_debug_status()
+{
+    gc.printf("debug_mode=%d\n",debug_mode); 
+    return debug_mode;
+}
+
+void debug_status_monitoring()
+{
+
+
+if(get_timer_debug()<TIMER_ENTER_DEBUG_MODE)
 {
-    return debug_mode;
-}
\ No newline at end of file
+ if (gc.readable())                                                             // check for the user input
+        {
+            
+           while (gc.readable()!= '\n')                                         // read till the newline
+            { 
+               
+                gc.scanf("%s", debug_message_rx);                               // store the message typed in buffer
+                gc.printf("%s", debug_message_rx);
+                break;
+            }
+         
+         
+            if (strcmp(debug_message_rx, debug_message) == 0)                   // compare the message with the required one
+            {
+                 debug_mode = 1;                                                // enable the debug mode status
+                 gc.printf("entered into debug mode\n");
+                 timer_debug.reset();
+                 timer_debug.start();                                           // timer is started in orede
+            } 
+        }        
+}
+    
+}  
+    
+uint32_t get_timer_debug()                                                         // timer for enabling debug option
+{
+  if(timer_debug.read_ms()>TIMER_ENABLE_DEBUG_MODE)
+    {
+        timer_debug.stop();
+    }
+  return  timer_debug.read_ms(); 
+}
+
+