
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 15:208b146151ba, committed 2017-06-05
- Comitter:
- nidhinvarghese
- Date:
- Mon Jun 05 09:14:44 2017 +0000
- Parent:
- 14:f5c62d30c6fc
- Child:
- 16:8fa1d7fd7953
- Commit message:
- Heart rate is calculated; GLC - Not working
Changed in this revision
--- a/bp.cpp Thu Jun 01 09:24:45 2017 +0000 +++ b/bp.cpp Mon Jun 05 09:14:44 2017 +0000 @@ -175,7 +175,7 @@ concatenate_value2 = readvalue(); //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); + ecg = sd_BP_ecgwrite(&concatenate_value2); maxim_max30102_read_reg(0,&uch_dummy); while(INTR.read()==1);
--- a/display_modules.cpp Thu Jun 01 09:24:45 2017 +0000 +++ b/display_modules.cpp Mon Jun 05 09:14:44 2017 +0000 @@ -401,7 +401,7 @@ } - void glc_4(unsigned int mgdl) // GLC screen to display blood glucose level on the LCD + void glc_4(uint16_t mgdl) // GLC screen to display blood glucose level on the LCD { char buf[10]; sprintf (buf, " BG %d mg/dl",mgdl);
--- a/display_modules.h Thu Jun 01 09:24:45 2017 +0000 +++ b/display_modules.h Mon Jun 05 09:14:44 2017 +0000 @@ -16,7 +16,7 @@ void glc_1(); void glc_2(); void glc_3(); -void glc_4(unsigned int mgdl); +void glc_4(uint16_t mgdl); void screen_again(); void screen_glc_2(); void screen_bp1(float SBP, float DBP) ;
--- a/ecgg.cpp Thu Jun 01 09:24:45 2017 +0000 +++ b/ecgg.cpp Mon Jun 05 09:14:44 2017 +0000 @@ -41,8 +41,8 @@ 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); + //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; @@ -64,8 +64,8 @@ //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); + //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 @@ -74,7 +74,7 @@ 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); + //pc.printf("Test Type is : %d\n", test_type_info_ecg); // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data. @@ -97,8 +97,8 @@ - int concatenate_value2 = 0; - int *ecg_ptr; // Added 1/6/2017 Nidhin + int32_t concatenate_value2 = 0; // ORG. "int concatenate_value2 = 0;" Nidhin 1/6/17 + int32_t *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]; @@ -134,7 +134,7 @@ sd_ecgwrite(ecg_ptr); // REPLACED Nidhin 1/6/2017 ecg_buf[i] = concatenate_value2; - //pc.printf( "%d\n", concatenate_value2); COMMENTED Nidhin 1/6/2017 + pc.printf( "%d\n", concatenate_value2); //COMMENTED Nidhin 1/6/2017 } //sd_close(); // closing the file COMMENTED Nidhin 1/6/2017
--- a/glc.cpp Thu Jun 01 09:24:45 2017 +0000 +++ b/glc.cpp Mon Jun 05 09:14:44 2017 +0000 @@ -1,4 +1,8 @@ -#include "mbed.h" + +/* +// Code by nikitha Commented by Nidhin + +/#include "mbed.h" #include "glc.h" #include "i2c_dec.h" //#include "ili9325.h" @@ -98,21 +102,6 @@ - - - - - - - - - - - - - - - void glc(int pid){ unsigned char GLC_START = 0; char t_s_d = 0; @@ -178,7 +167,278 @@ } +*/ + +// Code Modified with Bluetooth Structure Nidhin 2/6/17 +/// +#include "mbed.h" +#include "glc.h" +#include "i2c_dec.h" +//#include "ili9325.h" +//#include "lcd_base.h" +#include "display_modules.h" +//#include "touch_modules.h" +#include "rtc.h" +#include "sdcard.h" + +#include "struct.h" //Nidhin 31/5/2017 +#include "test_type.h" //Nidhin 31/5/2017 + + +void sample(); +void Compute(); +void i2c_spec(); +Ticker flipper; +Ticker flipper1; + +//osTimerDef (sample_data, sample); // define timers +//osTimerDef (Compute_GLC, Compute); +DigitalIn test_strip(PTA12); + +AnalogIn Ain(PTC1);//Electrode one +AnalogIn Ain2(PTE29); // Electrode two +AnalogOut DAC_signal(PTE30); +Serial gtc(USBTX, USBRX); +//unsigned char c; +//unsigned char HOME = 0; + +//signed char test_strip = 0; +static uint16_t mgdl = 0; +uint16_t mgdll = 0; +uint32_t daata1= 0; +uint32_t data2 = 0; + +static uint32_t data1n= 0; +static uint32_t data2n = 0; +uint32_t datafinal1 = 0; +uint32_t datafinal2 = 0; +//unsigned int data_diff = 0; +unsigned char err = 0; + +uint32_t glcraw[2]; // Nidhin 31/5/2017 +uint8_t chk_glc_data = 0; + +Serial ble(PTC4,PTC3); + + + +void sample() + +{ + data1n = Ain.read_u16(); + data2n = Ain2.read_u16(); + daata1 = beta*daata1+alpha*data1n; + data2 = beta*data2+alpha*data2n; + + if( ((daata1-data2) >=(data2/10) && (daata1 > data2)) || ((data2-daata1) >=(data2/10) && (data2 > daata1)) ) + { + + err = 1; + + } + else + { + err = 0; + //gtc.printf("\n", data1n, data2n); only for testing added nidhin 5Jun17 + } + +} + + + +void Compute() +{ + + + datafinal1 = (uint32_t ) NUMB1*(data2*VREF/(TOTAL))-NUMB2; + datafinal2 = (uint32_t ) NUMB1*(daata1*VREF/(TOTAL))-NUMB2; + mgdl = (uint16_t) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2; // Nidhin 5/6/17 mgdl = (uint32_t) NUMB1*(((daata1+data2)/2)*VREF/(TOTAL))-NUMB2; + + + + if (err == 0) + { + + glc_4(mgdl); + mgdll = mgdl; // Nidhin 31/5/2017 + //gtc.printf("The Result is - %d", mgdll); + //sd_write(mgdl); // storing value into the sd card + //sd_close(); + // ble.printf("blood glucose is %d mg/dl", mgdl); + flipper.detach(); + flipper1.detach(); + // return mgdl; + + + } + + else +{ + gtc.printf("err=1\n"); + + // lcd1.Print( " ERROR RESULT", 5,220,COLOR_RED,COLOR_BLACK, 0); + // ble.printf("E:"); + } + + +} + + +void glc(int pid){ + unsigned char GLC_START = 0; + char t_s_d = 0; + i2c_spec(); + +sd_open_GLCfilee(pid); // Opens GLC file in APPEND mode + + // Bluetooth Structure created globally + BLEMsg_info *ptr_BLEMsg_info_glc, BLEMsg_info_glc; // A copy of master strcuture [ "BLEMsg_info" ] by name "BLEMsg_info_bp" is created + ptr_BLEMsg_info_glc = &BLEMsg_info_glc; // *ptr_BLEMsg_info_bp is the pointer to local copy; + // Cant declare this statement outside main. Causing conflicts + +// Declaration of Date Structure + DateTime_info *ptr_DateTime_info_glc, DateTime_info_glc; // A copy of Master Structure "DateTime_info" created, + ptr_DateTime_info_glc = &DateTime_info_glc; // Structure pointer points to that copy. + + + + // RTC operations + time_t epoch_time_glc; //A copy of time_t by name epoch_time_bp is created + epoch_time_glc = rtc_read(); // time is got from get epoch function. + + struct tm * ptr_time_info_glc, time_info_glc; // Sturucture copy of tm is created + ptr_time_info_glc = localtime(&epoch_time_glc); // Structure accepts the time in local format from "time_t" type. + /* + //BELOW LINE IS TO CHECK Date and TIME + gtc.printf("Time is - %d:%d:%d\n", (*ptr_time_info_glc).tm_hour, (*ptr_time_info_glc).tm_min, (*ptr_time_info_glc).tm_sec); + gtc.printf("Date is - %d:%d:%d\n", (*ptr_time_info_glc).tm_mday, (*ptr_time_info_glc).tm_mon+1, (*ptr_time_info_glc).tm_year-100); + */ + //Copying from one structure to the other using variables + DateTime_info_glc.hour = (uint8_t)(*ptr_time_info_glc).tm_hour; + DateTime_info_glc.mins = (uint8_t)(*ptr_time_info_glc).tm_min; + DateTime_info_glc.sec = (uint8_t)(*ptr_time_info_glc).tm_sec; + + DateTime_info_glc.date = (uint8_t) (*ptr_time_info_glc).tm_mday; + DateTime_info_glc.month =(uint8_t)(*ptr_time_info_glc).tm_mon+1; + DateTime_info_glc.year = (uint8_t)(*ptr_time_info_glc).tm_year-100; + + // Copying Time to Main structure + BLEMsg_info_glc.date_time.hour = DateTime_info_glc.hour; + BLEMsg_info_glc.date_time.mins = DateTime_info_glc.mins; + BLEMsg_info_glc.date_time.sec = DateTime_info_glc.sec; + + BLEMsg_info_glc.date_time.date = DateTime_info_glc.date ; + BLEMsg_info_glc.date_time.month = DateTime_info_glc.month ; + BLEMsg_info_glc.date_time.year = DateTime_info_glc.year ; + + /* + //Checking if the structure has these values + gtc.printf("\nTime 2 is - %d:%d:%d\n", DateTime_info_glc.hour, DateTime_info_glc.mins, DateTime_info_glc.sec); + gtc.printf("\nDate 2 is - %d:%d:%d\n",DateTime_info_glc.date, DateTime_info_glc.month, DateTime_info_glc.year); + */ + + //Loading values to of Test type + test_type_info test_type_info_glc; // copy of " test_type_info" created + test_type_info_glc = BG_Test; // Loaded value 00 to the test type + + BLEMsg_info_glc.test_type = test_type_info_glc; + //Check if 01 is getting printed + //gtc.printf("\nTest Type for BG is 01 = %d\n", test_type_info_glc); + + + // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data. + BLEMsg_info_glc.device_id = 01; // Device ID fixed + BLEMsg_info_glc.patient_id = (uint32_t)pid; // Patient ID + BLEMsg_info_glc.sampling_freq = 0; // sampling frrquency + BLEMsg_info_glc.length = 30; //Total length of data in bytes 22 B+10752 B + + BLEMsg_info_glc.num_samples.num_sample_ecg_OTtyp = 2; + BLEMsg_info_glc.num_samples.num_sample_ppg_dummy = 0; + + + + GLC_START = 1; + // ble.baud(115200); + if(GLC_START == 1) + { + glc_1(); // displaying messages to insert the test strip + err = 0; + data1n = 0; + data2n = 0; + daata1 = 0; + data2 = 0; + //sd_open_GLCfile(pid); // opening the glc file Commented + + while((test_strip)); + + if (!test_strip) // checks for the presence of test strip + { + flipper.attach(&sample, 0.8); + t_s_d = 0; + glc_2(); // displaying message to insert blood + + while((!t_s_d) && (!test_strip)) + { + //if(chk_glc_data == 0) //Nidhin 31/5/2017 + //{ + /* + glcraw[0] = (uint32_t) data1n; //Nidhin 31/5/2017 + glcraw[1] = (uint32_t) data2n; // Nidhin 31/5/2017 + + gtc.printf("datain is =%d\n", data1n); + gtc.printf("data2n is = %d\n", data2n); + + gtc.printf("datain is =%d\n", data1n); + gtc.printf("data2n is = %d\n", data2n); + */ + //chk_glc_data = 1; + //} + //gtc.printf("Checking\n"); + + if ((daata1 >= THRESHOLD) || (data2 >= THRESHOLD)) + { + //glcraw[0] = (uint32_t) data1n; //Nidhin 5/6/2017 + //glcraw[1] = (uint32_t) data2n; // Nidhin 5/6/2017 + + //gtc.printf("data1n is =%d\n", data1n); + //gtc.printf("data2n is = %d\n", data2n); + + // gtc.printf("glcraw[0] is =%d\n", glcraw[0]); + //gtc.printf("glcraw[1] is = %d\n", glcraw[1]); + + t_s_d = 1; + flipper1.attach(&Compute, 2.25); //computing the glucose level + glc_3(); + } + else + { + //wait for insertion of blood; + } + } + wait_ms(800); + } + } + + gtc.printf("DATA1 is - %d\n", data1n); + gtc.printf("DATA2 is - %d\n", data2n); + gtc.printf("mgdl is - %d\n", mgdl); + + sd_glcwrite(glcraw, pid); //Writes the raw data into GLC file + + //Results Stored to Bluetooth structure + BLEMsg_info_glc.cal_data.cal_sbp_dummy = 0; + BLEMsg_info_glc.cal_data.cal_dbp_OTtyp = (uint16_t) mgdll; //To be checked for reliable results + + structure_file(ptr_BLEMsg_info_glc, pid); // Copy the structure into the GLC file + glcfile_mainfile(pid); + + } + + + + +
--- a/sdcard.cpp Thu Jun 01 09:24:45 2017 +0000 +++ b/sdcard.cpp Mon Jun 05 09:14:44 2017 +0000 @@ -129,9 +129,9 @@ //------------------------------------------------------ //FILE *sd_BP_ecgwrite (int value) // writing data into the file NIDHIN -FILE *sd_BP_ecgwrite (uint32_t *fpdrum11) // writing data into the file NIDHIN +FILE *sd_BP_ecgwrite (int32_t *fpdrum11) // writing data into the file NIDHIN { - fwrite(fpdrum11,sizeof(uint32_t),1, fpecg); //Change by Nidhin 30/5/2017 Direct writing to SD card. Org Val 64 + fwrite(fpdrum11,sizeof(int32_t),1, fpecg); //Change by Nidhin 30/5/2017 Direct writing to SD card. Org Val 64 return fpecg; }
--- a/sdcard.h Thu Jun 01 09:24:45 2017 +0000 +++ b/sdcard.h Mon Jun 05 09:14:44 2017 +0000 @@ -17,7 +17,7 @@ //void sd_BP_ppgwrite (uint32_t value); //void sd_BP_ecgwrite (int value); -FILE *sd_BP_ecgwrite (uint32_t *fpdrum11); +FILE *sd_BP_ecgwrite (int32_t *fpdrum11); FILE *sd_BP_ppgwrite (uint32_t *fpdrum21); void sd_open_BP_ECGfile(int pid); //added to write ECG to seperate file BP