Code clean up - modify Datatypes
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_3rd_nov_2017_15th_dec_2017_magicno_removal by
Diff: ecgg.cpp
- Revision:
- 61:2143f39103f7
- Parent:
- 59:e21cf7e08ebf
--- a/ecgg.cpp Fri Dec 15 11:57:03 2017 +0000 +++ b/ecgg.cpp Tue Dec 19 06:58:44 2017 +0000 @@ -31,7 +31,7 @@ void low_pass_filter(uint32_t pid); void swap(uint32_t *ptr); Serial pc(USBTX,USBRX); - +char buffer[32] = {0}; //buffer declared as file scope nikita uint16_t ecg(uint32_t pid) { @@ -61,11 +61,11 @@ uint8_t no_of_peaks = 0; uint16_t pos_dif = 0.0; float HR[10] = {0.0}; - float HR1 = 0.0; + //float HR1 = 0.0; //commented as not in use nikita float t_pos_dif = 0.0; float HR_sum = 0.0; float HR_avg = 0.0; - char buffer4[32] = {0}; + //----------------------- Structure for Bluetooth Added Nidhin 1/6/2017-------------------// //BLUETOOTH STRUCTURE @@ -120,7 +120,7 @@ // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data. BLEMsg_info_ecg.device_id = get_did(); // Device ID fixed // reading the device id // pc.printf("device id read ecg = %d\n", BLEMsg_info_ecg.device_id); - BLEMsg_info_ecg.patient_id = (uint32_t)pid; // Patient ID + BLEMsg_info_ecg.patient_id = pid; // Patient ID BLEMsg_info_ecg.sampling_freq = ECG_SAMPLING_FREQUENCY; // sampling frrquency BLEMsg_info_ecg.length = ECG_LENGTH_IN_BYTES; //Total length of data in bytes 22 B+ 4000 data @@ -141,7 +141,7 @@ sd_open_ECGfilee(pid); //open temporary ecg.csv file to write 2000 samples of data pc.printf( "Raw data is = \n"); - for(int i=0; i < N_ECG; i++) + for(uint16_t i=0; i < N_ECG; i++) // changed from int to uint16_t nikita { concatenate_value2 = readvalue(); pc.printf( "%d\n", concatenate_value2); @@ -155,8 +155,8 @@ //----------------------------- PEAK DETECTION AND HEART RATE CALCULATION --------------------------------------------------- // PEAK DETECTION - sprintf(buffer4, "/sd/%d_ECG_lpf.csv", pid); // For opening a specific file - fpeecg1 = fopen(buffer4, "r"); + sprintf(buffer, "/sd/%d_ECG_lpf.csv", pid); // For opening a specific file + fpeecg1 = fopen(buffer, "r"); for(uint16_t i = 100;i<((N_ECG-4)-10);i++) { @@ -211,7 +211,7 @@ pc.printf("time in seconds is = %f\n",t_pos_dif); HR[i] = SECONDS_60/t_pos_dif; //HR calculation pc.printf("Heart Rate is = %f\n",HR[i]); - HR1 = HR[0]; + // HR1 = HR[0]; } //To average individual HRs for higher number of samples ----------------------- for(uint16_t i = 0;i < no_of_peaks-1;i++) @@ -251,7 +251,7 @@ pc.printf("improper lead connection"); return 0; } - pc.printf("closing temporary file\n"); +// pc.printf("closing temporary file\n"); } // End of main function @@ -262,22 +262,22 @@ FILE *fpecg1; // FILE pointer to read raw data ECG file added by Suhasini 5-8-17 FILE *fpeecg_lpf; // FILE pointer to read and write into LPF output file added by Suhasini 5-8-17 uint32_t ecg_raw[5] = {0} ; // Buff of 5 samples created to Stores input samples for LPF added by Suhasini - 5-8-17 - uint32_t lpf_op[5] = {0}; // for LPF output added by Suhasini - 5-8-17 // changed from double to int32_t- 16-8-17 + uint32_t lpf_op[5] = {0}; // for LPF output added by Suhasini - 5-8-17 // changed from double to int32_t- 16-8-17 - uint32_t lpf_4samp = 0; // Variable to move 16 samples back from current in input file - changed by Suhasini- 5-8-17 - char buffer3[32]; - char buffer4[32]; // Added by Suhasini - 5-8-17 + // uint32_t lpf_4samp = 0; // Variable to move 16 samples back from current in input file - changed by Suhasini- 5-8-17 + //char buffer3[32]; + // char buffer4[32]; // Added by Suhasini - 5-8-17 const float b[5]= {0.0000624,0.0002495,0.0003743,0.0002495,0.0000624}; //Numerator co-efficients of low-pass butter-worth filter of order=4 const float a[5]= {1.0000,-3.5078,4.6409,-2.7427,0.6105}; //Denominator co-efficients of low-pass butter-worth filter of order=4 - sprintf(buffer3, "/sd/%d_ECG.csv", pid); // opening raw data file to read - fpecg1 = fopen(buffer3, "r"); // to read data from the above opened temp file + sprintf(buffer, "/sd/%d_ECG.csv", pid); // opening raw data file to read + fpecg1 = fopen(buffer, "r"); // to read data from the above opened temp file pc.printf("entered raw data file\n"); - sprintf(buffer4, "/sd/%d_ECG_lpf.csv", pid); // opening empty file to write lpf data - fpeecg_lpf = fopen(buffer4, "a"); // to read data from and write data into the above opened file // changed from "a+" to "a" + sprintf(buffer, "/sd/%d_ECG_lpf.csv", pid); // opening empty file to write lpf data + fpeecg_lpf = fopen(buffer, "a"); // to read data from and write data into the above opened file // changed from "a+" to "a" pc.printf("entered LPF data file\n"); fwrite(&lpf_op, sizeof(int32_t), 4, fpeecg_lpf);