Fix all the following issues which we faced during 01st April internal demo 1) Display hang and jump issue 2) Sequencing issue 3) Issue with BP code

Dependencies:   SDFileSystem ds3231 program mbed testUniGraphic_150217

Fork of Int_Demo_01Apr2017_newdisplaycode_bp_nikita by nikita teggi

Revision:
8:adf2ba7e6412
Parent:
4:6bd81bb1790d
Child:
10:aeff3309002a
--- a/sdcard.cpp	Wed Apr 26 10:14:53 2017 +0000
+++ b/sdcard.cpp	Fri Apr 28 10:05:29 2017 +0000
@@ -1,3 +1,4 @@
+ /*
  #include "mbed.h"
  #include <stdio.h>
  #include "SDFileSystem.h"
@@ -96,6 +97,280 @@
   void sd_close()            //closing the file
   {
    fclose(fp);
-   }
+   }*/
+ 
+ //----------------------------------------NEW ADD NIDHIN 28/4/2017-------------------------------//
+ 
+ #include "mbed.h"
+ #include <stdio.h>
+ #include "SDFileSystem.h"
+ #include "sdcard.h"
+  #include "rtc.h"
+  
+  Serial snd(USBTX,USBRX);
+  
+
+  SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd");
+  FILE *fp;
+  FILE *fpecg;  // PPG and ECG File pointers for BP
+  FILE *fpppg;
+  
+  int ecgloc = 0;  // PPG and eCG maximum locations
+  int ppgloc = 0;  
+  
+  int ebp = 0;      // variable for LOOP operation to read value from File i == ECG , j == PPG
+  int pbp = 0;
+  
+  
+ void sd_open_GLCfile(int pid)     // opening the glc file
+ {
+     
+  char buffer[32];
+  char buffer1[32];
+  time_t  epoch_time1;
+  epoch_time1=rtc_read();
+ // strftime(buffer, 32, "GLC_%s", pid);
+  
+ sprintf(buffer1,"/sd/%d_GLC.csv",pid);   
+  fp = fopen(buffer1,"a"); 
+  fprintf(fp,"%s\n",ctime(&epoch_time1) );  //writing the date, time into the file
+  
+ 
+ }   
+ 
+  void sd_open_GLCfilee(int pid)    // only opening the glc file after entering TEST screen
+ {
+     
+
+  char buffer1[32];
+  sprintf(buffer1,"/sd/%d_GLC.csv",pid);
+  fp = fopen(buffer1,"a"); 
+   fprintf(fp,"PATIENT ID %d\n",pid);
+  
+ 
+ } 
+ 
+  void sd_open_ECGfile(int pid)         
+ {
+     
+ // char buffer[32];
+  char buffer1[32];
+  time_t  epoch_time1;
+  epoch_time1=rtc_read();
+  // strftime(buffer, 32, "ECG_%d", pid);
+  
+  sprintf(buffer1,"/sd/%d_ECG.csv",pid);
+  fp = fopen(buffer1,"a"); 
+  fprintf(fp,"%s\n",ctime(&epoch_time1) );
+ 
+ } 
+ 
+  void sd_open_ECGfilee(int pid)          // only opening the ECG file after entering TEST screen
+ {
+     
+  char buffer1[32];
+   sprintf(buffer1,"/sd/%d_ECG.csv",pid);
+  fp = fopen(buffer1,"a"); 
+  fprintf(fp,"PATIENT ID %d\n",pid );
+ 
+ } 
+ 
+ 
+  void sd_open_BPfile(int pid)         
+ {
+     
+  char buffer[32];
+  char buffer1[32];
+  time_t  epoch_time1;
+  epoch_time1=rtc_read();
+  // strftime(buffer, 32, "ECG_%d", pid);
+  
+  sprintf(buffer1,"/sd/%d_BP.csv",pid);
+  fp = fopen(buffer1,"a"); 
+  fprintf(fp,"%s\n",ctime(&epoch_time1) );
+ } 
+
+void sd_open_BPfilee(int pid)          // only opening the BP file after entering TEST screen
+ {
+     
+ 
+  char buffer1[32];
+  sprintf(buffer1,"/sd/%d_BP.csv",pid);
+  fp = fopen(buffer1,"a"); 
+  fprintf(fp,"PATIENT ID %d\n",pid );
+ 
+ } 
+  
+ void sd_write (int value)      // writing data into the file
+ {
+    fprintf(fp,"%d\n", value);
+ }
+ 
+ //------------------------------------------------------
+  
+//FILE *sd_BP_ecgwrite (int value)      // writing data into the file NIDHIN
+FILE *sd_BP_ecgwrite (int *fpdrum11)      // writing data into the file NIDHIN
+  {
+        fwrite(fpdrum11,sizeof(int),64, fpecg); 
+        return fpecg;
+  }
+    
+FILE* sd_BP_ppgwrite (uint32_t *fpdrum21)      // writing data into the file NIDHIN
+  {
+       fwrite(fpdrum21,sizeof(uint32_t),64, fpppg); 
+    return fpppg;
+  }
+  //-----------------------------------------------SD Read
+  
+  void sd_reopen_BPfilee(int pid)          // only opening the BP file after entering TEST screen
+ {
+     
+ 
+  char buffer1[32];
+  sprintf(buffer1,"/sd/%d_BP.csv",pid);
+  fp = fopen(buffer1,"r"); 
+  //fprintf(fp,"PATIENT ID %d\n",pid );
+ 
+ 
+ } 
+  //-------------------------------------------------
+
+
+//---------------------------------------
+
+
+   void sd_open_BP_ECGfile(int pid)         
+ {
+     
+  //char buffer[32];
+  char buffer1[32];
+  //time_t  epoch_time1;
+  //epoch_time1=rtc_read();
+  // strftime(buffer, 32, "ECG_%d", pid);
+  
+  sprintf(buffer1,"/sd/%d_BP_ECG.csv",pid);
+  fpecg = fopen(buffer1,"a"); 
+  if (fpecg == NULL)
+  {
+      exit(1);
+  }   
+  //fprintf(fpecg,"%s\n",ctime(&epoch_time1) );
+  
+ } 
+ 
+  
+   void sd_open_BP_PPGfile(int pid)         
+ {
+     
+  char buffer1[32];
+  //time_t  epoch_time1;
+  //epoch_time1=rtc_read();
+  // strftime(buffer, 32, "ECG_%d", pid);
+  
+  sprintf(buffer1,"/sd/%d_BP_PPG.csv",pid);
+  fpppg = fopen(buffer1,"a"); 
+  if(fpppg == NULL)
+  {
+            exit(1);
+  }
+  
+  //fprintf(fpppg,"%s\n",ctime(&epoch_time1) );
+  
+ } 
+  
+  
+  
+  //--------------------------------------------------
+  
+//void sd_bp_read(  
+  
+void sd_close()            //closing the file
+  {
    
- 
\ No newline at end of file
+      fclose(fp);
+   }
+ //------------------------------------------  
+ //REOPEN FUNCTIONs for reading data Nidhin
+ 
+ int sd_BP_ECGMAX(int pid)         
+ {
+     
+  char buffer1[32];
+   
+  sprintf(buffer1,"/sd/%d_BP_ECG.csv",pid);
+  fpecg = fopen(buffer1,"r"); 
+  if(fpecg == NULL)
+  {
+            exit(1);
+  }
+  
+  else
+  {
+    int ecgmax = 0;
+    int a[1] = {0};
+    int samplesecg =0;
+for(ebp=0; ebp<1024; ebp++)
+    {
+
+    
+    fread(a,sizeof(int), 1,fpecg);
+    snd.printf("\n%d", a[0]);
+        if(a[0] > ecgmax)
+            {
+                ecgmax=a[0];
+                ecgloc= ebp +1;
+            }
+        else
+        samplesecg =ebp+1;
+    
+    }
+    }
+    fclose (fpecg);
+   return ecgloc; 
+ } 
+ 
+ // Function to calculate PPG MAx and location
+ 
+   int sd_BP_PPGMAX(int pid)         
+ {
+     
+  char buffer1[32];
+   
+  sprintf(buffer1,"/sd/%d_BP_PPG.csv",pid);
+  fpppg = fopen(buffer1,"r"); 
+  if(fpppg == NULL)
+  {
+            exit(1);
+  }
+  
+  else
+  {
+    uint32_t ppgmax = 0;
+    uint32_t b[1] ={0};
+    int samplesppg = 0;
+       for(pbp=0; pbp<1664; pbp++)
+            {
+                fread(b, sizeof(uint32_t),1, fpppg);
+                snd.printf("\n%d", b[0]);
+                
+                if((pbp>ecgloc) && (pbp< (ecgloc+350)))
+                    {
+                        if(b[0] > ppgmax)
+                            {
+                                ppgmax=b[0];
+                                ppgloc= pbp+1;
+                            }
+                        else
+                            samplesppg =pbp+1;
+                    }
+                else 
+                    samplesppg = pbp+1;
+            }
+    }        
+    fclose (fpppg);
+    return ppgloc;
+ } 
+
+//fread(buffer, 1, size, fp)
+//fwrite(&buffer, ,   
+ //----------------------------------------------------28/4/2017---------------------------------
\ No newline at end of file