Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Diff: ecgg.cpp
- Revision:
- 22:ffa88619551d
- Parent:
- 20:7c64e6ecad76
- Child:
- 24:d992ee8369f4
--- a/ecgg.cpp Wed Jun 21 08:39:10 2017 +0000 +++ b/ecgg.cpp Fri Jun 23 07:25:24 2017 +0000 @@ -18,8 +18,8 @@ Serial pc(USBTX,USBRX); - -float ecg(int pid) +uint16_t ecg(int32_t pid) +//float ecg(int pid) { uint8_t lead_reg=0; // added on 14/06 to check lead -off @@ -83,7 +83,7 @@ BLEMsg_info_ecg.device_id = 01; // Device ID fixed BLEMsg_info_ecg.patient_id = (uint32_t)pid; // Patient ID BLEMsg_info_ecg.sampling_freq = 500; // sampling frrquency - BLEMsg_info_ecg.length = 4026; //Total length of data in bytes 22 B+10752 B + BLEMsg_info_ecg.length = 4022; //Total length of data in bytes 22 B+ 4000 data /* //Loading number of samples @@ -104,44 +104,52 @@ 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]; - int32_t count = 0; int32_t fs = 500; - uint32_t ecg_buf[N_ECG]; // Moved out of func() Nidhin 9/6/17 - Timer t; + int32_t count = 0; + //int32_t fs = 500; //COMMENTED NIDHIN 17/6/17 + //uint32_t ecg_buf[N_ECG]; //COMMENTED NIDHIN 17/6/17 + //Timer t; //COMMENTED NIDHIN 17/6/17 //------------------ Declaration for Peak value detection ------------------------------------ - + /* uint32_t hi_val;uint32_t pk_val[20];unsigned int pk_pos[20]={0};unsigned int a; //uint32_t pk=0; int hi_dif = 0;int j=0; // int count1 = N_ECG/fs, a_dif=0, fs1 = fs ,h=0; // ------------------------- Declaration for Heart Rate calculation -------------------------- int n=0; //int n=10; float pos_dif, HR[2], HR1,t_pos_dif;int t_sec = 60; float HR_sum = 0,HR_avg; + */ //WHOLE SECTION COMMENTED NIDHIN 17/6/17 // ------------------------------------------------------------------------------------------- // unsigned char chk = 1; pc.baud(baud_rate); freqset(); // setting the frequency - setupfunc(); - lead_reg=ecgsetupfunc(); // added a return function to read leadoff // 14/06 + setupfunc(); + //ecgtestsetupfunc(); // For test set up of 1Hz square wave signal + lead_reg= ecgsetupfunc(); // chk = 1; + + + //ORIGINAL sd_open_ECGfile(pid); // opening the ecg file COMMENTED Nidhin 1/6/2017 if (lead_reg==0) // checking for proper lead contact// 14/06 - { - //ORIGINAL sd_open_ECGfile(pid); // opening the ecg file COMMENTED Nidhin 1/6/2017 + { sd_open_ECGfilee(pid); // REPLACED Nidhin 1/6/2017 Nidhin pc.printf( "Raw data is = \n"); for(int i=0; i<N_ECG; i++) { concatenate_value2= readvalue(); + pc.printf( "%d\n", concatenate_value2); //ADDED Nidhin 21/6/2017 //ORIGINAL sd_write(concatenate_value2); // writing into the sd card COMMENTED Nidhin 1/6/2017 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", *ecg_ptr); + //ecg_buf[i] = concatenate_value2; //COMMENTED Nidhin 10/6/2017 + //pc.printf( "%d\n", concatenate_value2); //COMMENTED Nidhin 10/6/2017 } //sd_close(); // closing the file COMMENTED Nidhin 1/6/2017 sd_close_ecg(); // closing the ECG file REPLACED Nidhin 1/6/2017 Nidhin + + /* // ---------- reading back SD data for processing -------------------- sd_read_file(15); @@ -158,7 +166,7 @@ // -------------------------------------- PEAK DETECTION ------------------------------------------------------------- // ------------------ Main loop --------------------------------- - +/* for(int i=0;i<N_ECG-10;i++){ if(ecg_buf[i]>ecg_buf[i+1]) { @@ -179,9 +187,9 @@ // if(a_dif <= 0) ------------------------ add this condition if needed ---------------------- // { pk_val[j] = hi_val; //if condition satisfied, put the "pk" value into "pk_val" buffer - //// pc.printf("peak value= %d\n",pk_val[j]); + pc.printf("peak value= %d\n",pk_val[j]); pk_pos[j]=a; // also save the peak's position - //// pc.printf("peak position is = %d\n",pk_pos[j]); + pc.printf("peak position is = %d\n",pk_pos[j]); i = a+120; // once confirmed that this is the necessary peak, skip the next 120 input values n = j; // where n is the number of peaks detected j = j+1; @@ -224,28 +232,32 @@ printf("Denominator = %d\n",n); printf("Heart Rate = %f\n",HR_avg); */ - + //HR1 = 72; // Added Nidhin 10June17; //ADDED Nidhin 1/6/2017 -BLEMsg_info_ecg.cal_data.cal_sbp_dummy = 0; -BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = (uint16_t)HR1; //To be modified after HR code is added. + uint16_t HR1; -structure_file(ptr_BLEMsg_info_ecg, pid); //copy the ECG structure to Main file -ecgfile_mainfile(pid); // copy raw data to the main file and ECG file is cleared. +//HR1 = 72; + HR1 = heart_cal(pid); + +BLEMsg_info_ecg.cal_data.cal_sbp_dummy = 0; +BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = HR1; //To be modified after HR code is added. - pc.printf("Closed the main file\n"); +structure_file(ptr_BLEMsg_info_ecg, pid); //copy the ECG structure to Main file //COMMENTED Nidhin 10/6/2017 +ecgfile_mainfile(pid); // copy raw data to the main file and ECG file is cleared. //COMMENTED Nidhin 10/6/2017 + +pc.printf("Closed the main file\n"); return HR1; // return HR_avg; - } +} else { pc.printf("no - leadoff"); return 0; } -} // End of main function - +} // End of main function