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