Changes done in ECG and BT

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of merged_code2_20sept_2017_4th_oct_2017 by nikita teggi

Files at this revision

API Documentation at this revision

Comitter:
nidhinvarghese
Date:
Thu Jun 01 09:24:45 2017 +0000
Parent:
13:5d3b478ea9c7
Child:
15:208b146151ba
Commit message:
HR code is running with Structure ; COMPILATION success; Results not accurate

Changed in this revision

bp.cpp Show annotated file Show diff for this revision Revisions of this file
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
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
test_type.h Show annotated file Show diff for this revision Revisions of this file
--- a/bp.cpp	Sat May 27 05:47:55 2017 +0000
+++ b/bp.cpp	Thu Jun 01 09:24:45 2017 +0000
@@ -1,17 +1,14 @@
-
-//BP Optimised Program for Averaging the received value from PPG and ECG & Check for SD card Storage//
+//-----------------------------------------------NEW BP code starts--------------------------------///
 
 
-/** ECG ADS1291 Test program.
-ADS1291 is a single channel ECG chip
-with a 24 bit Sigma-Delta ADC
- */
 
-/* 
 #include "mbed.h"
 #include "MAX30102.h" // BP ADD
 #include <string.h>
 #include <stdio.h>
+
+#include <time.h>
+//#include <iostream>
 #include "ds3231.h"
 #include "SDFileSystem.h"
 #include "rtc.h"
@@ -21,218 +18,23 @@
 #include "display_modules.h"
 
 
-Serial bc(USBTX,USBRX);
-DigitalIn INTR(PTC7);
 
- 
-    
-void bp() {
- 
-//------------------BP ADD------------------------------//{ 
-//int location; // BP ADD
-int32_t n_red_buffer_length = 1500;    //data length
-uint32_t aun_red_buffer[1500];    //Red LED sensor data, set to 500
-uint32_t red_value;
-uint32_t ecg_value;
-uint8_t uch_dummy;
-uint32_t ecg_buf[1000];
-int32_t ecg_buffer_length = 1000;
-float SBP, DBP, PWV, delta_t;
-int d = 210;
-
-uint32_t un_min, un_max, ecg_min, ecg_max ;  //variables to calculate the on-board LED brightness that reflects the heartbeats
-    //int i, j;
-    float ecg_location, ppg_location; 
-    //int32_t n_brightness;
-    
-   // n_brightness=0;
-    un_min=0x3FFFF;
-    un_max=0;
-    ecg_min = 0xFFFFFF;
-    ecg_max = 0;
- //---------------- BP ADD-----------------------------//}
- 
- 
- //time_t epoch_time;
-  //int fp;
- int concatenate_value1 = 0;
-//uint32_t ecg_buf[1500];
-//int32_t ecg_der[1500];
-//int buff1[15]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
-//int32_t sample_sum; // static int32_t avg[1500];
- //int32_t count = 0; int32_t fs = 500; int32_t w=0,w1=0;
-
-   unsigned char chk = 1;
-    bc.baud(baud_rate);
-   // mySpi.frequency(freq) ;
-   // mySpi.format(bits, mode) ; 
- freqset();
-  //  Ds3231 rtc(PTC11, PTC10); //sda,scl2yy
-   
-   //------------------BP ADD---------------------------// {
-    while(bc.readable()==0)
-    {
-        bc.printf("\x1B[2J");  //clear terminal program screen
-        bc.printf("Press any key to start conversion\n\r");
-        wait(1);
-    }
-  wait(5);
-  bc.printf("Start of capture, Remain CALM and Donot MOVE\n");  
-  wait(2);
-  //-------------------BP ADD---------------------------//}
-    
-  setupfunc();
-  ecgsetupfunc(); 
-  //--------------- BP ADD------------------------------------//{
-  maxim_max30102_reset();  // PPG reset
-  maxim_max30102_init(); // PPG ADC register Initialise 
-  //---------------BP ADD ----------------------------------// }  
-  
- 
-   chk = 1;
- bc.printf("rawecg......................\n");
- for(int i=0; i<N_ECG; i++)
- {
-    
-     concatenate_value1=readvalue();
-    ecg_buf[i] = concatenate_value1;
-   
-    bc.printf( "%d\n", concatenate_value1);
-    maxim_max30102_read_reg(0,&uch_dummy);
-    while(INTR.read()==1); 
-    maxim_max30102_read_fifo((aun_red_buffer+i)); 
-     //bc.printf( "%d\n", concatenate_value1);
-      // bc.printf("%d\n",aun_red_buffer[i]);
-    //sd_write(concatenate_value); - -- BP ADD commented
-    //printf( "%d\n", concatenate_value); -- BP ADD commented
-    // bc.printf("loop2");
-    }
-    
-  for (int w=1000; w < n_red_buffer_length; w++)  // for reading extra 500 PPG samples.
-  {
- //bc.printf("loop2");
-  while(INTR.read()==1);
-  maxim_max30102_read_fifo((aun_red_buffer+w));
-  } 
-
-
-   //sd_close();  -- BP ADD commented
-   
-   int32_t ecg_n_denom;
-
- // 4 pt Moving Average ECG
-    bc.printf("PRINTING ECG 4 POINT IN DECIMAL........\n");
-    for(int y=0; y<996; y++){
-        ecg_n_denom= ( ecg_buf[y]+ ecg_buf[y+1]+ ecg_buf[y+2]+ ecg_buf[y+3]);
-        ecg_buf[y]=  ecg_n_denom/(int32_t)4;
-    }
-    for( int l= 0; l<1000; l++){
-    bc.printf("%d\n",ecg_buf[l]); //PRINTING ecg AFTER AVERAGING
-    }
-bc.printf("PRINTING PPG IN DECIMAL (after averaging)........\n");
-int32_t ppg_n_denom;
-  // 4 pt Moving Average PPG
-    for(int f=0; f<1496; f++){
-        ppg_n_denom= ( aun_red_buffer[f]+aun_red_buffer[f+1]+ aun_red_buffer[f+2]+ aun_red_buffer[f+3]);
-        aun_red_buffer[f]= ppg_n_denom/(int32_t)4;
-    }
-    for( int b = 0; b<1500; b++){
-       bc.printf("%d\n",aun_red_buffer[b]);
-    }
-    
-
-for(int f=0; f<ecg_buffer_length; f++)
-   {
-       if(ecg_min > ecg_buf[f])
-           ecg_min = ecg_buf[f];    //update signal min
-        if(ecg_max < ecg_buf[f])
-        {
-            ecg_max=ecg_buf[f];    //update signal max
-            ecg_location = f+1;
-    }
-    }
-    bc.printf( "ecg_location = %f\n", ecg_location);
-
-for(int g = ecg_location;  g < (ecg_location+400); g++) // Peak detect changed to 400 samples from 500 samples
-    {
-       if(un_min>aun_red_buffer[g])
-           un_min=aun_red_buffer[g];    //update signal min
-        if(un_max<aun_red_buffer[g])
-        {
-            un_max=aun_red_buffer[g];    //update signal max
-            ppg_location = g+1;
-    }
-    }
-bc.printf( "ppg_location = %f\n", ppg_location);
-
-delta_t = (2*(ppg_location - ecg_location))/1000;
-bc.printf( "delta_t = %f\n", delta_t);
-
-PWV = d/delta_t;
-bc.printf( "PWV = %f\n", PWV);
-
-SBP = 0.0508955*PWV+62.559;
-DBP = 0.0494*PWV + 17.480;
-
-
-bc.printf( "SBP = %f\n", SBP);
-bc.printf( "DBP = %f\n", DBP);
-
-screen_bp1(SBP,DBP);
-*/
-
-//-----------------WRITE ECG &PPG
- /*  
-sd_open_BPfile(1);
-for (int w=0; w < 1000; w++)
-{
-ecg_value =  ecg_buf[w];   
-sd_write(ecg_value);
-}
-
-
-
-for (int w=0; w < n_red_buffer_length; w++)
-{
-red_value =  aun_red_buffer[w];   
-sd_write(red_value); 
-}
-sd_close();*/
-
-//----------- FINISHED WRITING ECG & PPG TO SD CARD
-
-   
-
-        
- //}    // End of main function
-
-
-//-----------------------------------------------NEW BP code starts--------------------------------///
-
-#include "mbed.h"
-#include "MAX30102.h" // BP ADD
-#include <string.h>
-#include <stdio.h>
-//#include <iostream>
-#include "ds3231.h"
-#include "SDFileSystem.h"
-#include "rtc.h"
-#include "sdcard.h"
-#include "ec_bp.h"
-#include "bp.h"
-#include "display_modules.h"
+#include "struct.h"
+#include "test_type.h"
 
 using namespace std;
 
-Serial bc(USBTX,USBRX);
+Serial bpr(USBTX,USBRX);
 DigitalIn INTR(PTC7);
 
 Timer t; 
 
+
 //FILE *ecg;
 //FILE *ppg;
     
-void bp(int pid) {
+ void bp(int pid) {
+    
     uint8_t uch_dummy;
     uint32_t ppgdata; 
 
@@ -240,8 +42,83 @@
     int concatenate_value2 = 0;
     unsigned char chk = 1;
 
-    int drum11[64];
+    uint32_t drum11[64];
     uint32_t drum21[64];
+    
+           
+    //Declaration of  Master structure
+    
+    BLEMsg_info *ptr_BLEMsg_info_bp, BLEMsg_info_bp; // A copy of master strcuture [ "BLEMsg_info" ] by name "BLEMsg_info_bp" is created
+    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.
+    
+    
+    // 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
+    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 
+    bpr.printf("Time is %d: %d: %d\n", (*ptr_time_info_bp).tm_hour, (*ptr_time_info_bp).tm_min, (*ptr_time_info_bp).tm_sec);
+    bpr.printf("Date is %d:%d:%d\n", (*ptr_time_info_bp).tm_mday, (*ptr_time_info_bp).tm_mon+1, (*ptr_time_info_bp).tm_year-100);
+    
+    //Copying from one structure to the other using variables
+    DateTime_info_bp.hour = (uint8_t)(*ptr_time_info_bp).tm_hour;
+    DateTime_info_bp.mins = (uint8_t)(*ptr_time_info_bp).tm_min;
+    DateTime_info_bp.sec =  (uint8_t)(*ptr_time_info_bp).tm_sec;
+    
+    DateTime_info_bp.date = (uint8_t) (*ptr_time_info_bp).tm_mday;
+    DateTime_info_bp.month =(uint8_t)(*ptr_time_info_bp).tm_mon+1;
+    DateTime_info_bp.year = (uint8_t)(*ptr_time_info_bp).tm_year-100;
+    
+    // Copying Time to Main structure
+    BLEMsg_info_bp.date_time.hour = DateTime_info_bp.hour;
+    BLEMsg_info_bp.date_time.mins = DateTime_info_bp.mins;
+    BLEMsg_info_bp.date_time.sec = DateTime_info_bp.sec;
+    
+    BLEMsg_info_bp.date_time.date = DateTime_info_bp.date ;
+    BLEMsg_info_bp.date_time.month = DateTime_info_bp.month ;
+    BLEMsg_info_bp.date_time.year =  DateTime_info_bp.year ;
+    
+    
+    //Checking if the structure has these values    
+    bpr.printf("Time 2 is %d:%d:%d\n", DateTime_info_bp.hour, DateTime_info_bp.mins, DateTime_info_bp.sec);
+    bpr.printf("\t Date is %d:%d:%d\n",DateTime_info_bp.date, DateTime_info_bp.month, DateTime_info_bp.year);
+    
+    
+    //Loading values to of Test type
+    test_type_info test_type_info_bp;  // copy of " test_type_info" created  
+    test_type_info_bp = BP_Test;       // Loaded value 00 to the test type 
+    
+    BLEMsg_info_bp.test_type = test_type_info_bp;
+    //Check if 00 is getting printed
+    bpr.printf("Test Type is : %d\n", test_type_info_bp);
+    
+    
+    // Loading values of Length ,  PID, DID, sampling frequency, number of samples, calculated data.
+    BLEMsg_info_bp.device_id = 01;                   // Device ID fixed
+    BLEMsg_info_bp.patient_id = (uint32_t)pid;       // Patient ID
+    BLEMsg_info_bp.sampling_freq = 500;              // sampling frrquency
+    BLEMsg_info_bp.length = 10774;                   //Total length of data in bytes  22 B+10752 B
+    
+    /*
+    //Loading number of samples
+    NumSamples_info NumSamples_info_bp;              //Copy of structure NumSamples_info
+    NumSamples_info_bp.num_ppg_sample = 1664;        // PPG & ECG Sample number loaded in structure copy
+    NumSamples_info_bp.num_ecg_sample = 1024;
+    */
+    
+    BLEMsg_info_bp.num_samples.num_sample_ppg_dummy =  1664 ;// PPG  number of samples copied to master struct 
+    BLEMsg_info_bp.num_samples.num_sample_ecg_OTtyp =  1024 ; // ECG  number of samples copied to master struct
+    
+    
+      
+    
 
     // Variables for file operations
    // uint32_t amax=0;
@@ -253,7 +130,7 @@
    //int bloc = 0;
    //int samples = 0;
 
-    bc.baud(baud_rate);
+    bpr.baud(baud_rate);
 
     freqset();               // setting the frequency
     setupfunc();              
@@ -279,48 +156,52 @@
             
     }   
 
-
+    sd_open_BPfilee(pid);
     sd_open_BP_ECGfile(pid) ; //   sd_open_BP_ECGfile(123) draft file for testing
     sd_open_BP_PPGfile(pid) ; // sd_open_BP_PPGfile(123) draft file for testing
 
     FILE *ecg = NULL;
     FILE *ppg = NULL;
-    int *drum_ecg = NULL; // pointers to ecg buffer
+    uint32_t *drum_ecg = NULL; // pointers to ecg buffer  changed to uint32_t from int
     uint32_t *drum_ppg = NULL; // pointer to ppg buffer
     
     drum_ecg = drum11;
     drum_ppg = drum21;
     
-    for(int j =0 ; j<16; j++) // changed to 16 from 8
+    for(int j =0 ; j<1; j++) // changed to 16 from 8 // Change by Nidhin 30/5/2017 Direct writing to SD card. no loop required
     {
-        for(int i=0; i<64; i++)
+        for(int i=0; i<1024; i++)
         {
             concatenate_value2 = readvalue();
-            drum11[i]=concatenate_value2;   //drum11[i]=concatenate_value2;      drum11[i]=dummyconcat;
-         
+            //drum11[i]=(uint32_t)concatenate_value2;   //drum11[i]=concatenate_value2;      drum11[i]=dummyconcat; typecasted to uint32_t
+            //Change by Nidhin 30/5/2017 Direct writing to SD card.
+            ecg = sd_BP_ecgwrite(drum_ecg);
+            
             maxim_max30102_read_reg(0,&uch_dummy);
             while(INTR.read()==1); 
             maxim_max30102_read_fifo(&ppgdata); 
-            drum21[i]=ppgdata;    
+            ppg = sd_BP_ppgwrite(&ppgdata); //Change by Nidhin 30/5/2017 Direct writing to SD card.
+            //drum21[i]=ppgdata;            //Change by Nidhin 30/5/2017 Direct writing to SD card.
         }
                            
-            ecg = sd_BP_ecgwrite(drum_ecg); //
-            ppg = sd_BP_ppgwrite(drum_ppg);
+            //ecg = sd_BP_ecgwrite(drum_ecg); // //Change by Nidhin 30/5/2017 Direct writing to SD card.
+            //ppg = sd_BP_ppgwrite(drum_ppg); // //Change by Nidhin 30/5/2017 Direct writing to SD card.
         
         
     } 
     
-    for(int j =0 ; j<10; j++) // changed to 16 from 8
+    for(int j =0 ; j<1; j++) // changed to 16 from 8
     {
-        for(int i=0; i<64; i++)
+        for(int i=0; i<640; i++)
         {
             maxim_max30102_read_reg(0,&uch_dummy);
             while(INTR.read()==1); 
             maxim_max30102_read_fifo(&ppgdata); 
-            drum21[i]=ppgdata; 
+            //drum21[i]=ppgdata; 
+            ppg = sd_BP_ppgwrite (&ppgdata);         //Change by Nidhin 30/5/2017 Direct writing to SD card.
         }
         
-         ppg = sd_BP_ppgwrite (drum_ppg);
+         
         
      }  
     fclose(ecg);
@@ -355,8 +236,24 @@
     SBP = 0.0508955*PWV+62.559;
     DBP = (0.0494*PWV + 17.480)+10;
     
+    /*
+    //Copying to Structure starts
+    CalData_info CalData_info_bp;
+    CalData_info_bp.cal_sbp = (uint16_t) SBP;
+    CalData_info_bp.cal_dbp = (uint16_t) DBP; NOT REQUIRED
+    */
+    
+    BLEMsg_info_bp.cal_data.cal_sbp_dummy = (uint16_t) SBP;
+    BLEMsg_info_bp.cal_data.cal_dbp_OTtyp = (uint16_t) DBP;
+    
+    
+    
+    create_single_BPfile(pid);                          // Copy ECG and PPG data to BP file
+    structure_file(ptr_BLEMsg_info_bp, pid);            // Copy BP structure to main file
+    bpfile_mainfile(pid);
+    
     screen_bp1(SBP,DBP);
     
-    create_single_BPfile(pid);
- 
- }
\ No newline at end of file
+    // Only for testing
+ }
+ 
\ No newline at end of file
--- a/bp.h	Sat May 27 05:47:55 2017 +0000
+++ b/bp.h	Thu Jun 01 09:24:45 2017 +0000
@@ -1,19 +1,21 @@
-/*
-#ifndef BP_H_
-#define BP_H_
-
-
-void bp();
-#endif
-*/
-
-//-------------------------------NEW BP Nidhin Add 28/4/2017--------------------
+//Whole Code replaced by Nidhin 1/6/2017
 
 #ifndef BP_H_
 #define BP_H_
 
+#define DID 101
+#define BP_S_FREQ 500
+
+#define BUFFER 64
+#define ECG_LOOP 16
+#define PPG_LOOP 26
+
+#define ECG_SPLS BUFFER*ECG_LOOP
+#define PPG_SPLS BUFFER*PPG_LOOP
+#define BPLEN_BYT 10778 // TOTAL length in BYTEs for BP inclu Should change if BUffer is changed
+//#define 
 
 void bp(int pid);
-#endif
+
 
-//--------------------------------------------28/4/2017---------------------------
+#endif
\ No newline at end of file
--- a/ecgg.cpp	Sat May 27 05:47:55 2017 +0000
+++ b/ecgg.cpp	Thu Jun 01 09:24:45 2017 +0000
@@ -12,14 +12,95 @@
 #include "rtc.h"
 #include "sdcard.h"
 #include "ec_bp.h"
+
+#include "struct.h"  // Added on 31/5/17_Nidhin
+#include "test_type.h" //Added on  31/5/17_Nidhin
 Serial pc(USBTX,USBRX);  
 
 
 
 float ecg(int pid) 
  {
+    //----------------------- Structure for Bluetooth  Added Nidhin 1/6/2017-------------------//
+    
+    //BLUETOOTH STRUCTURE
+    
+    BLEMsg_info *ptr_BLEMsg_info_ecg, BLEMsg_info_ecg; // A copy of master strcuture [ "BLEMsg_info" ] by name "BLEMsg_info_ecg" is created
+    ptr_BLEMsg_info_ecg = &BLEMsg_info_ecg;            // *ptr_BLEMsg_info_bp is the pointer to local copy;
+    
+    // Declaration of Date Structure
+    DateTime_info *ptr_DateTime_info_ecg, DateTime_info_ecg; // A copy of Master Structure "DateTime_info" created, 
+    ptr_DateTime_info_ecg = &DateTime_info_ecg;             // Structure pointer points to that copy.
+    
+    
+    // RTC operations
+    time_t epoch_time_ecg;           //A copy of time_t by name  epoch_time_bp is created 
+    epoch_time_ecg = rtc_read();    // time is got from get epoch function.  
+    
+    struct tm * ptr_time_info_ecg, time_info_ecg;   // Sturucture copy of tm is created
+    ptr_time_info_ecg = localtime(&epoch_time_ecg); // Structure accepts the time in local format from "time_t" type.
+      
+    //BELOW LINE IS TO CHECK Date and TIME 
+    pc.printf("Time is %d: %d: %d\n", (*ptr_time_info_ecg).tm_hour, (*ptr_time_info_ecg).tm_min, (*ptr_time_info_ecg).tm_sec);
+    pc.printf("Date is %d:%d:%d\n", (*ptr_time_info_ecg).tm_mday, (*ptr_time_info_ecg).tm_mon+1, (*ptr_time_info_ecg).tm_year-100);
+    
+    //Copying from one structure to the other using variables
+    DateTime_info_ecg.hour = (uint8_t)(*ptr_time_info_ecg).tm_hour;
+    DateTime_info_ecg.mins = (uint8_t)(*ptr_time_info_ecg).tm_min;
+    DateTime_info_ecg.sec =  (uint8_t)(*ptr_time_info_ecg).tm_sec;
+    
+    DateTime_info_ecg.date = (uint8_t) (*ptr_time_info_ecg).tm_mday;
+    DateTime_info_ecg.month =(uint8_t)(*ptr_time_info_ecg).tm_mon+1;
+    DateTime_info_ecg.year = (uint8_t)(*ptr_time_info_ecg).tm_year-100;
+    
+    // Copying Time to Main structure
+    BLEMsg_info_ecg.date_time.hour = DateTime_info_ecg.hour;
+    BLEMsg_info_ecg.date_time.mins = DateTime_info_ecg.mins;
+    BLEMsg_info_ecg.date_time.sec = DateTime_info_ecg.sec;
+    
+    BLEMsg_info_ecg.date_time.date = DateTime_info_ecg.date ;
+    BLEMsg_info_ecg.date_time.month = DateTime_info_ecg.month ;
+    BLEMsg_info_ecg.date_time.year =  DateTime_info_ecg.year ;
+    
+    
+    //Checking if the structure has these values    
+    pc.printf("Time 2 is %d:%d:%d\n", DateTime_info_ecg.hour, DateTime_info_ecg.mins, DateTime_info_ecg.sec);
+    pc.printf("\t Date is %d:%d:%d\n",DateTime_info_ecg.date, DateTime_info_ecg.month, DateTime_info_ecg.year);
+    
+    
+    //Loading values to of Test type
+    test_type_info test_type_info_ecg;  // copy of " test_type_info" created  
+    test_type_info_ecg = ECG_Test;       // Loaded value 00 to the test type 
+    
+    BLEMsg_info_ecg.test_type = test_type_info_ecg;
+    //Check if 00 is getting printed
+    pc.printf("Test Type is : %d\n", test_type_info_ecg);
+    
+    
+    // Loading values of Length ,  PID, DID, sampling frequency, number of samples, calculated data.
+    BLEMsg_info_ecg.device_id = 01;                   // Device ID fixed
+    BLEMsg_info_ecg.patient_id = (uint32_t)pid;       // Patient ID
+    BLEMsg_info_ecg.sampling_freq = 500;              // sampling frrquency
+    BLEMsg_info_ecg.length = 4026;                   //Total length of data in bytes  22 B+10752 B
+    
+    /*
+    //Loading number of samples
+    NumSamples_info NumSamples_info_bp;              //Copy of structure NumSamples_info
+    NumSamples_info_bp.num_ppg_sample = 1664;        // PPG & ECG Sample number loaded in structure copy
+    NumSamples_info_bp.num_ecg_sample = 1024;
+    */
+    
+    BLEMsg_info_ecg.num_samples.num_sample_ppg_dummy =  0 ;// PPG  number of samples copied to master struct 
+    BLEMsg_info_ecg.num_samples.num_sample_ecg_OTtyp =  1000 ; // ECG  number of samples copied to master struct
+    
+    //----------------------------------------END Structure for Bluetooth - Added Nidhin 1/6/2017-------
+
+
 
     int concatenate_value2 = 0;
+    int *ecg_ptr;                   // Added 1/6/2017 Nidhin
+    ecg_ptr = &concatenate_value2; // Pointer to pass for ECG write into SD card Nidhin 1/6/2017
+    
  //   int32_t sample_sum; // static int32_t avg[1500];
     int32_t count = 0; int32_t fs = 500; 
     uint32_t ecg_buf[N_ECG];
@@ -40,17 +121,24 @@
     setupfunc();              
     ecgsetupfunc();
  //   chk = 1;
-   sd_open_ECGfile(pid);        // opening the ecg file
+ 
+   //ORIGINAL sd_open_ECGfile(pid);        // opening the ecg file  COMMENTED Nidhin 1/6/2017
+   sd_open_ECGfilee(pid);  // REPLACED Nidhin 1/6/2017 Nidhin 
+   
   pc.printf( "Raw data is = \n"); 
  for(int i=0; i<N_ECG; i++)
    {
      concatenate_value2= readvalue();
-     sd_write(concatenate_value2);               // writing into the sd card
+     
+     //ORIGINAL sd_write(concatenate_value2); // writing into the sd card  COMMENTED Nidhin 1/6/2017
+     sd_ecgwrite(ecg_ptr); // REPLACED Nidhin 1/6/2017
+     
      ecg_buf[i] = concatenate_value2;
-     pc.printf( "%d\n", concatenate_value2);
+     //pc.printf( "%d\n", concatenate_value2); COMMENTED Nidhin 1/6/2017
    } 
-   
-   sd_close();          // closing the file
+  
+   //sd_close();          // closing the file COMMENTED Nidhin 1/6/2017
+    sd_close_ecg();          // closing the ECG file REPLACED Nidhin 1/6/2017 Nidhin
 /*   
  // ---------- reading back SD data for processing --------------------
  sd_read_file(15);
@@ -133,6 +221,19 @@
  printf("Denominator = %d\n",n);
  printf("Heart Rate = %f\n",HR_avg);
  */
+ 
+ //ADDED Nidhin 1/6/2017
+ 
+BLEMsg_info_ecg.cal_data.cal_sbp_dummy = 0;
+BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = (uint16_t)HR1;  //To be modified after HR code is added. 
+
+structure_file(ptr_BLEMsg_info_ecg, pid); //copy the ECG structure to Main file
+ecgfile_mainfile(pid);                        // copy raw data to the main file and ECG file is cleared.
+
+ pc.printf("Closed the main file\n");
+ 
+ 
+ 
   return HR1;
   // return HR_avg; 
   
--- a/main.cpp	Sat May 27 05:47:55 2017 +0000
+++ b/main.cpp	Thu Jun 01 09:24:45 2017 +0000
@@ -156,12 +156,17 @@
                 pid=pid+1;
                eprom_write(1,pid);         // writing the patient id to eeprom
                 screen_main_2(pid);
-                sd_open_GLCfilee(pid);     // only opening the glc,bp and ecg file
+                
+                sd_open_mainfile(pid);    //ADDED on 1/6/2017 - NIDHIN
+                sd_close();
+                
+                
+                /*sd_open_GLCfilee(pid);     // only opening the glc,bp and ecg file // COMMENTED Nidhin 1/6/17
                  sd_close();
                  sd_open_ECGfilee(pid);
                  sd_close();
                  sd_open_BPfilee(pid);
-                 sd_close();
+                 sd_close();*/
                  flag=1;
                  }
                else
--- a/sdcard.cpp	Sat May 27 05:47:55 2017 +0000
+++ b/sdcard.cpp	Thu Jun 01 09:24:45 2017 +0000
@@ -1,14 +1,49 @@
- /*
+ // Exisiting code in Int_Demo_09May2017_suhasini/sdcard.cpp is deleted and replaced by new code 
+ //Nidhin 1/6/2017
+ 
+ 
  #include "mbed.h"
  #include <stdio.h>
  #include "SDFileSystem.h"
  #include "sdcard.h"
   #include "rtc.h"
+  #include "struct.h"
+  
+  Serial snd(USBTX,USBRX);
   
 
   SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd");
-  FILE *fp=NULL;
-
+  
+  FILE *fpecg;  // PPG and ECG File pointers for BP
+  FILE *fpppg;  //""          ""
+  
+  FILE *fpmain; // FILE pointer for main file
+  
+  FILE *fpbg;   // FILE pointer to BG file
+  FILE *fpeecg; // FILE pointer to ECG file
+  FILE *fpbp;   // FILE pointer to BP file
+  
+  FILE *fp;    // FILE pointer for random use
+  
+  
+  
+  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;
+  
+  //Function Added on 16/5/2017 by Nidhin
+ void sd_open_mainfile(int pid)
+ {
+ char buffer1[32];
+ sprintf(buffer1,"/sd/%d.csv",pid);
+  fp = fopen(buffer1,"a"); 
+    }
+  //------------------------------------------
+  
+  
+  
  void sd_open_GLCfile(int pid)     // opening the glc file
  {
      
@@ -27,15 +62,13 @@
  
   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);
-  
+  fpbg = fopen(buffer1,"a"); 
+  fclose(fpbg);
+ } 
  
- } 
+ 
  
   void sd_open_ECGfile(int pid)         
  {
@@ -56,9 +89,9 @@
  {
      
   char buffer1[32];
-   sprintf(buffer1,"/sd/%d_ECG.csv",pid);
-  fp = fopen(buffer1,"a"); 
-  fprintf(fp,"PATIENT ID %d\n",pid );
+  sprintf(buffer1,"/sd/%d_ECG.csv",pid);
+  fpeecg = fopen(buffer1,"a"); 
+  //fclose(fpeecg);
  
  } 
  
@@ -83,122 +116,9 @@
  
   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); 
-  }
-  
-  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 );
- 
+  fpbp = fopen(buffer1,"a"); 
+  //fprintf(fp,"PATIENT ID %d\n",pid );        Not required in new code as writing in hex
+ fclose(fpbp);
  } 
   
  void sd_write (int value)      // writing data into the file
@@ -209,15 +129,15 @@
  //------------------------------------------------------
   
 //FILE *sd_BP_ecgwrite (int value)      // writing data into the file NIDHIN
-FILE *sd_BP_ecgwrite (int *fpdrum11)      // writing data into the file NIDHIN
+FILE *sd_BP_ecgwrite (uint32_t *fpdrum11)      // writing data into the file NIDHIN  
   {
-        fwrite(fpdrum11,sizeof(int),64, fpecg); 
+        fwrite(fpdrum11,sizeof(uint32_t),1, fpecg); //Change by Nidhin 30/5/2017 Direct writing to SD card. Org Val 64
         return fpecg;
   }
     
-FILE* sd_BP_ppgwrite (uint32_t *fpdrum21)      // writing data into the file NIDHIN
+FILE* sd_BP_ppgwrite (uint32_t *fpdrum21)      // //Change by Nidhin 30/5/2017 Direct writing to SD card.
   {
-       fwrite(fpdrum21,sizeof(uint32_t),64, fpppg); 
+       fwrite(fpdrum21,sizeof(uint32_t),1, fpppg); //Change by Nidhin 30/5/2017 Direct writing to SD card. OR Val 64
     return fpppg;
   }
   //-----------------------------------------------SD Read
@@ -282,13 +202,32 @@
   
   //--------------------------------------------------
   
-//void sd_bp_read(  
-  
-void sd_close()            //closing the file
+//FUNCTIONS TO CLOSE FILES
+//__________________________________________________  
+void sd_close()            //close the file with fp
   {
    
       fclose(fp);
    }
+//______________________________________________________   
+ void sd_close_ecg()          // Closes ECG file pinted by fpeecg
+ {
+   
+      fclose(fpeecg);
+ }
+//______________________________________________________
+ void sd_close_glc()          // Closes GLC file pinted by fpbg
+ {
+   
+      fclose(fpbg);
+ }
+ //_____________________________________________________
+ 
+ 
+ 
+ 
+ 
+ 
  //------------------------------------------  
  //REOPEN FUNCTIONs for reading data Nidhin
  
@@ -313,7 +252,7 @@
     {
 
     
-    fread(a,sizeof(int), 1,fpecg);
+    fread(a,sizeof(uint32_t), 1,fpecg);
     // snd.printf("\n%d", a[0]); Commented May3_2017 (Nidhin)
         if(a[0] > ecgmax)
             {
@@ -387,54 +326,198 @@
     
     char buffer3[32];
     sprintf(buffer3, "/sd/%d_BP.csv", pid);
-    fp = fopen(buffer3, "a");
+    fpbp = fopen(buffer3, "a");                   // Opens BP file with FILE pointer fpbp in APPEND mode
 
     //buffer1[32] = ""; 
-    sprintf(buffer3, "/sd/%d_BP_ECG.csv", pid);
-    fpecg = fopen(buffer3, "r");
+    sprintf(buffer3, "/sd/%d_BP_ECG.csv", pid);   
+    fpecg = fopen(buffer3, "r");                  // Opens ECG file of BP with FILE pointer fpecg in READ mode
 
     //char buffer1[32] = "";
     sprintf(buffer3, "/sd/%d_BP_PPG.csv", pid);
-    fpppg = fopen(buffer3, "r");
+    fpppg = fopen(buffer3, "r");                  // Opens PPG file of BP with FILE pointer fpppg in READ mode
 
     for(int i=0; i<16; i++)
     {
     int ecgbuf[64] = {0} ;
-    fread(ecgbuf, sizeof(int), 64, fpecg);
-    fwrite(ecgbuf, sizeof(int), 64, fp);
+    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++)
     {
     int ppgbuf[64] = {0} ;
-    fread(ppgbuf, sizeof(int), 64, fpppg);
-    fwrite(ppgbuf, sizeof(int), 64, fp);
+    fread(ppgbuf, sizeof(uint32_t), 64, fpppg);
+    fwrite(ppgbuf, sizeof(uint32_t), 64, fpbp);  // Copy PPG data of BP into BP file
     }
 
-    fclose(fpecg);
-    fclose(fpppg);
-    fclose(fp);
+    fclose(fpecg);                                  // Closes the ECG file of BP
+    fclose(fpppg);                                  // Closes the PPG file of BP
+    fclose(fpbp);                                   // Closes the BP file
 
     //char buffer1[32] = "";
-    int status = 0 ;
+    int status = 1 ;
     sprintf(buffer3, "/sd/%d_BP_ECG.csv", pid);
-    status = remove(buffer3);
+    status = remove(buffer3);                         //Removes ECG file of BP and updates status with 0 if successful
     
     
     if( status == 0 )
-        snd.printf("\nECG file delete : Successful");
+        snd.printf("\nECG file delete : Successful");   // Checks for SUCCESS
     else 
         snd.printf("\nECG file delete : UnSuccessful");
    
     
     //char buffer1[32] = "";
-    status = 0 ;
+    status = 1 ;
     sprintf(buffer3, "/sd/%d_BP_PPG.csv", pid);
-    status = remove(buffer3);
+    status = remove(buffer3);                           //Removes PPG file of BP and updates status with 0 if successful
     
     if( status == 0 )
-        snd.printf("\nPPG file delete : Successful");
+        snd.printf("\nPPG file delete : Successful");   // Checks for SUCCESS
     else 
         snd.printf("\nPPG file delete : UnSuccessful");
        
+}
+
+//Creating strcuture file Common to All Functions
+void structure_file(BLEMsg_info *ptr, int pid)
+{
+char buffer3[32];
+sprintf(buffer3, "/sd/%d.csv", pid);        //Printing file path to the buffer
+fpmain = fopen(buffer3, "a");               // open the file PID.csv with FILE pointer fpmain
+fwrite(ptr, sizeof(uint8_t),26, fpmain );   // writing the Structure into the file
+fclose(fpmain);                             // Close File
+}
+
+//Copy Data into file.
+
+void bpfile_mainfile(int pid)                       //Copy data of bp file to main
+{
+    char buffer3[32];
+    sprintf(buffer3, "/sd/%d.csv", pid);
+    fpmain = fopen(buffer3, "a");                   // Opens Main file with FILE pointer "fpmain" in APPEND mode
+    
+    sprintf(buffer3, "/sd/%d_BP.csv", pid);
+    fpbp = fopen(buffer3, "r");                     // Opens BP file with FILE pointer "fpbp" in READ mode
+    
+    
+    for(int i=0; i<21; i++)
+    {
+    int 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
+}
+
+//------------New function added to print ECG data to Sd card using fwrite
+void sd_ecgwrite(int *ecg_ptr)
+{
+   fwrite(ecg_ptr, sizeof(int), 1, fpeecg); 
+}
+
+
+//------------ Function to write ECG data to main file
+void ecgfile_mainfile(int pid)
+{
+    char buffer3[32];
+    sprintf(buffer3, "/sd/%d.csv", pid);       
+    fpmain = fopen(buffer3, "a");             // Main File is opened in Append mode
+    
+    sprintf(buffer3, "/sd/%d_ECG.csv", pid);  // ECG file is opened in read mode
+    fpeecg = fopen(buffer3, "r");
+    
+    for(int i=0; i<10; i++)
+    {
+    int bigbuf[100] = {0} ;
+    fread(bigbuf, sizeof(int),100 , fpeecg);
+    fwrite(bigbuf, sizeof(int), 100, fpmain);
+    }
+    fclose(fpeecg);                               // Both files are Closed
+    fclose(fpmain);
+    
+    /*
+    sprintf(buffer3, "/sd/%d_ECG.csv", pid);  // ECG file is opened in write mode to empty the file
+    fpeecg = fopen(buffer3, "w");
+    fclose(fpecg);  
+    */                           // File is closed
+    int success;
+    sprintf(buffer3, "/sd/%d_ECG.csv", pid);
+    success = remove(buffer3);  
+}
+
+
+//---------------------- Function to write GLC data to GLC file
+void sd_glcwrite(uint32_t *glc_ptr, int pid)
+{
+    char buffer3[32];
+    sprintf(buffer3, "/sd/%d_GLC.csv", pid);       
+    fpbg = fopen(buffer3, "a");  
+    
+    fwrite(glc_ptr, sizeof(uint32_t), 2, fpbg);
+    fclose(fpbg);
+   
+}
+
+// --------------------------Fuinction to write GLC data to Main file
+
+void glcfile_mainfile(int pid)
+{
+    char buffer3[32];
+    sprintf(buffer3, "/sd/%d.csv", pid);       
+    fpmain = fopen(buffer3, "a");             // Main File is opened in Append mode
+    
+    sprintf(buffer3, "/sd/%d_GLC.csv", pid);  // BG file is opened in read mode
+    fpbg = fopen(buffer3, "r");
+    
+    for(int i=0; i<2; i++)
+    {
+    int bigbuf[2] = {0} ;
+    fread(bigbuf, sizeof(int),2 , fpbg);      
+    fwrite(bigbuf, sizeof(int), 2, fpmain);
+    }
+    fclose(fpbg);                               // Both files are Closed
+    fclose(fpmain);
+    
+    int success;
+    sprintf(buffer3, "/sd/%d_GLC.csv", pid);  
+    success = remove(buffer3);                           // GLC file is deleted
+}
+
+
+void delete_subfiles(int pid)
+{
+    char buffer3[32];  
+    int success1 , success2, success3;
+    success1 = 1 ;
+    sprintf(buffer3, "/sd/%d_BP.csv", pid);
+    success1 = remove(buffer3);                           //Removes PPG file of BP and updates status with 0 if successful
+    
+    if( success1 == 0 )
+        snd.printf("\nBP file delete : Successful");   // Checks for SUCCESS
+    else 
+        snd.printf("\nBP file delete : UnSuccessful");
+
+    success2 = 1 ;
+    sprintf(buffer3, "/sd/%d_GLC.csv", pid);
+    success2 = remove(buffer3);                           //Removes GLC file and updates status with 0 if successful
+    
+    if( success2 == 0 )
+        snd.printf("\nGLC file delete : Successful");   // Checks for SUCCESS
+    else 
+        snd.printf("\nGLC file delete : UnSuccessful");
+
+    success3 = 1 ;
+    sprintf(buffer3, "/sd/%d_ECG.csv", pid);
+    success3 = remove(buffer3);                           //Removes ECG file and updates status with 0 if successful
+    
+    if( success3 == 0 )
+        snd.printf("\nECG file delete : Successful");   // Checks for SUCCESS
+    else 
+        snd.printf("\nECG file delete : UnSuccessful");
+
 }
\ No newline at end of file
--- a/sdcard.h	Sat May 27 05:47:55 2017 +0000
+++ b/sdcard.h	Thu Jun 01 09:24:45 2017 +0000
@@ -1,22 +1,10 @@
-/*
+// Exisiting code in Int_Demo_09May2017_suhasini/sdcard.h is deleted and replaced by new code 
+ //Nidhin 1/6/2017
+ 
 #ifndef SDCARD_H_
 #define SDCARD_H_
 
-void sd_open_ECGfile(int pid);
-void sd_open_ECGfilee(int pid);
-void sd_open_GLCfile(int pid);
-void sd_open_GLCfilee(int pid);
-void sd_open_BPfilee(int pid);
-void sd_open_BPfile(int pid);
-void sd_write (int value);
-void sd_close();
-
-#endif
-*/
-
-//-----------------------------------------------new ADD NIDHIN 28/4/2017-----------------
-#ifndef SDCARD_H_
-#define SDCARD_H_
+#include "struct.h"
 
 void sd_open_ECGfile(int pid);
 void sd_open_ECGfilee(int pid);
@@ -29,13 +17,15 @@
 //void sd_BP_ppgwrite (uint32_t value);
 //void sd_BP_ecgwrite (int value);
 
-FILE *sd_BP_ecgwrite (int *fpdrum11);
+FILE *sd_BP_ecgwrite (uint32_t *fpdrum11);
 FILE *sd_BP_ppgwrite (uint32_t *fpdrum21);
  
 void sd_open_BP_ECGfile(int pid); //added to write ECG to seperate file BP
 void sd_open_BP_PPGfile(int pid); //added to write PPG to seperate file BP
 
-void sd_close();
+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
 
 int sd_BP_ECGMAX(int pid);
 int sd_BP_PPGMAX(int pid);
@@ -43,6 +33,19 @@
 
 void create_single_BPfile(int pid); //Function to create 1 file from 2 temp BP file (ECG &PPG)
 
-#endif 
+void sd_open_mainfile(int pid); // Function for oprning main file
+//----------------- For testing
+void structure_file(BLEMsg_info *ptr, int pid); // Writes structure to the File.
+
+void bpfile_mainfile(int pid);
 
-//----------------------------------------------------28/4/2017------------------------ 
\ No newline at end of file
+void sd_ecgwrite(int *ecg_ptr);  //to print ECG data in ECG func as binary using fwrite.   NIDHIN 25 May 2017
+void ecgfile_mainfile(int pid); 
+
+void sd_glcwrite(uint32_t *glc_ptr, int pid);  // GLC raw data to GLC file
+void glcfile_mainfile(int pid);  // GLC file to main file
+
+void delete_subfiles(int pid);  //deletes all subfiles under a pid
+
+
+#endif 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/struct.h	Thu Jun 01 09:24:45 2017 +0000
@@ -0,0 +1,47 @@
+#ifndef STRUCT_H_
+#define STRUCT_H_
+
+#include "bp.h"
+#include "glc.h"
+#include "ecg_dec.h"
+#include "test_type.h"
+
+
+typedef struct __attribute__((__packed__))
+{
+    uint8_t               date;
+    uint8_t               month;
+    uint8_t               year;
+    uint8_t               hour;
+    uint8_t               mins;
+    uint8_t               sec;
+}DateTime_info;
+
+typedef struct __attribute__((__packed__))
+{
+    uint16_t             num_sample_ppg_dummy;
+    uint16_t             num_sample_ecg_OTtyp;
+}NumSamples_info;
+
+
+typedef struct __attribute__((__packed__))
+{
+    uint16_t             cal_sbp_dummy;
+    uint16_t             cal_dbp_OTtyp;
+}CalData_info;
+
+
+
+typedef struct __attribute__((__packed__))
+{
+  uint32_t               length;
+  uint8_t                device_id;
+  uint32_t              patient_id;
+  DateTime_info         date_time;
+  test_type_info        test_type;
+  uint16_t               sampling_freq;
+  NumSamples_info       num_samples;
+  CalData_info          cal_data;
+}BLEMsg_info;
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_type.h	Thu Jun 01 09:24:45 2017 +0000
@@ -0,0 +1,10 @@
+#ifndef TEST_TYPE_H_
+#define TEST_TYPE_H_
+typedef enum
+{ 
+    BP_Test =   (uint8_t )0x00,   // removed Semi Colon and replaced with comma
+    BG_Test ,
+    ECG_Test, 
+}test_type_info;
+
+#endif
\ No newline at end of file