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

Committer:
rashmivenkataramaiah
Date:
Mon Sep 11 13:09:29 2017 +0000
Revision:
43:85a7f399cb9d
Parent:
42:c81673b04b6a
PID tracking with get and inc file pid and bt pid

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nidhinvarghese 14:f5c62d30c6fc 1 //-----------------------------------------------NEW BP code starts--------------------------------///
nikitateggi 3:9a06c2bed650 2
nikitateggi 3:9a06c2bed650 3
nidhinvarghese 8:adf2ba7e6412 4
nikitateggi 3:9a06c2bed650 5 #include "mbed.h"
nikitateggi 3:9a06c2bed650 6 #include "MAX30102.h" // BP ADD
nikitateggi 3:9a06c2bed650 7 #include <string.h>
nikitateggi 3:9a06c2bed650 8 #include <stdio.h>
nikitateggi 39:69b09bd87502 9 #include "eeprom_pgm.h"
nidhinvarghese 14:f5c62d30c6fc 10 #include <time.h>
nikitateggi 3:9a06c2bed650 11 #include "ds3231.h"
nikitateggi 3:9a06c2bed650 12 #include "SDFileSystem.h"
nikitateggi 3:9a06c2bed650 13 #include "rtc.h"
nikitateggi 3:9a06c2bed650 14 #include "sdcard.h"
nikitateggi 3:9a06c2bed650 15 #include "ec_bp.h"
nikitateggi 3:9a06c2bed650 16 #include "bp.h"
nikitateggi 3:9a06c2bed650 17 #include "display_modules.h"
rashmivenkataramaiah 43:85a7f399cb9d 18 #include "main.h"
nikitateggi 3:9a06c2bed650 19
rashmivenkataramaiah 41:1141a75eacc4 20
avp2417 40:f7f351699288 21 #define MAX_SBP_THRESHOLD 300
avp2417 40:f7f351699288 22 #define MAX_DBP_THRESHOLD 300
avp2417 40:f7f351699288 23 #define MIN_SBP_THRESHOLD 40
avp2417 40:f7f351699288 24 #define MIN_DBP_THRESHOLD 40
avp2417 40:f7f351699288 25
avp2417 40:f7f351699288 26
avp2417 36:00d96aa14658 27 FILE *fpecg_bp; // file pointer in place of fpecg- Suhasini- 21/7/17
avp2417 36:00d96aa14658 28 FILE *fpppg1;
nikitateggi 3:9a06c2bed650 29
nidhinvarghese 14:f5c62d30c6fc 30 #include "struct.h"
nidhinvarghese 8:adf2ba7e6412 31
nidhinvarghese 8:adf2ba7e6412 32 using namespace std;
nidhinvarghese 8:adf2ba7e6412 33
nidhinvarghese 14:f5c62d30c6fc 34 Serial bpr(USBTX,USBRX);
nidhinvarghese 8:adf2ba7e6412 35 DigitalIn INTR(PTC7);
nidhinvarghese 8:adf2ba7e6412 36
nidhinvarghese 8:adf2ba7e6412 37 Timer t;
nidhinvarghese 8:adf2ba7e6412 38
nidhinvarghese 14:f5c62d30c6fc 39
avp2417 36:00d96aa14658 40 uint16_t ecgloc = 0; // PPG and eCG maximum locations //int to uint16_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 41 uint16_t ppgloc = 0; //int to uint16_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 42 uint16_t ebp = 0; // variable for LOOP operation to read value from File i == ECG , j == PPG
avp2417 36:00d96aa14658 43 uint16_t pbp = 0; //int to uint16_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 44
rashmivenkataramaiah 43:85a7f399cb9d 45 void bp(uint32_t pid) {
nidhinvarghese 14:f5c62d30c6fc 46
nidhinvarghese 8:adf2ba7e6412 47 uint8_t uch_dummy;
nidhinvarghese 8:adf2ba7e6412 48 uint32_t ppgdata;
nikitateggi 20:7c64e6ecad76 49 uint8_t lead_reg=0;
avp2417 36:00d96aa14658 50 uint32_t concatenate_value2 = 0; //int to uint32_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 51 uint8_t chk = 1; //unsigned char to uint8_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 52
nidhinvarghese 14:f5c62d30c6fc 53 //Declaration of Master structure
nidhinvarghese 14:f5c62d30c6fc 54
nidhinvarghese 14:f5c62d30c6fc 55 BLEMsg_info *ptr_BLEMsg_info_bp, BLEMsg_info_bp; // A copy of master strcuture [ "BLEMsg_info" ] by name "BLEMsg_info_bp" is created
nidhinvarghese 14:f5c62d30c6fc 56 ptr_BLEMsg_info_bp = &BLEMsg_info_bp; // *ptr_BLEMsg_info_bp is the pointer to local copy;
nidhinvarghese 14:f5c62d30c6fc 57
nidhinvarghese 14:f5c62d30c6fc 58 // Declaration of Date Structure
nidhinvarghese 14:f5c62d30c6fc 59 DateTime_info *ptr_DateTime_info_bp, DateTime_info_bp; // A copy of Master Structure "DateTime_info" created,
nidhinvarghese 14:f5c62d30c6fc 60 ptr_DateTime_info_bp = &DateTime_info_bp; // Structure pointer points to that copy.
nidhinvarghese 14:f5c62d30c6fc 61
nidhinvarghese 14:f5c62d30c6fc 62
nidhinvarghese 14:f5c62d30c6fc 63 // RTC operations
nidhinvarghese 14:f5c62d30c6fc 64 time_t epoch_time_bp; //A copy of time_t by name epoch_time_bp is created
nidhinvarghese 14:f5c62d30c6fc 65 epoch_time_bp = rtc_read(); // time is got from get epoch function.
nidhinvarghese 14:f5c62d30c6fc 66
nidhinvarghese 14:f5c62d30c6fc 67 struct tm * ptr_time_info_bp, time_info_bp; // Sturucture copy of tm is created
nidhinvarghese 14:f5c62d30c6fc 68 ptr_time_info_bp = localtime(&epoch_time_bp); // Structure accepts the time in local format from "time_t" type.
nidhinvarghese 14:f5c62d30c6fc 69
nidhinvarghese 14:f5c62d30c6fc 70 //BELOW LINE IS TO CHECK Date and TIME
nidhinvarghese 14:f5c62d30c6fc 71 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);
nidhinvarghese 14:f5c62d30c6fc 72 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);
nidhinvarghese 14:f5c62d30c6fc 73
nidhinvarghese 14:f5c62d30c6fc 74 //Copying from one structure to the other using variables
nidhinvarghese 14:f5c62d30c6fc 75 DateTime_info_bp.hour = (uint8_t)(*ptr_time_info_bp).tm_hour;
nidhinvarghese 14:f5c62d30c6fc 76 DateTime_info_bp.mins = (uint8_t)(*ptr_time_info_bp).tm_min;
nidhinvarghese 14:f5c62d30c6fc 77 DateTime_info_bp.sec = (uint8_t)(*ptr_time_info_bp).tm_sec;
nidhinvarghese 14:f5c62d30c6fc 78
nidhinvarghese 14:f5c62d30c6fc 79 DateTime_info_bp.date = (uint8_t) (*ptr_time_info_bp).tm_mday;
nidhinvarghese 14:f5c62d30c6fc 80 DateTime_info_bp.month =(uint8_t)(*ptr_time_info_bp).tm_mon+1;
nidhinvarghese 14:f5c62d30c6fc 81 DateTime_info_bp.year = (uint8_t)(*ptr_time_info_bp).tm_year-100;
nidhinvarghese 14:f5c62d30c6fc 82
nidhinvarghese 14:f5c62d30c6fc 83 // Copying Time to Main structure
nidhinvarghese 14:f5c62d30c6fc 84 BLEMsg_info_bp.date_time.hour = DateTime_info_bp.hour;
nidhinvarghese 14:f5c62d30c6fc 85 BLEMsg_info_bp.date_time.mins = DateTime_info_bp.mins;
nidhinvarghese 14:f5c62d30c6fc 86 BLEMsg_info_bp.date_time.sec = DateTime_info_bp.sec;
nidhinvarghese 14:f5c62d30c6fc 87
nidhinvarghese 14:f5c62d30c6fc 88 BLEMsg_info_bp.date_time.date = DateTime_info_bp.date ;
nidhinvarghese 14:f5c62d30c6fc 89 BLEMsg_info_bp.date_time.month = DateTime_info_bp.month ;
nidhinvarghese 14:f5c62d30c6fc 90 BLEMsg_info_bp.date_time.year = DateTime_info_bp.year ;
nidhinvarghese 14:f5c62d30c6fc 91
nidhinvarghese 14:f5c62d30c6fc 92
nidhinvarghese 14:f5c62d30c6fc 93 //Checking if the structure has these values
nidhinvarghese 14:f5c62d30c6fc 94 bpr.printf("Time 2 is %d:%d:%d\n", DateTime_info_bp.hour, DateTime_info_bp.mins, DateTime_info_bp.sec);
nidhinvarghese 14:f5c62d30c6fc 95 bpr.printf("\t Date is %d:%d:%d\n",DateTime_info_bp.date, DateTime_info_bp.month, DateTime_info_bp.year);
nidhinvarghese 14:f5c62d30c6fc 96
nidhinvarghese 14:f5c62d30c6fc 97
nidhinvarghese 14:f5c62d30c6fc 98 //Loading values to of Test type
nidhinvarghese 14:f5c62d30c6fc 99 test_type_info test_type_info_bp; // copy of " test_type_info" created
nidhinvarghese 14:f5c62d30c6fc 100 test_type_info_bp = BP_Test; // Loaded value 00 to the test type
nidhinvarghese 14:f5c62d30c6fc 101
nidhinvarghese 14:f5c62d30c6fc 102 BLEMsg_info_bp.test_type = test_type_info_bp;
nidhinvarghese 14:f5c62d30c6fc 103 //Check if 00 is getting printed
nidhinvarghese 14:f5c62d30c6fc 104 bpr.printf("Test Type is : %d\n", test_type_info_bp);
nidhinvarghese 14:f5c62d30c6fc 105
nidhinvarghese 14:f5c62d30c6fc 106
nidhinvarghese 14:f5c62d30c6fc 107 // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data.
nikitateggi 39:69b09bd87502 108 BLEMsg_info_bp.device_id = eprom_read_8(12); // Device ID fixed // changed on 11/8/17 nikita
nidhinvarghese 14:f5c62d30c6fc 109 BLEMsg_info_bp.patient_id = (uint32_t)pid; // Patient ID
nidhinvarghese 14:f5c62d30c6fc 110 BLEMsg_info_bp.sampling_freq = 500; // sampling frrquency
nidhinvarghese 14:f5c62d30c6fc 111 BLEMsg_info_bp.length = 10774; //Total length of data in bytes 22 B+10752 B
nidhinvarghese 14:f5c62d30c6fc 112
nidhinvarghese 14:f5c62d30c6fc 113 BLEMsg_info_bp.num_samples.num_sample_ppg_dummy = 1664 ;// PPG number of samples copied to master struct
nidhinvarghese 14:f5c62d30c6fc 114 BLEMsg_info_bp.num_samples.num_sample_ecg_OTtyp = 1024 ; // ECG number of samples copied to master struct
nidhinvarghese 14:f5c62d30c6fc 115
nidhinvarghese 14:f5c62d30c6fc 116 bpr.baud(baud_rate);
nidhinvarghese 8:adf2ba7e6412 117
nidhinvarghese 8:adf2ba7e6412 118 freqset(); // setting the frequency
nidhinvarghese 8:adf2ba7e6412 119 setupfunc();
nikitateggi 20:7c64e6ecad76 120 lead_reg=ecgsetupfunc(); // lead contact // 14/06
nidhinvarghese 8:adf2ba7e6412 121
nidhinvarghese 8:adf2ba7e6412 122 maxim_max30102_reset(); // PPG reset
nidhinvarghese 8:adf2ba7e6412 123 wait_ms(20);
nidhinvarghese 8:adf2ba7e6412 124 maxim_max30102_init();
nidhinvarghese 8:adf2ba7e6412 125
nidhinvarghese 8:adf2ba7e6412 126 chk = 1;
nidhinvarghese 8:adf2ba7e6412 127 wait(2);
avp2417 36:00d96aa14658 128
avp2417 36:00d96aa14658 129 for(uint16_t i=0; i<500; i++)
nidhinvarghese 8:adf2ba7e6412 130 {
nidhinvarghese 8:adf2ba7e6412 131 concatenate_value2= readvalue();
nidhinvarghese 8:adf2ba7e6412 132
nidhinvarghese 8:adf2ba7e6412 133 maxim_max30102_read_reg(0,&uch_dummy);
nidhinvarghese 8:adf2ba7e6412 134 while(INTR.read()==1);
nidhinvarghese 8:adf2ba7e6412 135 maxim_max30102_read_fifo(&ppgdata);
nidhinvarghese 8:adf2ba7e6412 136
nidhinvarghese 8:adf2ba7e6412 137 }
nikitateggi 20:7c64e6ecad76 138 // BP Finger detect Function Added Nidhin 16/6/17
nikitateggi 20:7c64e6ecad76 139 // START
nikitateggi 20:7c64e6ecad76 140 uint32_t un_max, un_min; // Declare two VARIABLE FOR MAX AND MIN
nikitateggi 20:7c64e6ecad76 141 un_max = 0;
nikitateggi 20:7c64e6ecad76 142 un_min = 0x3FFF;
nikitateggi 20:7c64e6ecad76 143
avp2417 36:00d96aa14658 144 for(uint16_t i=0; i<500; i++) // READS 500 SAMPLES TO SEE MAX AND MIN VAL DIFFERENCE
nikitateggi 20:7c64e6ecad76 145 {
nikitateggi 20:7c64e6ecad76 146 maxim_max30102_read_reg(0,&uch_dummy);
nikitateggi 20:7c64e6ecad76 147 while(INTR.read()==1);
nikitateggi 20:7c64e6ecad76 148 maxim_max30102_read_fifo(&ppgdata);
nikitateggi 21:7ef1b0b40841 149 bpr.printf("%d\n",ppgdata);
nikitateggi 20:7c64e6ecad76 150 if(un_min>ppgdata)
nikitateggi 20:7c64e6ecad76 151 un_min=ppgdata; //update signal min
nikitateggi 20:7c64e6ecad76 152 if(un_max<ppgdata)
nikitateggi 20:7c64e6ecad76 153 un_max=ppgdata;
nikitateggi 20:7c64e6ecad76 154 }
nikitateggi 20:7c64e6ecad76 155
nikitateggi 21:7ef1b0b40841 156 bpr.printf("The max is %d\n", un_max); //
nikitateggi 21:7ef1b0b40841 157 bpr.printf("The min is %d\n", un_min);
nikitateggi 20:7c64e6ecad76 158 if (((un_max -un_min) > 300) && (lead_reg==0)) // Checking for threshold 300 Added Nidhin 16/6/17
nikitateggi 20:7c64e6ecad76 159
nikitateggi 20:7c64e6ecad76 160 { //Added Nidhin 16/6/17
nidhinvarghese 8:adf2ba7e6412 161
nidhinvarghese 14:f5c62d30c6fc 162 sd_open_BPfilee(pid);
nidhinvarghese 8:adf2ba7e6412 163 sd_open_BP_ECGfile(pid) ; // sd_open_BP_ECGfile(123) draft file for testing
nidhinvarghese 8:adf2ba7e6412 164 sd_open_BP_PPGfile(pid) ; // sd_open_BP_PPGfile(123) draft file for testing
nidhinvarghese 8:adf2ba7e6412 165
nidhinvarghese 8:adf2ba7e6412 166 FILE *ecg = NULL;
nidhinvarghese 8:adf2ba7e6412 167 FILE *ppg = NULL;
nidhinvarghese 8:adf2ba7e6412 168
avp2417 36:00d96aa14658 169 for(uint16_t i=0; i<1024; i++) //int to uint16_t-Suhasini-21stJuly2017
nidhinvarghese 8:adf2ba7e6412 170 {
nidhinvarghese 8:adf2ba7e6412 171 concatenate_value2 = readvalue();
nidhinvarghese 15:208b146151ba 172 ecg = sd_BP_ecgwrite(&concatenate_value2);
nidhinvarghese 14:f5c62d30c6fc 173
nidhinvarghese 8:adf2ba7e6412 174 maxim_max30102_read_reg(0,&uch_dummy);
nidhinvarghese 8:adf2ba7e6412 175 while(INTR.read()==1);
nidhinvarghese 8:adf2ba7e6412 176 maxim_max30102_read_fifo(&ppgdata);
nidhinvarghese 14:f5c62d30c6fc 177 ppg = sd_BP_ppgwrite(&ppgdata); //Change by Nidhin 30/5/2017 Direct writing to SD card.
avp2417 36:00d96aa14658 178 }
avp2417 36:00d96aa14658 179
avp2417 36:00d96aa14658 180 for(uint16_t i=0; i<640; i++) //int to uint16_t-Suhasini-21stJuly2017
nidhinvarghese 8:adf2ba7e6412 181 {
nidhinvarghese 8:adf2ba7e6412 182 maxim_max30102_read_reg(0,&uch_dummy);
nidhinvarghese 8:adf2ba7e6412 183 while(INTR.read()==1);
nidhinvarghese 8:adf2ba7e6412 184 maxim_max30102_read_fifo(&ppgdata);
nidhinvarghese 14:f5c62d30c6fc 185 ppg = sd_BP_ppgwrite (&ppgdata); //Change by Nidhin 30/5/2017 Direct writing to SD card.
nidhinvarghese 8:adf2ba7e6412 186 }
nidhinvarghese 8:adf2ba7e6412 187
nidhinvarghese 8:adf2ba7e6412 188 fclose(ecg);
nidhinvarghese 8:adf2ba7e6412 189 fclose(ppg);
nidhinvarghese 8:adf2ba7e6412 190
nidhinvarghese 8:adf2ba7e6412 191 maxim_max30102_reset();
nidhinvarghese 8:adf2ba7e6412 192
avp2417 36:00d96aa14658 193 uint16_t eloc = 0; //int to uint16_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 194 uint16_t ploc = 0; //int to uint16_t-Suhasini-21stJuly2017
nidhinvarghese 8:adf2ba7e6412 195
nidhinvarghese 8:adf2ba7e6412 196
nidhinvarghese 8:adf2ba7e6412 197 eloc = sd_BP_ECGMAX(pid); // eloc = sd_BP_ECGMAX(123);
nidhinvarghese 8:adf2ba7e6412 198 ploc = sd_BP_PPGMAX(pid); // ploc = sd_BP_PPGMAX(123);
avp2417 36:00d96aa14658 199 bpr.printf("eloc: %d ploc: %d\n",eloc,ploc);
nidhinvarghese 8:adf2ba7e6412 200
nidhinvarghese 8:adf2ba7e6412 201 float PWV = 0;
avp2417 36:00d96aa14658 202 uint32_t d = 210000; //int to uint32_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 203 uint16_t delta_t = 0; //int to uint16_t-Suhasini-21stJuly2017
nidhinvarghese 8:adf2ba7e6412 204 float SBP = 0;
nidhinvarghese 8:adf2ba7e6412 205 float DBP = 0;
nidhinvarghese 8:adf2ba7e6412 206
nidhinvarghese 8:adf2ba7e6412 207 delta_t = (2*(ploc - eloc));
nidhinvarghese 8:adf2ba7e6412 208 PWV = d/delta_t;
nidhinvarghese 8:adf2ba7e6412 209
nidhinvarghese 8:adf2ba7e6412 210 SBP = 0.0508955*PWV+62.559;
nidhinvarghese 8:adf2ba7e6412 211 DBP = (0.0494*PWV + 17.480)+10;
avp2417 36:00d96aa14658 212 bpr.printf("sbp: %.0f dbp: %.0f\n",SBP,DBP);
nidhinvarghese 14:f5c62d30c6fc 213
nidhinvarghese 14:f5c62d30c6fc 214 BLEMsg_info_bp.cal_data.cal_sbp_dummy = (uint16_t) SBP;
nidhinvarghese 14:f5c62d30c6fc 215 BLEMsg_info_bp.cal_data.cal_dbp_OTtyp = (uint16_t) DBP;
nidhinvarghese 14:f5c62d30c6fc 216
avp2417 40:f7f351699288 217 if((SBP > MAX_SBP_THRESHOLD || SBP < MIN_SBP_THRESHOLD) && (DBP > MAX_DBP_THRESHOLD || DBP < MIN_SBP_THRESHOLD)) // checking for range below and above and then displaying error
avp2417 36:00d96aa14658 218 {
nikitateggi 31:0f67acfc6236 219 screen_bp_error(); // checking for error out of range- nikita 10-7-17
avp2417 36:00d96aa14658 220 del_ppg_ecg_BPfile(pid); // Copy ECG and PPG data to BP file
nikitateggi 39:69b09bd87502 221 delete_subfiles(pid); //added on 11/8/17 nikita
avp2417 36:00d96aa14658 222 }
nidhinvarghese 14:f5c62d30c6fc 223
nikitateggi 31:0f67acfc6236 224 else
nikitateggi 31:0f67acfc6236 225 {
nikitateggi 31:0f67acfc6236 226 create_single_BPfile(pid); // Copy ECG and PPG data to BP file
nikitateggi 31:0f67acfc6236 227 structure_file(ptr_BLEMsg_info_bp, pid); // Copy BP structure to main file
avp2417 36:00d96aa14658 228 bpfile_mainfile(pid);
avp2417 36:00d96aa14658 229 screen_bp1(SBP,DBP);
rashmivenkataramaiah 43:85a7f399cb9d 230 if(get_filecreated_status() == false) //if file is in write mode
rashmivenkataramaiah 43:85a7f399cb9d 231 {
rashmivenkataramaiah 43:85a7f399cb9d 232 set_filecreated_status();
rashmivenkataramaiah 43:85a7f399cb9d 233 increment_filepid ();
rashmivenkataramaiah 43:85a7f399cb9d 234 }
rashmivenkataramaiah 43:85a7f399cb9d 235 }
nikitateggi 20:7c64e6ecad76 236 } //Added Nidhin 16/6/17
nikitateggi 20:7c64e6ecad76 237
nikitateggi 20:7c64e6ecad76 238 else //Added Nidhin 16/6/17
nikitateggi 20:7c64e6ecad76 239 { //Added Nidhin 16/6/17
nikitateggi 20:7c64e6ecad76 240 // Add display sequence for Finger detect fail //Added Nidhin 16/6/17
nikitateggi 20:7c64e6ecad76 241 maxim_max30102_reset();
nikitateggi 20:7c64e6ecad76 242 bpr.printf("no finger detect\n");
nikitateggi 20:7c64e6ecad76 243 screen_ecg_lead_bp_fingerdetect();
nikitateggi 20:7c64e6ecad76 244 } //Added Nidhin 16/6/17
nikitateggi 20:7c64e6ecad76 245 screen_ecg_bp() ;
avp2417 36:00d96aa14658 246 }
avp2417 36:00d96aa14658 247
avp2417 36:00d96aa14658 248
avp2417 36:00d96aa14658 249 //------------------------------------------
avp2417 36:00d96aa14658 250 //REOPEN FUNCTIONs for reading data Nidhin
avp2417 36:00d96aa14658 251
avp2417 36:00d96aa14658 252 uint16_t sd_BP_ECGMAX(int32_t pid)
avp2417 36:00d96aa14658 253 {
avp2417 36:00d96aa14658 254 uint32_t ecgmax = 0; // changed from int to uint32_t - suhasini - 21/7/17
avp2417 36:00d96aa14658 255 uint32_t a[1] = {0}; // changed from int to uint32_t - suhasini - 21/7/17
avp2417 36:00d96aa14658 256 uint16_t samplesecg =0; // changed from int to uint32_t - suhasini - 21/7/17
avp2417 36:00d96aa14658 257 char buffer1[32];
avp2417 36:00d96aa14658 258
avp2417 36:00d96aa14658 259 sprintf(buffer1,"/sd/%d_BP_ECG.csv",pid);
avp2417 36:00d96aa14658 260 fpecg_bp = fopen(buffer1,"r");
avp2417 36:00d96aa14658 261 if(fpecg_bp == NULL)
avp2417 36:00d96aa14658 262 {
avp2417 36:00d96aa14658 263 exit(1);
avp2417 36:00d96aa14658 264 }
avp2417 36:00d96aa14658 265
avp2417 36:00d96aa14658 266 else
avp2417 36:00d96aa14658 267 {
avp2417 36:00d96aa14658 268 for(ebp=0; ebp<1024; ebp++)
avp2417 36:00d96aa14658 269 {
avp2417 36:00d96aa14658 270
avp2417 36:00d96aa14658 271
avp2417 36:00d96aa14658 272 fread(a,sizeof(uint32_t), 1,fpecg_bp);
avp2417 36:00d96aa14658 273 if(a[0] > ecgmax)
avp2417 36:00d96aa14658 274 {
avp2417 36:00d96aa14658 275 ecgmax=a[0];
avp2417 36:00d96aa14658 276 ecgloc= ebp +1;
avp2417 36:00d96aa14658 277 }
avp2417 36:00d96aa14658 278 else
avp2417 36:00d96aa14658 279 samplesecg =ebp+1;
avp2417 36:00d96aa14658 280 }
avp2417 36:00d96aa14658 281 }
avp2417 36:00d96aa14658 282 fclose (fpecg_bp);
avp2417 36:00d96aa14658 283 return ecgloc;
avp2417 36:00d96aa14658 284 }
avp2417 36:00d96aa14658 285
avp2417 36:00d96aa14658 286 // Function to calculate PPG MAx and location
avp2417 36:00d96aa14658 287
avp2417 36:00d96aa14658 288 uint16_t sd_BP_PPGMAX(int32_t pid) //int to uint16_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 289 {
avp2417 36:00d96aa14658 290 uint32_t ppgmax = 0; //int to uint32_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 291 uint32_t b[1] ={0}; //int to uint32_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 292 uint16_t samplesppg = 0; //int to uint16_t-Suhasini-21stJuly2017
avp2417 36:00d96aa14658 293 char buffer1[32];
avp2417 36:00d96aa14658 294
avp2417 36:00d96aa14658 295 sprintf(buffer1,"/sd/%d_BP_PPG.csv",pid);
avp2417 36:00d96aa14658 296 fpppg1 = fopen(buffer1,"r");
avp2417 36:00d96aa14658 297 if(fpppg1 == NULL)
avp2417 36:00d96aa14658 298 {
avp2417 36:00d96aa14658 299 exit(1);
avp2417 36:00d96aa14658 300 }
avp2417 36:00d96aa14658 301
avp2417 36:00d96aa14658 302 else
avp2417 36:00d96aa14658 303 {
avp2417 36:00d96aa14658 304 for(pbp=0; pbp<1664; pbp++)
avp2417 36:00d96aa14658 305 {
avp2417 36:00d96aa14658 306 fread(b, sizeof(uint32_t),1, fpppg1);
avp2417 36:00d96aa14658 307
avp2417 36:00d96aa14658 308 if((pbp>ecgloc) && (pbp< (ecgloc+350)))
avp2417 36:00d96aa14658 309 {
avp2417 36:00d96aa14658 310 if(b[0] > ppgmax)
avp2417 36:00d96aa14658 311 {
avp2417 36:00d96aa14658 312 ppgmax=b[0];
avp2417 36:00d96aa14658 313 ppgloc= pbp+1;
avp2417 36:00d96aa14658 314 }
avp2417 36:00d96aa14658 315 else
avp2417 36:00d96aa14658 316 samplesppg =pbp+1;
avp2417 36:00d96aa14658 317 }
avp2417 36:00d96aa14658 318 else
avp2417 36:00d96aa14658 319 samplesppg = pbp+1;
avp2417 36:00d96aa14658 320 }
avp2417 36:00d96aa14658 321 }
avp2417 36:00d96aa14658 322 fclose (fpppg1);
avp2417 36:00d96aa14658 323 return ppgloc;
avp2417 36:00d96aa14658 324 }