created separate function for hex to char
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of SS_SensePOC2P0_11Dec2017_USERPID by
Diff: ecgg.cpp
- Revision:
- 14:f5c62d30c6fc
- Parent:
- 13:5d3b478ea9c7
- Child:
- 15:208b146151ba
--- a/ecgg.cpp Sat May 27 05:47:55 2017 +0000 +++ b/ecgg.cpp Thu Jun 01 09:24:45 2017 +0000 @@ -12,14 +12,95 @@ #include "rtc.h" #include "sdcard.h" #include "ec_bp.h" + +#include "struct.h" // Added on 31/5/17_Nidhin +#include "test_type.h" //Added on 31/5/17_Nidhin Serial pc(USBTX,USBRX); float ecg(int pid) { + //----------------------- Structure for Bluetooth Added Nidhin 1/6/2017-------------------// + + //BLUETOOTH STRUCTURE + + BLEMsg_info *ptr_BLEMsg_info_ecg, BLEMsg_info_ecg; // A copy of master strcuture [ "BLEMsg_info" ] by name "BLEMsg_info_ecg" is created + ptr_BLEMsg_info_ecg = &BLEMsg_info_ecg; // *ptr_BLEMsg_info_bp is the pointer to local copy; + + // Declaration of Date Structure + DateTime_info *ptr_DateTime_info_ecg, DateTime_info_ecg; // A copy of Master Structure "DateTime_info" created, + ptr_DateTime_info_ecg = &DateTime_info_ecg; // Structure pointer points to that copy. + + + // RTC operations + time_t epoch_time_ecg; //A copy of time_t by name epoch_time_bp is created + epoch_time_ecg = rtc_read(); // time is got from get epoch function. + + struct tm * ptr_time_info_ecg, time_info_ecg; // Sturucture copy of tm is created + 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); + + //Copying from one structure to the other using variables + DateTime_info_ecg.hour = (uint8_t)(*ptr_time_info_ecg).tm_hour; + DateTime_info_ecg.mins = (uint8_t)(*ptr_time_info_ecg).tm_min; + DateTime_info_ecg.sec = (uint8_t)(*ptr_time_info_ecg).tm_sec; + + DateTime_info_ecg.date = (uint8_t) (*ptr_time_info_ecg).tm_mday; + DateTime_info_ecg.month =(uint8_t)(*ptr_time_info_ecg).tm_mon+1; + DateTime_info_ecg.year = (uint8_t)(*ptr_time_info_ecg).tm_year-100; + + // Copying Time to Main structure + BLEMsg_info_ecg.date_time.hour = DateTime_info_ecg.hour; + BLEMsg_info_ecg.date_time.mins = DateTime_info_ecg.mins; + BLEMsg_info_ecg.date_time.sec = DateTime_info_ecg.sec; + + BLEMsg_info_ecg.date_time.date = DateTime_info_ecg.date ; + BLEMsg_info_ecg.date_time.month = DateTime_info_ecg.month ; + BLEMsg_info_ecg.date_time.year = DateTime_info_ecg.year ; + + + //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); + + + //Loading values to of Test type + test_type_info test_type_info_ecg; // copy of " test_type_info" created + test_type_info_ecg = ECG_Test; // Loaded value 00 to the test type + + 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); + + + // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data. + 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 + + /* + //Loading number of samples + NumSamples_info NumSamples_info_bp; //Copy of structure NumSamples_info + NumSamples_info_bp.num_ppg_sample = 1664; // PPG & ECG Sample number loaded in structure copy + NumSamples_info_bp.num_ecg_sample = 1024; + */ + + BLEMsg_info_ecg.num_samples.num_sample_ppg_dummy = 0 ;// PPG number of samples copied to master struct + BLEMsg_info_ecg.num_samples.num_sample_ecg_OTtyp = 1000 ; // ECG number of samples copied to master struct + + //----------------------------------------END Structure for Bluetooth - Added Nidhin 1/6/2017------- + + int concatenate_value2 = 0; + int *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]; int32_t count = 0; int32_t fs = 500; uint32_t ecg_buf[N_ECG]; @@ -40,17 +121,24 @@ setupfunc(); ecgsetupfunc(); // chk = 1; - sd_open_ECGfile(pid); // opening the ecg file + + //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(); - sd_write(concatenate_value2); // writing into the sd card + + //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); + //pc.printf( "%d\n", concatenate_value2); COMMENTED Nidhin 1/6/2017 } - - sd_close(); // closing the file + + //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); @@ -133,6 +221,19 @@ printf("Denominator = %d\n",n); printf("Heart Rate = %f\n",HR_avg); */ + + //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. + +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. + + pc.printf("Closed the main file\n"); + + + return HR1; // return HR_avg;