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