
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: sdcard.cpp
- Revision:
- 41:1141a75eacc4
- Parent:
- 36:00d96aa14658
- Child:
- 42:c81673b04b6a
--- a/sdcard.cpp Sun Aug 20 16:21:54 2017 +0000 +++ b/sdcard.cpp Fri Sep 08 10:35:21 2017 +0000 @@ -2,12 +2,14 @@ //Nidhin 1/6/2017 - #include "mbed.h" - #include <stdio.h> - #include "SDFileSystem.h" - #include "sdcard.h" - #include "rtc.h" - #include "struct.h" +#include "mbed.h" +#include <stdio.h> +#include "SDFileSystem.h" +#include "sdcard.h" +#include "rtc.h" +#include "struct.h" +#include "main.h" +#include "eeprom_pgm.h" Serial snd(USBTX,USBRX); SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd"); @@ -61,22 +63,6 @@ } - - /*void sd_open_ECGfile(int pid) - { - - // char buffer[32]; - char buffer1[32]; - time_t epoch_time1; - epoch_time1=rtc_read(); - // strftime(buffer, 32, "ECG_%d", pid); - - sprintf(buffer1,"/sd/%d_ECG.csv",pid); - fp = fopen(buffer1,"a"); - fprintf(fp,"%s\n",ctime(&epoch_time1) ); - - } - */ void sd_open_ECGfilee(int32_t pid) // only opening the ECG file after entering TEST screen { @@ -88,20 +74,6 @@ } - /*void sd_open_BPfile(int pid) - { - - char buffer[32]; - char buffer1[32]; - time_t epoch_time1; - epoch_time1=rtc_read(); - // strftime(buffer, 32, "ECG_%d", pid); - - sprintf(buffer1,"/sd/%d_BP.csv",pid); - fp = fopen(buffer1,"a"); - fprintf(fp,"%s\n",ctime(&epoch_time1) ); - } */ - void sd_open_BPfilee(int32_t pid) // only opening the BP file after entering TEST screen { @@ -371,9 +343,19 @@ //Creating strcuture file Common to All Functions void structure_file(BLEMsg_info *ptr, int32_t pid) { -char buffer3[32]; -sprintf(buffer3, "/sd/%d.csv", pid); //Printing file path to the buffer -fpmain = fopen(buffer3, "a"); // open the file PID.csv with FILE pointer fpmain + char buffer3[32]; + sprintf(buffer3, "/sd/%d.csv", pid); //Printing file path to the buffer + if(get_filecreated_status()) //if file created open in append mode + { + fpmain = fopen(buffer3, "a"); // open the file PID.csv with FILE pointer fpmain + snd.printf("\n Append mode\n"); + } + else //if file not created, open in write mode + { + fpmain = fopen(buffer3, "w"); // open the file PID.csv with FILE pointer fpmain + snd.printf("\n Write mode\n"); + } + fwrite(ptr, sizeof(uint8_t),26, fpmain ); // writing the Structure into the file fclose(fpmain); // Close File } @@ -540,4 +522,45 @@ else snd.printf("\n temp PPG file delete for error condition: UnSuccessful"); -} \ No newline at end of file +} + +void sd_read(uint32_t *pid_btpid) //reading the data from the openend file + { + FILE *fp; FILE *fp1; + uint32_t pid[2]={1,1}; + fp= fopen("/sd/pid_info.txt","r"); + if (fp==NULL) + { + fp1= fopen("/sd/pid_info.txt","w"); + fwrite(&pid, sizeof(uint32_t),2,fp1); + fclose(fp1); + fp= fopen("/sd/pid_info.txt","r"); + } + + fread(pid_btpid,sizeof(pid_btpid),2,fp); + fclose(fp); + + } + + +void sd_write(uint32_t *pid_btpid) //reading the data from the openend file +{ + FILE *fp; + fp= fopen("/sd/pid_info.txt","w"); + fwrite(pid_btpid,sizeof(pid_btpid),2,fp); + fclose(fp); + +} + +void increment_pid (void) //increment pid if a test is completed +{ + uint32_t pid[2]; + if(!get_filecreated_status()) //if file is in write mode + { + set_filecreated_status(); //set it to make it append mode + sd_read(pid); //read pid from sd card + pid[0] = pid[0] + 1; //increment it by 1 + sd_write(pid); //write it back to sd card + } + +} \ No newline at end of file