Code clean up - modify Datatypes

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of merged_code2_3rd_nov_2017_15th_dec_2017_magicno_removal by nikita teggi

Files at this revision

API Documentation at this revision

Comitter:
nikitateggi
Date:
Tue Dec 19 06:58:44 2017 +0000
Parent:
60:945c4a1e9a13
Commit message:
Code clean up - modify Datatypes

Changed in this revision

bp.cpp Show annotated file Show diff for this revision Revisions of this file
bt.cpp Show annotated file Show diff for this revision Revisions of this file
display_modules.cpp Show annotated file Show diff for this revision Revisions of this file
ec_bp.cpp Show annotated file Show diff for this revision Revisions of this file
ec_bp.h Show annotated file Show diff for this revision Revisions of this file
ecgg.cpp Show annotated file Show diff for this revision Revisions of this file
glc.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
sdcard.cpp Show annotated file Show diff for this revision Revisions of this file
sdcard.h Show annotated file Show diff for this revision Revisions of this file
struct.h Show annotated file Show diff for this revision Revisions of this file
touch_modules.cpp Show annotated file Show diff for this revision Revisions of this file
touch_modules.h Show annotated file Show diff for this revision Revisions of this file
diff -r 945c4a1e9a13 -r 2143f39103f7 bp.cpp
--- a/bp.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/bp.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -56,7 +56,7 @@
     uint32_t ppgdata; 
     uint8_t lead_reg=0;
     uint32_t concatenate_value2 = 0;    
-    uint8_t chk = 1;                    
+    //uint8_t chk = 1;                                                          //commented nikita                   
     uint32_t un_max = 0;                                                        // Declare two VARIABLE FOR MAX AND MIN
     uint32_t un_min = 0x3FFF;
     
@@ -77,15 +77,15 @@
     ptr_BLEMsg_info_bp = &BLEMsg_info_bp;                                       // *ptr_BLEMsg_info_bp is the pointer to local copy;
     
     // Declaration of Date Structure
-    DateTime_info *ptr_DateTime_info_bp, DateTime_info_bp;                      // A copy of Master Structure "DateTime_info" created, 
-    ptr_DateTime_info_bp = &DateTime_info_bp;                                   // Structure pointer points to that copy.
+    DateTime_info DateTime_info_bp;                                             // A copy of Master Structure "DateTime_info" created, //commented nikita  
+   // ptr_DateTime_info_bp = &DateTime_info_bp;                                  // Structure pointer points to that copy.
     
     
     // RTC operations
     time_t epoch_time_bp;                                                       //A copy of time_t by name  epoch_time_bp is created 
     epoch_time_bp = rtc_read();                                                 // time is got from get epoch function.  
     
-    struct tm * ptr_time_info_bp, time_info_bp;                                 // Sturucture copy of tm is created
+    struct tm * ptr_time_info_bp;                                               // Sturucture copy of tm is created//removed //time_info_bp; //nikita
     ptr_time_info_bp = localtime(&epoch_time_bp);                               // Structure accepts the time in local format from "time_t" type.
       
     //BELOW LINE IS TO CHECK Date and TIME 
@@ -128,7 +128,7 @@
     // Loading values of Length ,  PID, DID, sampling frequency, number of samples, calculated data.
     BLEMsg_info_bp.device_id = get_did();                   // Device ID fixed  // changed on 11/8/17 nikita
     serial_bp.printf("device id read ecg = %d\n", BLEMsg_info_bp.device_id); 
-    BLEMsg_info_bp.patient_id = (uint32_t)pid;       // Patient ID
+    BLEMsg_info_bp.patient_id = pid;       // Patient ID
     BLEMsg_info_bp.sampling_freq = ECG_SAMPLING_FREQUENCY;                      // sampling frrquency
     BLEMsg_info_bp.length = BP_LENGTH_IN_BYTES;                                 //Total length of data in bytes  22 B+10752 B
     
@@ -145,7 +145,7 @@
     wait_ms(20);
     maxim_max30102_init();
         
-    chk = 1;
+    //chk = 1;                                                                  //commented nikita  
         
     for(uint16_t i = 0; i < DUMMY_CAPTURE; i++)
     {
diff -r 945c4a1e9a13 -r 2143f39103f7 bt.cpp
--- a/bt.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/bt.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -40,7 +40,7 @@
 
 uint8_t bt_send(uint8_t state_tx)
 {
-    int8_t check_sum = 0;
+    uint8_t check_sum = 0;                                                      //changed from int8_t to uint8_t
     uint8_t state_rx = 0;
     uint16_t buffer_start = 0;
     
@@ -66,9 +66,9 @@
             {
                 send_initial_string(); 
                 blue.printf("\n"); 
-                file = sd_open_read(bt_pid);                         // open the file for reading
+                file = sd_open_read_bt(bt_pid);                         // open the file for reading
                 serial_bt.printf("File opened to read\n");
-                total_file_size = file_size();                           // determined the file size 
+                total_file_size = file_size_init();                           // determined the file size 
                 state_rx = 1;  
             }
             
@@ -83,7 +83,7 @@
                    
        case 2:   
             total_samples = 0; 
-            sd_read1(bt_file1);                                    // read the sd card file
+            sd_read_struct(bt_file1);                                    // read the sd card file//function name changed nikita
             serial_bt.printf("sd file opened to read data in it\n");
             myBleMsg->bt_msg = bt_file1;                              //copy the contents to the structure
             send_structure();                                       // send the structure string
@@ -93,7 +93,7 @@
             state_tx = 0;
             state_rx = 2;
             count_send = 0;
-            total_file_size_sent = file_size1();
+            total_file_size_sent = file_size_sent();
             
             break;                 
  
@@ -102,7 +102,7 @@
             counter = 0;
             if(count_send < (total_samples/BT_BUFFER_SIZE))
             {
-                sd_read(v1,BT_BUFFER_SIZE);      
+                sd_read_bt(v1,BT_BUFFER_SIZE);      
                 counter = BT_BUFFER_SIZE;               //read 1500 samples
                 send_data_str1(); 
                 for(file_start = 0;file_start < (BT_BUFFER_SIZE);file_start++)
@@ -125,7 +125,7 @@
                 }
                 counter = (total_samples - (BT_BUFFER_SIZE*count_send));
                 send_data_str1();
-                sd_read(v1,(total_samples - (BT_BUFFER_SIZE*count_send)));
+                sd_read_bt(v1,(total_samples - (BT_BUFFER_SIZE*count_send)));
             
                 for(file_start = 0;file_start < (total_samples - ( BT_BUFFER_SIZE*count_send));file_start++)
                 {     
@@ -138,7 +138,7 @@
                 send_data_str2(check_sum);
             }   
             
-            total_file_size_sent = file_size1();
+            total_file_size_sent = file_size_sent();
             blue.printf("\n");  
             
             break;        
@@ -155,7 +155,7 @@
             else   
             {
                 total_samples = 0;   
-                sd_read1(bt_file1);               // read the sd card file
+                sd_read_struct(bt_file1);               // read the sd card file
                 //  serial_bt.printf("sd file opened to read data in it\n");
                 myBleMsg->bt_msg = bt_file1;         //copy the contents to the structure
                 send_structure();                                // send the initial string
@@ -165,7 +165,7 @@
                 state_tx = 0;
                 state_rx = 2;
                 count_send = 0;
-                total_file_size_sent = file_size1();
+                total_file_size_sent = file_size_sent();                                                                                //name changed //nikita
             
             }   
             break;           
@@ -181,7 +181,7 @@
 uint8_t bt_receive (uint8_t state_rx)
 {
        
-    unsigned char state_tx = 1;                                                      //state for transmitting 
+    uint8_t state_tx = 1;                                                      //state for transmitting //changed from unsigned char to uint8_t
     uint8_t string_length_rx = 0;
     char ack_rx[2];                                                                 // varibale to receive ack from the bluetooth 
     char chksum_rx[3]; 
@@ -230,7 +230,7 @@
             { 
             
             state_tx = 2;
-            setpos1(file_pointer_position);          
+            setpos_file(file_pointer_position);          
             }
             
             break;
@@ -249,7 +249,7 @@
             { 
                 state_tx = 3;
                 file_start = file_start- BT_BUFFER_SIZE;
-                setpos1(file_pointer_position);
+                setpos_file(file_pointer_position);
             }
             
             break;    
@@ -267,7 +267,7 @@
             { 
                 state_tx = 3;
                 file_start = file_start - BT_BUFFER_SIZE;
-                setpos1(file_pointer_position);
+                setpos_file(file_pointer_position);                             //name changed nikita
             } 
             
             break;                
diff -r 945c4a1e9a13 -r 2143f39103f7 display_modules.cpp
--- a/display_modules.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/display_modules.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -39,10 +39,10 @@
 
 void screen_main()                                                              //main screen
 {
-    char buff1[32];
+    char buffer[32] = {0};
     time_t epoch_time;
     epoch_time=rtc_read();                                                      // read the time from rtc module
-    strftime(buff1, 32, "%d-%m-%Y           %H:%M",localtime(&epoch_time));
+    strftime(buffer, 32, "%d-%m-%Y           %H:%M",localtime(&epoch_time));
     backlight = 0 ;
     TFT.BusEnable(true) ;
     TFT.background(White) ;
@@ -51,7 +51,7 @@
     TFT.set_font((unsigned char*) Arial12x12);
     TFT.foreground(Red);
     TFT.locate(20,100) ;
-    TFT.printf(buff1);
+    TFT.printf(buffer);
     TFT.set_font((unsigned char*) Arial24x23);  
     TFT.foreground(Black);
     TFT.locate(35,30) ;
@@ -75,12 +75,12 @@
     
 void screen_main_2(int32_t pid)                                                 // test main screen
 {
-    char buff2[10];     
+    char buffer[10] = {0};     
     backlight = 0 ;
     
     TFT.BusEnable(true) ;
     TFT.background(White) ;
-    sprintf(buff2 ,"%d", pid);
+    sprintf(buffer ,"%d", pid);
     TFT.fillrect(5,20,250,150,White ); 
     TFT.fillrect(5,20,250,250,White );              
     TFT.fillrect(60,130,180,200,White );  
@@ -91,7 +91,7 @@
     TFT.locate(10,50) ;
     TFT.printf("PATIENTID") ;
     TFT.locate(180,50) ;
-    TFT.printf(buff2) ;
+    TFT.printf(buffer) ;
     TFT.background(Orange) ;
     TFT.foreground(Black);
     TFT.fillrect( 10,130,100,200,Orange);
@@ -168,7 +168,7 @@
                 
 void screen_ecg_2(uint16_t heart_rate)                                          // ECG screen 2
 {
-    char buf[5];
+    char buf[5] = {0};
     backlight = 0 ;
     TFT.BusEnable(true) ;
     TFT.background(White) ;
@@ -270,11 +270,12 @@
 
 void screen_bp1(float SBP, float DBP)                                           // BP  screen 2
 {
+    char buf[10] = {0}; 
     backlight = 0 ;
     TFT.BusEnable(true) ;
     TFT.background(White) ;
     TFT.foreground(Green) ;
-    char buf[10];  
+     
     TFT.fillrect(3,130,200,200,White);
     TFT.fillrect(60,230,180,300,White);
     TFT.fillrect(60,110,180,250,White);
@@ -335,11 +336,12 @@
                
 void ecg_countdown()                                                            // ECG measurement countdown 
 {    
+    char timer_buff[1] = {0};                                                            //changed the timer buffer nikita from array
     backlight = 0 ;
     TFT.BusEnable(true) ;
     TFT.background(White) ;
     TFT.foreground(Green) ;
-    char tim1[5];
+    
     TFT.fillrect(3,80,240,300,White);   
     TFT.fillrect(60,230,180,300,White);
     TFT.fillrect(5,215,230,290,White);
@@ -349,9 +351,9 @@
     for(int i=5;i>=0;i--)
     {
         wait(1);
-        sprintf (tim1, "%d",i);
+        sprintf (timer_buff, "%d",i);
         TFT.locate(120,120) ;        
-        TFT.printf(tim1) ; 
+        TFT.printf(timer_buff) ; 
     }
     TFT.fillrect(5,80,240,200,White);    
     TFT.locate(35,110) ;        
@@ -366,11 +368,12 @@
   
 void bp_countdown()                                                             // ECG measurement countdown 
 {    
+    char timer_buff[1] = {0};                                                            //changed from array nikita
     backlight = 0 ;
     TFT.BusEnable(true) ;
     TFT.background(White) ;
     TFT.foreground(Green) ;
-    char tim1[5];
+    
     
     TFT.fillrect(3,130,200,200,White);
     TFT.fillrect(60,230,180,300,White);
@@ -382,9 +385,9 @@
     for(int i=5;i>=0;i--)
     {
         wait(1);
-        sprintf (tim1, "%d",i);
+        sprintf (timer_buff, "%d",i);
         TFT.locate(120,120) ;        
-        TFT.printf(tim1) ; 
+        TFT.printf(timer_buff) ; 
     }
     TFT.fillrect(5,80,240,200,White);
     TFT.locate(35,110) ;        
@@ -499,7 +502,7 @@
   
 void glc_4(uint16_t mgdl)                                                       // GLC screen to display blood glucose level on the LCD
 { 
-    char buf[10];
+    char buf[10] = {0};
     sprintf (buf, " BG %d mg/dl",mgdl);
     backlight = 0 ;
     TFT.BusEnable(true) ;
@@ -702,7 +705,7 @@
     
 void screen_patient_info(uint32_t current_test_pid,uint32_t  bt_file_sent_pid)
 {
-    char buf[10];
+    char buf[10] = {0};
     sprintf (buf, "Test pid:%d",current_test_pid);      
     backlight = 0 ;
     TFT.BusEnable(true) ;
diff -r 945c4a1e9a13 -r 2143f39103f7 ec_bp.cpp
--- a/ec_bp.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/ec_bp.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -10,14 +10,14 @@
 DigitalOut myled(LED1);
 PwmOut led(PTB18);
 
- float value = 0;
- unsigned int value1;
- unsigned int value2;
- unsigned int value3;
- unsigned int value4;
- unsigned int value5;
- unsigned int value6;
- uint8_t data1;
+ uint8_t value = 0;                                                             // datatype changed from float to uint8_t nikita 
+ uint8_t value1 = 0;
+ uint8_t value2 = 0;
+ uint8_t value3 = 0;
+ uint8_t value4 = 0;
+ uint8_t value5 = 0;
+ uint8_t value6 = 0;
+ uint8_t data1 = 0;
 
  /* SPI is the spi function written in mbed and mySpi is the instance name*/
 
@@ -44,7 +44,7 @@
 
 func_ptr getFunc(char *cmd)  /*here "func_ptr is same as void*/
 {
-    int i = 0 ;
+    uint8_t i = 0 ;                                                              // datatype changed from int to uint8_t nikita 
     while(cmd_list[i].name != 0) 
     {
         if (strcmp(cmd, cmd_list[i].name) == 0)
@@ -212,7 +212,7 @@
 
 void doRead(void) 
 {
-    int dummy = 0 ;
+    uint8_t dummy = 0 ;                                                          // datatype changed from int to uint8_t nikita 
     
     while(!DRDY_BAR)
         ADS_START = 0;
@@ -227,7 +227,7 @@
     printf("repeat number has been set to %d\n\r", ECG_SPI_LOOP) ;
 }
 
-void cmdWrite(int data) 
+void cmdWrite(uint8_t data)                                                     // datatype changed from int to uint8_t nikita  
 {
     CHIPSEL_BAR = 0;
     mySpi.write(data) ;
@@ -235,9 +235,9 @@
     CHIPSEL_BAR = 1;  
 }
 
-void regWrite(int address, int data) 
+void regWrite(uint8_t address, uint8_t data)                                    // datatype changed from int to uint8_t nikita  
 {
-    int data_to_send = CMD_WREG << 5;
+    uint8_t data_to_send = CMD_WREG << 5;                                       // datatype changed from int to uint8_t nikita 
     data_to_send = data_to_send | address;
     CHIPSEL_BAR = 0;
     mySpi.write(data_to_send);
@@ -249,9 +249,9 @@
     CHIPSEL_BAR = 1;  
 }
 
-void regRead(int address)
+void regRead(uint8_t address)                                                   // datatype changed from int to uint8_t nikita 
 {
-    int data_to_receive = CMD_RREG << 5;
+    uint8_t data_to_receive = CMD_RREG << 5;                                    // datatype changed from int to uint8_t nikita 
     data_to_receive = data_to_receive | address;
     CHIPSEL_BAR = 0;
     mySpi.write(data_to_receive);
diff -r 945c4a1e9a13 -r 2143f39103f7 ec_bp.h
--- a/ec_bp.h	Fri Dec 15 11:57:03 2017 +0000
+++ b/ec_bp.h	Tue Dec 19 06:58:44 2017 +0000
@@ -85,9 +85,9 @@
 void setup(void);
 void testsetup(void);
 void ecgsetup();
-void regWrite(int,int);
-void cmdWrite(int);
-void regRead(int);
+void regWrite(uint8_t,uint8_t);
+void cmdWrite(uint8_t);
+void regRead(uint8_t);
 void freqset();
 void ecgtestsetupfunc();
 
diff -r 945c4a1e9a13 -r 2143f39103f7 ecgg.cpp
--- a/ecgg.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/ecgg.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -31,7 +31,7 @@
 void low_pass_filter(uint32_t pid);
 void swap(uint32_t *ptr);
 Serial pc(USBTX,USBRX);
-
+char buffer[32] = {0};                                                          //buffer declared as file scope nikita        
 
 uint16_t ecg(uint32_t pid) 
 {
@@ -61,11 +61,11 @@
     uint8_t no_of_peaks = 0;
     uint16_t pos_dif = 0.0;                                                            
     float HR[10] = {0.0};
-    float HR1 = 0.0;
+    //float HR1 = 0.0;                                                          //commented as not in  use nikita
     float t_pos_dif = 0.0;
     float HR_sum = 0.0;
     float HR_avg = 0.0;
-    char buffer4[32] = {0};
+    
     //----------------------- Structure for Bluetooth  Added Nidhin 1/6/2017-------------------//
     
     //BLUETOOTH STRUCTURE
@@ -120,7 +120,7 @@
     // Loading values of Length ,  PID, DID, sampling frequency, number of samples, calculated data.
     BLEMsg_info_ecg.device_id =  get_did();                                     // Device ID fixed // reading the device id // 
     pc.printf("device id read ecg = %d\n", BLEMsg_info_ecg.device_id); 
-    BLEMsg_info_ecg.patient_id = (uint32_t)pid;                                 // Patient ID
+    BLEMsg_info_ecg.patient_id = pid;                                 // Patient ID
     BLEMsg_info_ecg.sampling_freq = ECG_SAMPLING_FREQUENCY;                                        // sampling frrquency
     BLEMsg_info_ecg.length = ECG_LENGTH_IN_BYTES;                                              //Total length of data in bytes  22 B+ 4000 data
     
@@ -141,7 +141,7 @@
         sd_open_ECGfilee(pid);                                                  //open temporary ecg.csv file to write 2000 samples of data
         pc.printf( "Raw data is = \n");
         
-        for(int i=0; i < N_ECG; i++) 
+        for(uint16_t i=0; i < N_ECG; i++)                                       // changed from int to uint16_t nikita 
         {
             concatenate_value2 = readvalue();
             pc.printf( "%d\n", concatenate_value2);                            
@@ -155,8 +155,8 @@
  //----------------------------- PEAK DETECTION AND HEART RATE CALCULATION ---------------------------------------------------
  
                                                                                 // PEAK DETECTION 
-     sprintf(buffer4, "/sd/%d_ECG_lpf.csv", pid);                               // For opening a specific file    
-     fpeecg1 = fopen(buffer4, "r");
+     sprintf(buffer, "/sd/%d_ECG_lpf.csv", pid);                               // For opening a specific file    
+     fpeecg1 = fopen(buffer, "r");
      
     for(uint16_t i = 100;i<((N_ECG-4)-10);i++)
     {
@@ -211,7 +211,7 @@
           pc.printf("time in seconds is = %f\n",t_pos_dif);
           HR[i] = SECONDS_60/t_pos_dif;                                         //HR calculation
           pc.printf("Heart Rate is = %f\n",HR[i]);
-          HR1 = HR[0];
+         // HR1 = HR[0];
      }
                                                                                 //To average individual HRs for higher number of samples -----------------------
      for(uint16_t i = 0;i < no_of_peaks-1;i++)
@@ -251,7 +251,7 @@
         pc.printf("improper lead connection");
         return 0;
     } 
-    pc.printf("closing temporary file\n");
+//    pc.printf("closing temporary file\n");
     
 }   // End of main function
 
@@ -262,22 +262,22 @@
     FILE *fpecg1;                                                               // FILE pointer to read raw data ECG file  added by Suhasini 5-8-17
     FILE *fpeecg_lpf;                                                           // FILE pointer to read and write into LPF output file   added by Suhasini 5-8-17
     uint32_t ecg_raw[5] = {0} ;                                                 // Buff of 5 samples created to Stores input samples for LPF  added by Suhasini - 5-8-17
-    uint32_t lpf_op[5] = {0};                                              // for LPF output   added by Suhasini - 5-8-17 // changed from double to int32_t- 16-8-17
+    uint32_t lpf_op[5] = {0};                                                   // for LPF output   added by Suhasini - 5-8-17 // changed from double to int32_t- 16-8-17
 
-    uint32_t lpf_4samp = 0;                                                     // Variable to move 16 samples back from current in input file - changed by Suhasini- 5-8-17
-    char buffer3[32];
-    char buffer4[32];                                                           // Added by Suhasini - 5-8-17
+   // uint32_t lpf_4samp = 0;                                                   // Variable to move 16 samples back from current in input file - changed by Suhasini- 5-8-17
+    //char buffer3[32];
+   // char buffer4[32];                                                           // Added by Suhasini - 5-8-17
     const float b[5]= {0.0000624,0.0002495,0.0003743,0.0002495,0.0000624};      //Numerator co-efficients of low-pass butter-worth filter of order=4
     const float a[5]= {1.0000,-3.5078,4.6409,-2.7427,0.6105};                   //Denominator co-efficients of low-pass butter-worth filter of order=4
 
 
 
-    sprintf(buffer3, "/sd/%d_ECG.csv", pid);                                    // opening raw data file to read
-    fpecg1 = fopen(buffer3, "r");                                               // to read data from the above opened temp file
+    sprintf(buffer, "/sd/%d_ECG.csv", pid);                                    // opening raw data file to read
+    fpecg1 = fopen(buffer, "r");                                               // to read data from the above opened temp file
     pc.printf("entered raw data file\n");
     
-    sprintf(buffer4, "/sd/%d_ECG_lpf.csv", pid);                                // opening empty file to write lpf data
-    fpeecg_lpf = fopen(buffer4, "a");                                           // to read data from and write data into the above opened file // changed from "a+" to "a"
+    sprintf(buffer, "/sd/%d_ECG_lpf.csv", pid);                                // opening empty file to write lpf data
+    fpeecg_lpf = fopen(buffer, "a");                                           // to read data from and write data into the above opened file // changed from "a+" to "a"
     pc.printf("entered LPF data file\n");
     
     fwrite(&lpf_op, sizeof(int32_t), 4, fpeecg_lpf);
diff -r 945c4a1e9a13 -r 2143f39103f7 glc.cpp
--- a/glc.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/glc.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -46,17 +46,17 @@
 void i2c_spec();
 
 
-unsigned char GLC_START = 0;
+bool GLC_START = false;                                                         //changed from uint16_t to bool nikita
 static uint16_t mgdl = 0;
-static uint16_t mgdll = 0;
+//static uint16_t mgdll = 0;                                                    //commented nikita
 uint16_t  daata1= 0;
 uint16_t  data2 = 0;
 
-static uint16_t  data1n = 0;
-static uint16_t  data2n = 0;
+uint16_t  data1n = 0;                                                           //changed the static to nonstatic nikita
+uint16_t  data2n = 0;
 uint16_t  datafinal1 = 0;
 uint16_t  datafinal2 = 0;
-unsigned char err = 0;
+bool err = false;                                                               //changed from uint16_t to bool nikita
 
 uint32_t glcraw[2] = {0};
 uint8_t chk_glc_data = 0;
@@ -71,11 +71,11 @@
     
     if( ((daata1 - data2) >= (data2/10) && (daata1 > data2)) || ((data2 - daata1) >= (data2 / 10) && (data2 > daata1)) )
     {
-        err = 1;     
+        err = true;     
     }
     else
     {
-        err = 0;
+        err = false;
     //gtc.printf("\n", data1n, data2n); 
     }
      
@@ -88,7 +88,7 @@
    datafinal1 = (uint16_t ) NUMB1 * (data2 * VREF / (TOTAL))- NUMB2;
    datafinal2 = (uint16_t ) NUMB1 * (daata1 * VREF / (TOTAL)) - NUMB2;
    mgdl = (uint16_t) NUMB1 * (((daata1 + data2) / 2) * VREF / (TOTAL)) - NUMB2;  
-   GLC_START = 0;
+   GLC_START = false;
    flipper1.detach();                                                           // ticker for computation is disabled
 }
 
@@ -96,7 +96,7 @@
 void  glc(uint32_t pid)
 {
    
-    char t_s_d = 0;
+    bool t_s_d = false;                                                         // changed to bool nikita
     uint8_t err_no_teststip = 0; 
     i2c_spec();                                                                 // programming the i2c expander 
     sd_open_GLCfilee(pid);                                                      
@@ -107,8 +107,8 @@
                                                
     
     // Declaration of Date Structure
-    DateTime_info *ptr_DateTime_info_glc, DateTime_info_glc;                    // A copy of Master Structure "DateTime_info" created, 
-    ptr_DateTime_info_glc = &DateTime_info_glc;                                 // Structure pointer points to that copy.
+    DateTime_info DateTime_info_glc;                                            // A copy of Master Structure "DateTime_info" created, //commented pointer nikita
+   // ptr_DateTime_info_glc = &DateTime_info_glc;                                 // Structure pointer points to that copy.
     
     
       
@@ -116,7 +116,7 @@
     time_t epoch_time_glc;                                                      //A copy of time_t by name  epoch_time_bp is created 
     epoch_time_glc = rtc_read();                                                // time is got from get epoch function.  
     
-    struct tm * ptr_time_info_glc, time_info_glc;                               // Sturucture copy of tm is created
+    struct tm * ptr_time_info_glc;                                              // Sturucture copy of tm is created//commented nikita  time_info_glc;   
     ptr_time_info_glc = localtime(&epoch_time_glc);                             // Structure accepts the time in local format from "time_t" type.
     /*  
     //BELOW LINE IS TO CHECK Date and TIME 
@@ -168,12 +168,12 @@
        
      
             
-    GLC_START = 1;
+    GLC_START = true;
     
-    if(GLC_START == 1)
+    if(GLC_START == true)
     {
         glc_1();                                                                // displaying messages to insert the test strip
-        err = 0;
+        err = false;
         data1n = 0;
         data2n = 0;
         daata1 = 0;
@@ -184,15 +184,15 @@
         if (!test_strip)                                                        // checks for the presence of test strip
         { 
             flipper.attach(&sample, 0.8);    
-            t_s_d = 0;
+            t_s_d = false;
             glc_2();                                                            // displaying message to insert blood
              
-            while((!t_s_d) && (!test_strip))
+            while((t_s_d == false) && (!test_strip))
             {
                                 
                 if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD)) 
                 { 
-                    t_s_d = 1;
+                    t_s_d = true;
                     flipper1.attach(&Compute, 2.25);                            //computing the glucose level
                     glc_3();
                 }
@@ -212,7 +212,7 @@
     } 
     wait(2.25);
     //gtc.printf("error = %d\n", err);   
-    if ((err==0) && (err_no_teststip == 0) && ( mgdl < MAX_GLC_THRESHOLD) && ( mgdl > MIN_GLC_THRESHOLD))
+    if ((err==false) && (err_no_teststip == 0) && ( mgdl < MAX_GLC_THRESHOLD) && ( mgdl > MIN_GLC_THRESHOLD))
     {     
         glc_4(mgdl);
         //gtc.printf("DATA1 is - %d\n", data1n); 
@@ -244,7 +244,7 @@
             glc_error_test_strip_removed();
         }
         
-        else if(err == 1 || mgdl > MAX_GLC_THRESHOLD || mgdl < MIN_GLC_THRESHOLD)
+        else if(err == true || mgdl > MAX_GLC_THRESHOLD || mgdl < MIN_GLC_THRESHOLD)
         {   
             //gtc.printf("replace teststip"); 
             glc_error();                                                        //disaply for showing error
diff -r 945c4a1e9a13 -r 2143f39103f7 main.cpp
--- a/main.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/main.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -33,15 +33,15 @@
 Timer timer_battery;                                                            // timer declaration for battery
 Timer timer_debug;                                                              // timer declaration for entering the debug mode 
 
-uint32_t get_timer_bluetooth(void);
-static void battery_status_monitoring(void);                                        //bluetooth status pin
-uint8_t touch(uint8_t state);                                                   // touch state
-uint8_t display(uint8_t state1);                                                //  display state
-void sd_card_status(void);
-void debug_status_monitoring(void); 
-static uint8_t nstate=0;
-static uint8_t nstate1=0;                                                  
-static bool file_created_status = false;                                        //initialise file created to 0
+static void battery_status_monitoring(void);                                    //  function to get battery status condition
+uint32_t get_timer_bluetooth(void);                                             //  function to get time for bluetooth connection
+uint8_t touch(uint8_t state);                                                   //  function for touch state
+uint8_t display(uint8_t state1);                                                //  function for display state
+void debug_status_monitoring(void);                                             //  function to monitor debug status
+void sd_card_status(void); 
+
+                                                
+static bool file_created_status = false;                                        //  to get status of file creation false => file not created , true => file created
 static uint32_t filepid_btpid[2] = {0};
                                                               // timer for entering the debug mode   
 static bool debug_mode=false;                                                   // holds the status of the debug mode "1" indicates the device is in debug mode 
@@ -60,8 +60,6 @@
     uint8_t state_t = 1;                                                        // state to transmit to bluetooth
     uint8_t state_r = 0;                                                        // state to receive from bluetooth
     
-  
-  
     DisableTouch();
     serial_output.baud(SERIAL_BAUD_RATE);
     blue1.baud(SERIAL_BAUD_RATE);
@@ -153,14 +151,14 @@
                                    
                                 else 
                                     {
-                                        main_state=4;                           // move to receving stste of bluetooth
+                                        main_state = 4;                         // move to receving stste of bluetooth
                                     }
                           
                             }  
                   
                             else   
                             {
-                             BT_no_connection();     // display screen to show that there is no connection
+                             BT_no_connection();                                // display screen to show that there is no connection
                             }
                          }
 
@@ -186,8 +184,8 @@
                             {
                                
                                 state_t=bt_receive(state_r);
-                               //  gc.printf(" state_t = %d\n", state_t);
-                                // gc.printf(" state_r = %d\n", state_r);
+                               //  serial_output.printf(" state_t = %d\n", state_t);
+                                // serial_output.printf(" state_r = %d\n", state_r);
                                 timer_bt.stop();
                                 timer_bt.reset();
                                 if(state_t ==0)                                 // if state_t is zero, there is no other file to send
@@ -237,86 +235,86 @@
       case 1:   
                 state1=touch_main();                                            // determining the touch for main screen 
                 state=0;
-                nstate1=state1;
+               // nstate1=state1;
                 break;
                
       case 2: 
                 state1=touch_main_1();                                          // determining the touch for SYSTEM CONFIGURATION screen 
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;
                 
       case 3:  
                 state1=touch_main_2();                                          // determining the touch for TEST screen                 
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;
         
       case 4: 
                 state1=touch_glc();                                             // determining the touch for GLC screen 
                 state=0;
-                nstate1=state1;
+                ///nstate1=state1;
                 break;       
         
       case 5: 
                 state1=touch_ecg();                                             // determining the touch for ECG screen 
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                  break;   
      case 6: 
                 state1=touch_ret();                                             // determining the touch for returning back to the main screen      
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;
                 
      case 7: 
                 state1=touch_again_ecg();                                       // determining the touch when readings are taken more than once screen 
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;
                 
      case 8:    
                 state1=touch_bp();                                              // determining the touch for BP screen 
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;           
                 
      case 9:    
                 state1=touch_again_glc();  
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;            
                 
      case 10 :  
                 DisableTouch();
                 wait_ms(WAIT_300MS);
                 EnableTouch();
-                state=nstate;
+                //state=nstate;
                 break;
                   
                   
       case 11:   
                 state1=touch_again_bp();            
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;
       
       case 12:   
                 state1=BT_return();            
                 state=0;
-                nstate1=state1;
+                //nstate1=state1;
                 break;
          
       case 13:  
                 state1 = touch_debug();                                         //touch state for debug
                 //state=0;
-                nstate1=state1;
+               // nstate1=state1;
                 break;  
      default :  
                 DisableTouch();
                 wait_ms(WAIT_300MS);
                 EnableTouch();
-                state=nstate;
+               // state=nstate;
                 break;          
                           
     }         
@@ -341,7 +339,7 @@
                 screen_main();                                                  //  main screen 
                 state1=0;
                 state=1;
-                nstate=state;
+                //nstate=state;
                 ecg_flag=0;                                                     // ecg, glc flag to determine whether the readings are taken more than once
                 glc_flag=0;
                 clear_filecreated_status();
@@ -355,7 +353,7 @@
                 screen_main_1();                                                // System configration screen 
                 state1=0;
                 state=2;
-                nstate=state;
+                //nstate=state;
                 battery_status_display();                                       //Display battery status on LCD
                 EnableTouch();
                 break;
@@ -366,7 +364,7 @@
                 screen_main_2(pid);     
                 state1=0;
                 state=3;
-                nstate=state;
+                //nstate=state;
                 battery_status_display(); 
                 EnableTouch();
                 break;
@@ -378,14 +376,14 @@
                     screen_again();    
                     state1=0;
                     state=9;
-                    nstate=state;
+                  //  nstate=state;
                 }
                 else
                 { 
                     screen_glc();                                               // glc screen
                     state1=0;
                     state=4;
-                    nstate=state;
+                    //nstate=state;
                 }
                 EnableTouch();
                 
@@ -399,7 +397,7 @@
                     screen_again();
                     state1=0;
                     state=7;
-                    nstate=state;
+                    //nstate=state;
                 }
                 
                 else
@@ -407,7 +405,7 @@
                     screen_ecg();                                               //ecg main screen 
                     state1=0;
                     state=5;
-                    nstate=state;
+                   // nstate=state;
                 }
                 EnableTouch();
                 break;
@@ -417,7 +415,7 @@
                 screen_bp();                                                    // bp main screen
                 state1=0;
                 state=8;
-                nstate=state;         
+               // nstate=state;         
                 EnableTouch();        
                 break;
      
@@ -429,7 +427,7 @@
                 screen_glc_2();
                 state=6;
                 eprom_write_8(30,0);
-                nstate=state;        
+               // nstate=state;        
                 EnableTouch();
                 break;
     
@@ -452,7 +450,7 @@
                 }                            
                 state = 6;
                 eprom_write_8(30,1);
-                nstate = state;
+               // nstate = state;
                 screen_ecg_bp();
                 EnableTouch();
                 break;
@@ -465,7 +463,7 @@
                 state1=0;
                 state=6;
                 eprom_write_8(30,2);
-                nstate=state;
+               // nstate=state;
                 EnableTouch();
                 break;
  
@@ -474,7 +472,7 @@
                 DisableTouch();
                 wait_ms(WAIT_300MS);
                 EnableTouch();
-                state=nstate;
+               // state=nstate;
                 break;        
                   
       case 11 :    
@@ -490,7 +488,7 @@
                 screen_debug();
                 state1=0;
                 state=13;
-                nstate=state;
+                //nstate=state;
                 EnableTouch();
                 break; 
                    
@@ -500,7 +498,7 @@
                 screen_sdcard_delete();
                 state1=0;
                 state= 12;
-                nstate=state;
+               // nstate=state;
                 EnableTouch();
                 break;   
                 
@@ -512,13 +510,13 @@
                 screen_sdcard_read();
                 state1=0;
                 state= 12;
-                nstate=state;
+                //nstate=state;
                 EnableTouch();
                 break;                            
        
         default :  
                   
-                  state1=nstate1;
+                  //state1=nstate1;
                    break;          
                             
             
@@ -548,7 +546,7 @@
 {
     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_pid(filepid_btpid);                                                    //write it back to sd card
     
 } 
 
@@ -556,7 +554,7 @@
 {
     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
+    sd_write_pid(filepid_btpid);                                                    //write it back to sd card
     
 } 
 
@@ -574,7 +572,7 @@
 { 
     sd_read(filepid_btpid);                                                     //read pid from sd card
     filepid_btpid[0] = pid;                                              
-    sd_write(filepid_btpid);                                                    //write it back to sd card
+    sd_write_pid(filepid_btpid);                                                    //write it back to sd card
                                                         
 } 
 
@@ -593,7 +591,7 @@
 {  
     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_write_pid(filepid_btpid);                                                    //write it back to sd card
                                                         
 } 
 
diff -r 945c4a1e9a13 -r 2143f39103f7 sdcard.cpp
--- a/sdcard.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/sdcard.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -24,12 +24,7 @@
 FILE *fp;                                                                       // FILE pointer for random use
   
   
-void sd_open_mainfile(int32_t pid)
-{
-    char buffer1[32];
-    sprintf(buffer1,"/sd/%d.csv",pid);
-    fp = fopen(buffer1,"a"); 
-}
+
 
  
 void sd_open_GLCfilee(uint32_t pid)                                             // only opening the glc file after entering TEST screen
@@ -57,13 +52,9 @@
     fclose(fpbp);
 } 
   
-void sd_write (int value)                                                       // writing data into the file
-{
-    fprintf(fp,"%d\n", value);
-}
+
  
- 
-uint8_t sd_open_read(uint32_t pid)                                              // opening the file for read   
+uint8_t sd_open_read_bt(uint32_t pid)                                            // opening the file for read //name changed nikita  
 {
     char buffer1[32] = {};
     sprintf(buffer1,"/sd/%d.csv",pid);
@@ -80,23 +71,19 @@
     }
 }
  
-void sd_read(uint32_t  *v1, uint16_t size)                                      //reading the data from the openend file
+void sd_read_bt(uint32_t  *v1, uint16_t size)                                    //reading the data from the openend file// nikita changed name
 {
     fread(v1,sizeof(v1),size,fp);
 }
 
-void setpos()
-{
-    rewind (fp);
-}
 
-void setpos1(uint32_t position)
+void setpos_file(uint32_t position)                                        //changed the name nikita
 {
     fseek ( fp , position, SEEK_SET );  
 }
 
 
-uint32_t file_size()    
+uint32_t file_size_init()                                                       //changed the name nikita// defines the size of the file    
 {
     uint32_t file_length = 0;
     
@@ -108,7 +95,7 @@
 }  
      
      
-uint32_t file_size1()    
+uint32_t file_size_sent()                                                       //changed the name // defines the file size sent on bluetooth   
 {
     uint32_t file_length;
     
@@ -116,31 +103,25 @@
     return   file_length;
 }  
 
-void sd_read1(BLEMsg_info &f)
+void sd_read_struct(BLEMsg_info &f)                                             //changed the function name nikita
 {
     fread(&f,sizeof(BLEMsg_info),1,fp);
 }
  
   
-FILE *sd_BP_ecgwrite (uint32_t *fpdrum11)                                       // writing data into the file NIDHIN  
+FILE *sd_BP_ecgwrite (uint32_t *fp_bp_ecg)                                       // writing data into the file NIDHIN //pointer name changed nikita 
 {
-    fwrite(fpdrum11,sizeof(uint32_t),1, fpecg);                                 // Direct writing to SD card.
+    fwrite(fp_bp_ecg,sizeof(uint32_t),1, fpecg);                                 // Direct writing to SD card.
     return fpecg;
 }
 
-FILE* sd_BP_ppgwrite (uint32_t *fpdrum21)                                       // Direct writing to SD card.
+FILE* sd_BP_ppgwrite (uint32_t *fp_bp_ppg)                                       // Direct writing to SD card.// pointer name changed nikita
 {
-    fwrite(fpdrum21,sizeof(uint32_t),1, fpppg);                                 //Direct writing to SD card.
+    fwrite(fp_bp_ppg,sizeof(uint32_t),1, fpppg);                                 //Direct writing to SD card.
     return fpppg;
 }
   
-void sd_reopen_BPfilee(uint32_t pid)                                            // only opening the BP file after entering TEST screen
-{
-    char buffer1[32];
-    sprintf(buffer1,"/sd/%d_BP.csv",pid);
-    fp = fopen(buffer1,"r"); 
 
-} 
 
 void sd_open_BP_ECGfile(uint32_t pid)         
 {
@@ -180,16 +161,13 @@
     fclose(fpeecg);
 }
 
-void sd_close_glc()                                                             // Closes GLC file pinted by fpbg
-{
-    fclose(fpbg);
-}
+
  
 //------- FUNCTION TO CREATE SINGLE BP FILE -----------------//
 void create_single_BPfile(uint32_t pid)
 {  
     char buffer3[32];
-    
+    uint8_t bp_loop = 0;
     sprintf(buffer3, "/sd/%d_BP.csv", pid);
     fpbp = fopen(buffer3, "a");                                                 // Opens BP file with FILE pointer fpbp in APPEND mode
     
@@ -199,16 +177,16 @@
     sprintf(buffer3, "/sd/%d_BP_PPG.csv", pid);
     fpppg = fopen(buffer3, "r");                                                // Opens PPG file of BP with FILE pointer fpppg in READ mode
 
-    for(int i=0; i<16; i++)
+    for(bp_loop=0; bp_loop<16; bp_loop++)
     {
-        int ecgbuf[64] = {0} ;
+        uint32_t ecgbuf[64] = {0} ;                                             //changed from int to uint32_t//nikita
         fread(ecgbuf, sizeof(uint32_t), 64, fpecg);
         fwrite(ecgbuf, sizeof(uint32_t), 64, fpbp);                             // Copy ECG data of BP into BP file
     }
 
-    for(int i=0; i<26; i++)
+    for(bp_loop=0; bp_loop<26; bp_loop++)                                             //changed from int to uint32_t//nikita
     {
-        int ppgbuf[64] = {0} ;
+        uint32_t ppgbuf[64] = {0} ;
         fread(ppgbuf, sizeof(uint32_t), 64, fpppg);
         fwrite(ppgbuf, sizeof(uint32_t), 64, fpbp);                             // Copy PPG data of BP into BP file
     }
@@ -263,6 +241,8 @@
 void bpfile_mainfile(uint32_t pid)                                              //Copy data of bp file to main
 {
     char buffer3[32];
+    uint8_t bp_loop = 0;
+    int success;
     sprintf(buffer3, "/sd/%d.csv", pid);
     fpmain = fopen(buffer3, "a");                                               // Opens Main file with FILE pointer "fpmain" in APPEND mode
     
@@ -270,18 +250,19 @@
     fpbp = fopen(buffer3, "r");                                                 // Opens BP file with FILE pointer "fpbp" in READ mode
     
     
-    for(int i=0; i<21; i++)
+    for(bp_loop=0; bp_loop<21; bp_loop++)                                             //changed from int to uint32_t//nikita
     {
-        int bigbuf[128] = {0} ;
+        uint32_t bigbuf[128] = {0} ;
         fread(bigbuf, sizeof(uint32_t), 128, fpbp);
         fwrite(bigbuf, sizeof(uint32_t), 128, fpmain);                          // Copy BP raw data into main file 
     }
     fclose(fpbp);                                                               // Close BP file
     fclose(fpmain);                                                             // Close Main File
     
-    int success;
+   
     sprintf(buffer3, "/sd/%d_BP.csv", pid);
     success = remove(buffer3);                                                  // Should return zero on success
+    snd.printf("DELETE STATUS = %d\n", success); 
 }
 
 void sd_ecgwrite(uint32_t *ecg_ptr)                                             //function to print ECG data to Sd card using fwrite                                     
@@ -293,7 +274,7 @@
 {
     char buffer3[32];
     int success;
-    
+    uint8_t ecg_loop = 0;                                                       //loop name changed nikita
     sprintf(buffer3, "/sd/%d.csv", pid);       
     fpmain = fopen(buffer3, "a");                                               // Main File is opened in Append mode
     snd.printf("opening main file\n");
@@ -302,11 +283,11 @@
     fpeecg = fopen(buffer3, "r");
     snd.printf("opening temp file\n");
     
-    for(int i=0; i<20; i++)                                                     //the loop runs as 20 times of 100 i.e., 2k
+    for(ecg_loop=0; ecg_loop<20; ecg_loop++)                                                     //the loop runs as 20 times of 100 i.e., 2k
     {
-        int bigbuf[100] = {0} ;
-        fread(bigbuf, sizeof(int),100 , fpeecg);
-        fwrite(bigbuf, sizeof(int), 100, fpmain);
+        uint32_t bigbuf[100] = {0} ;                                            //changed from int to uint32_t//nikita
+        fread(bigbuf, sizeof(uint32_t),100 , fpeecg);
+        fwrite(bigbuf, sizeof(uint32_t), 100, fpmain);
     }
     snd.printf("to close temp file\n");
     fclose(fpeecg);                                                             // Both files are Closed
@@ -365,6 +346,7 @@
     
     sprintf(buffer3, "/sd/%d_GLC.csv", pid);  
     success = remove(buffer3);                                                  // GLC file is deleted
+    snd.printf("DELETE STATUS = %d\n", success);
 }
 
 
@@ -438,7 +420,7 @@
 void sd_read(uint32_t  *pid_btpid)                                              //reading the data from the openend file
 {
     uint32_t pid[2]={0,0};
-    int success;
+ //   int success;
     FILE *fp;
     
     fp= fopen("/sd/pid_info.txt","r");
@@ -456,7 +438,7 @@
 }
  
  
-void sd_write(uint32_t  *pid_btpid)                                             //reading the data from the openend file
+void sd_write_pid(uint32_t  *pid_btpid)                                             //reading the data from the openend file
 {
      FILE *fp;
      fp= fopen("/sd/pid_info.txt","w");
@@ -530,7 +512,7 @@
         for(uint16_t file_start=0;file_start<sample;file_start++)                                //reading the raw data
         {     
             fread(buf,sizeof(uint32_t),1,fp_read_sdcard_file);
-            snd.printf("%08x\n", buf[0]);
+            snd.printf("%d\n", buf[0]);                                                         //changed to %d nikita
         }
         fread(&pid_file,sizeof(BLEMsg_info),1,fp_read_sdcard_file);
            
diff -r 945c4a1e9a13 -r 2143f39103f7 sdcard.h
--- a/sdcard.h	Fri Dec 15 11:57:03 2017 +0000
+++ b/sdcard.h	Tue Dec 19 06:58:44 2017 +0000
@@ -8,24 +8,24 @@
 void sd_open_ECGfilee(uint32_t pid);
 void sd_open_GLCfilee(uint32_t pid);
 void sd_open_BPfilee(uint32_t pid);
-void sd_write (int value);
-uint32_t file_size() ;
-uint32_t file_size1() ;
-void sd_read(uint32_t  *v1, uint16_t size);
-uint8_t sd_open_read(uint32_t pid);
-void sd_read1(BLEMsg_info &f);
-void setpos();
-void setpos1(uint32_t position);
+//void sd_write (int value);                                                    //not used anywhere//nikita//commented
+uint32_t file_size_init() ;
+uint32_t file_size_sent() ;
+void sd_read_bt(uint32_t  *v1, uint16_t size);
+uint8_t sd_open_read_bt(uint32_t pid);
+void sd_read_struct(BLEMsg_info &f);
+//void setpos_bt();
+void setpos_file(uint32_t position);
 uint16_t heart_cal(int pid);
-FILE *sd_BP_ecgwrite (uint32_t *fpdrum11);
-FILE *sd_BP_ppgwrite (uint32_t *fpdrum21);
+FILE *sd_BP_ecgwrite (uint32_t *fp_bp_ecg);
+FILE *sd_BP_ppgwrite (uint32_t *fp_bp_ppg);
 void sd_open_BP_ECGfile(uint32_t pid);                                          //added to write ECG to seperate file BP
 void sd_open_BP_PPGfile(uint32_t pid);                                          //added to write PPG to seperate file BP
 void sd_close();                                                                // Close files opend with FILE pointer fp
 void sd_close_ecg() ;                                                           // Close files opend with FILE pointer fpeecg
 void sd_close_glc() ;                                                           //Close files opend with FILE pointer fpbg
 void create_single_BPfile(uint32_t pid);                                        //Function to create 1 file from 2 temp BP file (ECG &PPG)
-void sd_open_mainfile(uint32_t pid);                                            // Function for oprning main file
+//void sd_open_mainfile(uint32_t pid);                                            // Function for oprning main file
 void structure_file(BLEMsg_info *ptr, uint32_t pid);                            // Writes structure to the File.
 void bpfile_mainfile(uint32_t pid);
 void sd_ecgwrite(uint32_t *ecg_ptr);                                            //to print ECG data in ECG func as binary using fwrite.  
@@ -34,7 +34,7 @@
 void glcfile_mainfile(uint32_t pid);                                            // GLC file to main file
 void delete_subfiles(uint32_t pid);                                             //deletes all subfiles under a pid
 void del_ppg_ecg_BPfile(uint32_t pid);                                          // deletes temporary ECG_PPG files in BP when ERROR condition- 22/7/17-Suhasini
-void sd_write(uint32_t  *pid_btpid);
+void sd_write_pid(uint32_t  *pid_btpid);
 void sd_read(uint32_t  *pid_btpid);
 void delete_sdcard(void);                                                       //delete sd card
 void read_structure(FILE *fp_read_sdcard_file);
diff -r 945c4a1e9a13 -r 2143f39103f7 struct.h
--- a/struct.h	Fri Dec 15 11:57:03 2017 +0000
+++ b/struct.h	Tue Dec 19 06:58:44 2017 +0000
@@ -4,7 +4,6 @@
 #include "bp.h"
 #include "glc.h"
 #include "ecg_dec.h"
-//#include "test_type.h"
 
 
 typedef struct __attribute__((__packed__))
@@ -30,14 +29,6 @@
     uint16_t             cal_dbp_OTtyp;
 }CalData_info;
 
-/*typedef enum 
-{ 
-     ACK = (uint8_t)0x00,
-    start_of_file,
-    end_of_file,
-    data_trfr,
-    NACK=0xff,
-}bt_st;*/
 
 typedef enum
 { 
@@ -59,13 +50,6 @@
   CalData_info          cal_data;
 }BLEMsg_info;
 
-/*typedef enum 
-{ 
-     sos= (uint8_t)0xc0,
-     eos= (uint8_t)0xc0,
-}file_st;*/
-
-
 
 typedef struct __attribute__((__packed__))
 {
@@ -79,7 +63,6 @@
 
 }Point;
 
-
 uint8_t bt_send( uint8_t send_tx);
 uint8_t bt_receive(uint8_t send_rx);
 void send_structure();
@@ -87,11 +70,9 @@
 void send_last_string();
 void send_data_str1();
 void send_data_str2(uint8_t check_sum);
-//uint8_t checksum(uint32_t  *v1);
 uint8_t checksum_init();;
 uint8_t checksum_last();
-//uint8_t checksum_struct();
-
 uint8_t checksum_struct(const uint8_t data[], uint16_t numBytes) ;
 uint8_t checksum_rawdata(const uint8_t data[], uint32_t numBytes) ;
+
 #endif
\ No newline at end of file
diff -r 945c4a1e9a13 -r 2143f39103f7 touch_modules.cpp
--- a/touch_modules.cpp	Fri Dec 15 11:57:03 2017 +0000
+++ b/touch_modules.cpp	Tue Dec 19 06:58:44 2017 +0000
@@ -24,9 +24,9 @@
 Timer screen_timer;
 
 bool touch_detect_flag = false;
-unsigned int x_coordinate = 0;
-unsigned int y_coordinate = 0;
-
+uint16_t x_coordinate = 0;                                                      //changed from unsigned int to uint16_t nikita 
+uint16_t y_coordinate = 0;                                                      //changed from unsigned int to uint16_t nikita 
+uint8_t state=0;                                                                //changed from unsigned char to uint8_t nikita 
 
 void touch1()  //determining the touch co-ordinates
 {
@@ -38,7 +38,7 @@
 }
 
 
-void detect_touch(unsigned char display_state)   // detect the touch //debounce
+void detect_touch(uint8_t display_state)   // detect the touch //debounce
 {
     kc.printf("display state=%d\n",display_state);
     uint32_t time_ms = 0;
@@ -91,13 +91,13 @@
    x_coordinate = 0;
    y_coordinate = 0;
   
- }
+}
 
 
-unsigned char touch_main()    //determining the touch for home screen
+uint8_t touch_main()    //determining the touch for home screen
 {
     
-    unsigned char state = 0;
+    
     
     if ( ((x_coordinate >= SYSCFG_HOME_X_MIN) && (x_coordinate <= SYSCFG_HOME_X_MAX)) && ( (y_coordinate >= SYSCFG_HOME_Y_MIN) && (y_coordinate <= SYSCFG_HOME_Y_MAX) ) ) // system configuration
     { 
@@ -115,10 +115,10 @@
 }
    
    
-unsigned char touch_main_1()    //determining the touch for System Configuration screen
+uint8_t touch_main_1()    //determining the touch for System Configuration screen
 {
 
-    unsigned char state=0;
+   
     
     if ( ((x_coordinate >= BT_MAIN_X_MIN) && (x_coordinate <= BT_MAIN_X_MAX)) && ( (y_coordinate >= BT_MAIN_Y_MIN) && (y_coordinate <= BT_MAIN_Y_MAX) ) )                                                   // ble
     {
@@ -149,9 +149,9 @@
 }
 
 
-unsigned char touch_main_2()    //determining the touch for TEST screen
+uint8_t touch_main_2()    //determining the touch for TEST screen
 {
-    unsigned char state=0;
+   
     
     if ( ((x_coordinate >= BG_MAIN_X_MIN) && (x_coordinate <= BG_MAIN_X_MAX)) && ( (y_coordinate >= BG_MAIN_Y_MIN) && (y_coordinate <= BG_MAIN_Y_MAX) ) ) // GLC
     {
@@ -186,10 +186,10 @@
 
 
 
-unsigned char touch_ecg()     // determining the touch for ecg  main screen
+uint8_t touch_ecg()     // determining the touch for ecg  main screen
 {
 
-    unsigned char state = 0;
+   
     
     if ( ((x_coordinate >= START_MAIN_X_MIN) && (x_coordinate <= START_MAIN_X_MAX)) && ( (y_coordinate >= START_MAIN_Y_MIN) && (y_coordinate <= START_MAIN_Y_MAX) ) ) // START
     {
@@ -207,10 +207,9 @@
 }
     
 
-unsigned char touch_ret()     // determining the touch for ecg screen after the test
+uint8_t touch_ret()     // determining the touch for ecg screen after the test
 {
       
-    unsigned char state = 0;
     uint8_t test_type_retest = 0;
     test_type_retest = eprom_read_8(EEPROM_ADDRTEST_TYPE);
     kc.printf("testtype = %d\n", test_type_retest);
@@ -240,9 +239,9 @@
 
 
 
-unsigned char touch_bp()   // //determining the touch for bp main screen
+uint8_t touch_bp()   // //determining the touch for bp main screen
 {
-    unsigned char state = 0;
+    
     if ( ((x_coordinate >= START_MAIN_X_MIN) && (x_coordinate <= START_MAIN_X_MAX)) && ( (y_coordinate >= START_MAIN_Y_MIN) && (y_coordinate <= START_MAIN_Y_MAX) ) ) // START
     {
         state = 9;
@@ -260,9 +259,9 @@
     
     
     
-unsigned char touch_glc()        //determining the touch for GLC screen
+uint8_t touch_glc()        //determining the touch for GLC screen
 {
-    unsigned char state = 0;
+    
     
     if ( ((x_coordinate >= FPS_MAIN_X_MIN) && (x_coordinate <= FPS_MAIN_X_MAX)) && ( (y_coordinate >= FPS_MAIN_Y_MIN) && (y_coordinate <= FPS_MAIN_Y_MAX) ) ) //fasting     // 12/06/17       newly added
     {
@@ -292,10 +291,10 @@
       
  
  
-unsigned char touch_again_ecg()    //determining the touch for Repeat test 
+uint8_t touch_again_ecg()    //determining the touch for Repeat test 
 {
 
-    unsigned char state = 0;
+    
     
     if ( ((x_coordinate >= YES_MAIN_X_MIN) && (x_coordinate <= YES_MAIN_X_MAX)) && ( (y_coordinate >= YES_MAIN_Y_MIN) && (y_coordinate <= YES_MAIN_Y_MAX) ) ) // YES
     {
@@ -311,10 +310,10 @@
 }
  
  
-unsigned char touch_again_glc()    //determining the touch for Repeat test 
+uint8_t touch_again_glc()    //determining the touch for Repeat test 
 {
 
-    unsigned char state = 0;
+   
     
     if ( ((x_coordinate >= YES_MAIN_X_MIN) && (x_coordinate <= YES_MAIN_X_MAX)) && ( (y_coordinate >= YES_MAIN_Y_MIN) && (y_coordinate <= YES_MAIN_Y_MAX) ) ) // YES
     {
@@ -329,9 +328,9 @@
     return state;     
 }
     
-unsigned char touch_again_bp()    //determining the touch for Repeat test 
+uint8_t touch_again_bp()    //determining the touch for Repeat test 
 {
-    unsigned char state = 0;
+    
     
     if ( ((x_coordinate >= YES_MAIN_X_MIN) && (x_coordinate <= YES_MAIN_X_MAX)) && ( (y_coordinate >= YES_MAIN_Y_MIN) && (y_coordinate <= YES_MAIN_Y_MAX) ) ) // YES
     {
@@ -346,9 +345,9 @@
     return state;     
 } 
  
-unsigned char BT_return()   // //determining the touch for bp main screen
+uint8_t BT_return()   // //determining the touch for bp main screen
 {
-    unsigned char state = 0;
+  
     
     if ( ((x_coordinate >= MAIN_X_MIN) && (x_coordinate <= MAIN_X_MAX)) && ( (y_coordinate >= MAIN_Y_MIN) && (y_coordinate <= MAIN_Y_MAX) ) ) // RETURN
         state = 1;
@@ -358,9 +357,9 @@
     return state;
 }
 
-unsigned char touch_debug()
+uint8_t touch_debug()
 {
-    unsigned char state=0;
+   
     
     
     if ( ((x_coordinate >= SD_DEL_X_MIN) && (x_coordinate <= SD_DEL_X_MAX)) && ( (y_coordinate >= SD_DEL_Y_MIN) && (y_coordinate <= SD_DEL_Y_MAX) ) ) 
@@ -390,7 +389,7 @@
 
  //TOUCH Functionalities for new display// 
  
- int readTouchY(void)      // read the Y co-ordinate
+uint16_t readTouchY(void)                                                        // read the Y co-ordinate// changed the return type int to uint16_t nikita 
 {      
     DigitalOut Y_down(Y_DOWN_PIN);
     DigitalIn X_left(X_LEFT_PIN );
@@ -403,7 +402,7 @@
 }
     
     
-int readTouchX(void)    // // read the X co-ordinate
+uint16_t readTouchX(void)                                                       // uint16_t// read the X co-ordinate//// changed the return type int to uint16_t nikita
 {
     DigitalOut X_right(X_RIGHT_PIN);
     DigitalIn Y_down(Y_DOWN_PIN);
diff -r 945c4a1e9a13 -r 2143f39103f7 touch_modules.h
--- a/touch_modules.h	Fri Dec 15 11:57:03 2017 +0000
+++ b/touch_modules.h	Tue Dec 19 06:58:44 2017 +0000
@@ -126,29 +126,29 @@
 #define DEBUG_BACK_Y_MIN 180
 #define DEBUG_BACK_Y_MAX 260
 
-unsigned char touch_main();
-unsigned char touch_main_1();
-unsigned char touch_main_2();
+uint8_t touch_main();
+uint8_t touch_main_1();
+uint8_t touch_main_2();
 void touch1() ;
-int readTouchY(void);
-void detect_touch(unsigned char display_state);
-int readTouchX(void);
+uint16_t readTouchY(void);
+void detect_touch(uint8_t display_state);
+uint16_t readTouchX(void);
 void EnableTouch(void);
 void DisableTouch (void);
-unsigned char touch_main();
-unsigned char touch_glc();
-unsigned char touch_ecg();
-unsigned char touch_bp();
-unsigned char touch_ret();
-unsigned char touch_again_ecg();
-unsigned char touch_again_glc(); 
-unsigned char touch_again_bp(); 
+uint8_t touch_main();
+uint8_t touch_glc();
+uint8_t touch_ecg();
+uint8_t touch_bp();
+uint8_t touch_ret();
+uint8_t touch_again_ecg();
+uint8_t touch_again_glc(); 
+uint8_t touch_again_bp(); 
 void screen_bp2();
-unsigned char BT_return();   // //determining the touch for bp main screen
+uint8_t BT_return();   // //determining the touch for bp main screen
 void touch_func_with_timer(uint32_t time_ms);
 void touch_func_without_timer();
 uint32_t get_timer();
 void no_touch();
-unsigned char touch_debug(); 
+uint8_t touch_debug(); 
 void touch_detection();             // to detect the touch // separate routine
 #endif
\ No newline at end of file