
Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Revision 8:adf2ba7e6412, committed 2017-04-28
- Comitter:
- nidhinvarghese
- Date:
- Fri Apr 28 10:05:29 2017 +0000
- Parent:
- 7:11f926351d8f
- Child:
- 9:d0ecb61d219e
- Commit message:
- New Display code(Nik) updated with New BP code (Nid); Changes in Main.cpp, sdcard.cpp, sdcard.h, bp.cpp, bp.h; Code working without hang. ; BP result screen need modification.
Changed in this revision
--- a/bp.cpp Wed Apr 26 10:14:53 2017 +0000 +++ b/bp.cpp Fri Apr 28 10:05:29 2017 +0000 @@ -1,3 +1,4 @@ + //BP Optimised Program for Averaging the received value from PPG and ECG & Check for SD card Storage// @@ -5,7 +6,8 @@ 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> @@ -177,7 +179,7 @@ bc.printf( "DBP = %f\n", DBP); screen_bp1(SBP,DBP); - +*/ //-----------------WRITE ECG &PPG /* @@ -202,4 +204,157 @@ - } // End of main function + //} // 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" + +using namespace std; + +Serial bc(USBTX,USBRX); +DigitalIn INTR(PTC7); + +Timer t; + +//FILE *ecg; +//FILE *ppg; + +void bp(int pid) { + uint8_t uch_dummy; + uint32_t ppgdata; + + //int dummyconcat = 700000; + int concatenate_value2 = 0; + unsigned char chk = 1; + + int drum11[64]; + uint32_t drum21[64]; + + // Variables for file operations + // uint32_t amax=0; + //uint32_t bmax = 0; + //uint32_t a; + //uint32_t b; + + //int aloc = 0; + //int bloc = 0; + //int samples = 0; + + bc.baud(baud_rate); + + freqset(); // setting the frequency + setupfunc(); + ecgsetupfunc(); + + maxim_max30102_reset(); // PPG reset + wait_ms(20); + maxim_max30102_init(); + + chk = 1; + + wait(2); + //bc.printf("BP start\n"); + + for(int i=0; i<500; i++) + { + + concatenate_value2= readvalue(); + + maxim_max30102_read_reg(0,&uch_dummy); + while(INTR.read()==1); + maxim_max30102_read_fifo(&ppgdata); + + } + + + 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_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 i=0; i<64; i++) + { + concatenate_value2 = readvalue(); + drum11[i]=concatenate_value2; //drum11[i]=concatenate_value2; drum11[i]=dummyconcat; + + maxim_max30102_read_reg(0,&uch_dummy); + while(INTR.read()==1); + maxim_max30102_read_fifo(&ppgdata); + drum21[i]=ppgdata; + } + + ecg = sd_BP_ecgwrite(drum_ecg); // + ppg = sd_BP_ppgwrite(drum_ppg); + + + } + + for(int j =0 ; j<10; j++) // changed to 16 from 8 + { + for(int i=0; i<64; i++) + { + maxim_max30102_read_reg(0,&uch_dummy); + while(INTR.read()==1); + maxim_max30102_read_fifo(&ppgdata); + drum21[i]=ppgdata; + } + + ppg = sd_BP_ppgwrite (drum_ppg); + + } + fclose(ecg); + fclose(ppg); + + maxim_max30102_reset(); + + //-----Reading from file starts // + + //std::ifstream ec1("/sd/123_BP_ECG.csv"); + //std::ifstream pp1("/sd/123_BP_PPG.csv"); + + int eloc = 0; + int ploc = 0; + + + eloc = sd_BP_ECGMAX(pid); // eloc = sd_BP_ECGMAX(123); + ploc = sd_BP_PPGMAX(pid); // ploc = sd_BP_PPGMAX(123); + + //bc.printf("The ECG max is at : %d", eloc); + //bc.printf("The PPG Max is at : %d", ploc); + + float PWV = 0; + int d = 210000; + int delta_t = 0; + float SBP = 0; + float DBP = 0; + + delta_t = (2*(ploc - eloc)); + PWV = d/delta_t; + + SBP = 0.0508955*PWV+62.559; + DBP = (0.0494*PWV + 17.480)+10; + + screen_bp1(SBP,DBP); + + } \ No newline at end of file
--- a/bp.h Wed Apr 26 10:14:53 2017 +0000 +++ b/bp.h Fri Apr 28 10:05:29 2017 +0000 @@ -1,8 +1,19 @@ +/* #ifndef BP_H_ #define BP_H_ void bp(); #endif +*/ + +//-------------------------------NEW BP Nidhin Add 28/4/2017-------------------- + +#ifndef BP_H_ +#define BP_H_ +void bp(int pid); +#endif + +//--------------------------------------------28/4/2017---------------------------
--- a/main.cpp Wed Apr 26 10:14:53 2017 +0000 +++ b/main.cpp Fri Apr 28 10:05:29 2017 +0000 @@ -264,7 +264,7 @@ DisableTouch(); screen_bp2(); // bp main screen bp_countdown(); // countdown for bp - bp(); // measuring bp + bp(pid); // measuring bp earlier bp() changed to bp(pid) 28/4/2017 state1=0; // wait(1); state=6;
--- 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
--- a/sdcard.h Wed Apr 26 10:14:53 2017 +0000 +++ b/sdcard.h Fri Apr 28 10:05:29 2017 +0000 @@ -1,3 +1,4 @@ +/* #ifndef SDCARD_H_ #define SDCARD_H_ @@ -10,4 +11,36 @@ void sd_write (int value); void sd_close(); -#endif \ No newline at end of file +#endif +*/ + +//-----------------------------------------------new ADD NIDHIN 28/4/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_BP_ppgwrite (uint32_t value); +//void sd_BP_ecgwrite (int value); + +FILE *sd_BP_ecgwrite (int *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(); + +int sd_BP_ECGMAX(int pid); +int sd_BP_PPGMAX(int pid); +//void sd_close1(); + +#endif + +//----------------------------------------------------28/4/2017------------------------ \ No newline at end of file