Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of SS_SensePOC2P0_11Dec2017_USERPID by
sdcard.cpp
00001 // Exisiting code in Int_Demo_09May2017_suhasini/sdcard.cpp is deleted and replaced by new code 00002 //Nidhin 1/6/2017 00003 00004 00005 #include "mbed.h" 00006 #include <stdio.h> 00007 #include "SDFileSystem.h" 00008 #include "sdcard.h" 00009 #include "rtc.h" 00010 #include "struct.h" 00011 #include "main.h" 00012 #include "eeprom_pgm.h" 00013 00014 Serial snd(USBTX,USBRX); 00015 //SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd"); 00016 00017 FILE *fpecg; // PPG and ECG File pointers for BP 00018 FILE *fpppg; //"" "" 00019 00020 FILE *fpmain; // FILE pointer for main file 00021 00022 FILE *fpbg; // FILE pointer to BG file 00023 FILE *fpeecg; // FILE pointer to ECG file 00024 FILE *fpbp; // FILE pointer to BP file 00025 00026 FILE *fp; // FILE pointer for random use 00027 00028 //Function Added on 16/5/2017 by Nidhin 00029 void sd_open_mainfile(int32_t pid) 00030 { 00031 char buffer1[32]; 00032 sprintf(buffer1,"/sd/%d.csv",pid); 00033 fp = fopen(buffer1,"a"); 00034 } 00035 //------------------------------------------ 00036 00037 00038 00039 /*void sd_open_GLCfile(int pid) // opening the glc file 00040 { 00041 00042 char buffer[32]; 00043 char buffer1[32]; 00044 time_t epoch_time1; 00045 epoch_time1=rtc_read(); 00046 // strftime(buffer, 32, "GLC_%s", pid); 00047 00048 sprintf(buffer1,"/sd/%d_GLC.csv",pid); 00049 fp = fopen(buffer1,"a"); 00050 fprintf(fp,"%s\n",ctime(&epoch_time1) ); //writing the date, time into the file 00051 00052 00053 } */ 00054 00055 void sd_open_GLCfilee(uint32_t pid) // only opening the glc file after entering TEST screen 00056 { 00057 char buffer1[32]; 00058 sprintf(buffer1,"/sd/%d_GLC.csv",pid); 00059 fpbg = fopen(buffer1,"a"); 00060 fclose(fpbg); 00061 } 00062 00063 00064 void sd_open_ECGfilee(uint32_t pid) // only opening the ECG file after entering TEST screen 00065 { 00066 00067 char buffer1[32]; 00068 sprintf(buffer1,"/sd/%d_ECG.csv",pid); 00069 fpeecg = fopen(buffer1,"a"); 00070 //fclose(fpeecg); 00071 00072 } 00073 00074 00075 void sd_open_BPfilee(uint32_t pid) // only opening the BP file after entering TEST screen 00076 { 00077 00078 00079 char buffer1[32]; 00080 sprintf(buffer1,"/sd/%d_BP.csv",pid); 00081 fpbp = fopen(buffer1,"a"); 00082 //fprintf(fp,"PATIENT ID %d\n",pid ); Not required in new code as writing in hex 00083 fclose(fpbp); 00084 } 00085 00086 void sd_write (int value) // writing data into the file 00087 { 00088 fprintf(fp,"%d\n", value); 00089 } 00090 00091 00092 uint8_t sd_open_read(uint32_t pid) // opening the file for read // CHNAGED to return value 00093 { 00094 00095 char buffer1[32]; 00096 sprintf(buffer1,"/sd/%d.csv",pid); 00097 fp = fopen(buffer1,"r"); 00098 if (fp==NULL) 00099 { 00100 snd.printf("no"); 00101 return 0; 00102 } 00103 00104 else 00105 { 00106 snd.printf("yes"); 00107 return 1; 00108 } 00109 } 00110 00111 void sd_read(uint32_t *v1, uint16_t size) //reading the data from the openend file 00112 { 00113 fread(v1,sizeof(v1),size,fp); 00114 } 00115 00116 void setpos() 00117 { 00118 //fseek ( fp , 1 , SEEK_SET ); 00119 rewind (fp); 00120 } 00121 00122 void setpos1(uint32_t position) 00123 { 00124 fseek ( fp , position, SEEK_SET ); 00125 //rewind (fp); 00126 } 00127 00128 00129 uint32_t file_size() 00130 { 00131 uint32_t file_length; 00132 fseek (fp, 0, SEEK_END); 00133 file_length=ftell(fp); 00134 file_length=sizeof(char)*file_length; 00135 rewind(fp); 00136 return file_length; 00137 } 00138 00139 00140 uint32_t file_size1() 00141 { 00142 uint32_t file_length; 00143 // fseek (fp, 0, SEEK_END); 00144 00145 file_length=ftell(fp); 00146 // file_length=sizeof(char)*file_length; 00147 // rewind(fp); 00148 return file_length; 00149 } 00150 00151 00152 00153 00154 00155 void sd_read1(BLEMsg_info &f) 00156 { 00157 fread(&f,sizeof(BLEMsg_info),1,fp); 00158 //fscanf(fp,"%08x",&v1); 00159 } 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 //------------------------------------------------------ 00170 00171 //FILE *sd_BP_ecgwrite (int value) // writing data into the file NIDHIN 00172 FILE *sd_BP_ecgwrite (uint32_t *fpdrum11) // writing data into the file NIDHIN 00173 { 00174 fwrite(fpdrum11,sizeof(uint32_t),1, fpecg); //Change by Nidhin 30/5/2017 Direct writing to SD card. Org Val 64 00175 return fpecg; 00176 } 00177 00178 FILE* sd_BP_ppgwrite (uint32_t *fpdrum21) // //Change by Nidhin 30/5/2017 Direct writing to SD card. 00179 { 00180 fwrite(fpdrum21,sizeof(uint32_t),1, fpppg); //Change by Nidhin 30/5/2017 Direct writing to SD card. OR Val 64 00181 return fpppg; 00182 } 00183 //-----------------------------------------------SD Read 00184 00185 void sd_reopen_BPfilee(uint32_t pid) // only opening the BP file after entering TEST screen 00186 { 00187 00188 00189 char buffer1[32]; 00190 sprintf(buffer1,"/sd/%d_BP.csv",pid); 00191 fp = fopen(buffer1,"r"); 00192 //fprintf(fp,"PATIENT ID %d\n",pid ); 00193 00194 00195 } 00196 //------------------------------------------------- 00197 00198 00199 //--------------------------------------- 00200 00201 00202 void sd_open_BP_ECGfile(uint32_t pid) 00203 { 00204 00205 //char buffer[32]; 00206 char buffer1[32]; 00207 //time_t epoch_time1; 00208 //epoch_time1=rtc_read(); 00209 // strftime(buffer, 32, "ECG_%d", pid); 00210 00211 sprintf(buffer1,"/sd/%d_BP_ECG.csv",pid); 00212 fpecg = fopen(buffer1,"a"); 00213 if (fpecg == NULL) 00214 { 00215 exit(1); 00216 } 00217 //fprintf(fpecg,"%s\n",ctime(&epoch_time1) ); 00218 00219 } 00220 00221 00222 void sd_open_BP_PPGfile(uint32_t pid) 00223 { 00224 00225 char buffer1[32]; 00226 //time_t epoch_time1; 00227 //epoch_time1=rtc_read(); 00228 // strftime(buffer, 32, "ECG_%d", pid); 00229 00230 sprintf(buffer1,"/sd/%d_BP_PPG.csv",pid); 00231 fpppg = fopen(buffer1,"a"); 00232 if(fpppg == NULL) 00233 { 00234 exit(1); 00235 } 00236 00237 //fprintf(fpppg,"%s\n",ctime(&epoch_time1) ); 00238 00239 } 00240 00241 00242 00243 //-------------------------------------------------- 00244 00245 //FUNCTIONS TO CLOSE FILES 00246 //__________________________________________________ 00247 void sd_close() //close the file with fp 00248 { 00249 00250 fclose(fp); 00251 } 00252 //______________________________________________________ 00253 void sd_close_ecg() // Closes ECG file pinted by fpeecg 00254 { 00255 00256 fclose(fpeecg); 00257 } 00258 //______________________________________________________ 00259 void sd_close_glc() // Closes GLC file pinted by fpbg 00260 { 00261 00262 fclose(fpbg); 00263 } 00264 //_____________________________________________________ 00265 00266 00267 00268 00269 00270 00271 //fread(buffer, 1, size, fp) 00272 //fwrite(&buffer, , 00273 //----------------------------------------------------28/4/2017--------------------------------- 00274 //---------------------------------------------------------------------------------------------- 00275 00276 00277 00278 //------- FUNCTION TO CREATE SINGLE BP FILE --------2/5/2017 (NIDHIN)---------------// 00279 void create_single_BPfile(uint32_t pid) 00280 { 00281 00282 //int ecgbuf[64] = {0}; 00283 //uint32_t ppgbuf[64] = {0}; 00284 00285 char buffer3[32]; 00286 sprintf(buffer3, "/sd/%d_BP.csv", pid); 00287 fpbp = fopen(buffer3, "a"); // Opens BP file with FILE pointer fpbp in APPEND mode 00288 00289 //buffer1[32] = ""; 00290 sprintf(buffer3, "/sd/%d_BP_ECG.csv", pid); 00291 fpecg = fopen(buffer3, "r"); // Opens ECG file of BP with FILE pointer fpecg in READ mode 00292 00293 //char buffer1[32] = ""; 00294 sprintf(buffer3, "/sd/%d_BP_PPG.csv", pid); 00295 fpppg = fopen(buffer3, "r"); // Opens PPG file of BP with FILE pointer fpppg in READ mode 00296 00297 for(int i=0; i<16; i++) 00298 { 00299 int ecgbuf[64] = {0} ; 00300 fread(ecgbuf, sizeof(uint32_t), 64, fpecg); 00301 fwrite(ecgbuf, sizeof(uint32_t), 64, fpbp); // Copy ECG data of BP into BP file 00302 } 00303 00304 for(int i=0; i<26; i++) 00305 { 00306 int ppgbuf[64] = {0} ; 00307 fread(ppgbuf, sizeof(uint32_t), 64, fpppg); 00308 fwrite(ppgbuf, sizeof(uint32_t), 64, fpbp); // Copy PPG data of BP into BP file 00309 } 00310 00311 fclose(fpecg); // Closes the ECG file of BP 00312 fclose(fpppg); // Closes the PPG file of BP 00313 fclose(fpbp); // Closes the BP file 00314 00315 //char buffer1[32] = ""; 00316 int status = 1 ; 00317 sprintf(buffer3, "/sd/%d_BP_ECG.csv", pid); 00318 status = remove(buffer3); //Removes ECG file of BP and updates status with 0 if successful 00319 00320 00321 if( status == 0 ) 00322 snd.printf("\nECG file delete : Successful"); // Checks for SUCCESS 00323 else 00324 snd.printf("\nECG file delete : UnSuccessful"); 00325 00326 00327 //char buffer1[32] = ""; 00328 status = 1 ; 00329 sprintf(buffer3, "/sd/%d_BP_PPG.csv", pid); 00330 status = remove(buffer3); //Removes PPG file of BP and updates status with 0 if successful 00331 00332 if( status == 0 ) 00333 snd.printf("\nPPG file delete : Successful"); // Checks for SUCCESS 00334 else 00335 snd.printf("\nPPG file delete : UnSuccessful"); 00336 00337 } 00338 00339 00340 00341 //Creating strcuture file Common to All Functions 00342 void structure_file(BLEMsg_info *ptr, uint32_t pid) 00343 { 00344 char buffer3[32]; 00345 sprintf(buffer3, "/sd/%d.csv", pid); //Printing file path to the buffer 00346 if(get_filecreated_status() == true) //if file created open in append mode 00347 { 00348 fpmain = fopen(buffer3, "a"); // open the file PID.csv with FILE pointer fpmain 00349 snd.printf("\n Append mode\n"); 00350 } 00351 else //if file not created, open in write mode 00352 { 00353 fpmain = fopen(buffer3, "w"); // open the file PID.csv with FILE pointer fpmain 00354 snd.printf("\n Write mode\n"); 00355 } 00356 00357 fwrite(ptr, sizeof(uint8_t),32, fpmain ); // writing the Structure into the file 00358 fclose(fpmain); // Close File 00359 } 00360 00361 //Copy Data into file. 00362 00363 void bpfile_mainfile(uint32_t pid) //Copy data of bp file to main 00364 { 00365 char buffer3[32]; 00366 sprintf(buffer3, "/sd/%d.csv", pid); 00367 fpmain = fopen(buffer3, "a"); // Opens Main file with FILE pointer "fpmain" in APPEND mode 00368 00369 sprintf(buffer3, "/sd/%d_BP.csv", pid); 00370 fpbp = fopen(buffer3, "r"); // Opens BP file with FILE pointer "fpbp" in READ mode 00371 00372 00373 for(int i=0; i<21; i++) 00374 { 00375 int bigbuf[128] = {0} ; 00376 fread(bigbuf, sizeof(uint32_t), 128, fpbp); 00377 fwrite(bigbuf, sizeof(uint32_t), 128, fpmain); // Copy BP raw data into main file 00378 } 00379 fclose(fpbp); // Close BP file 00380 fclose(fpmain); // Close Main File 00381 00382 int success; 00383 sprintf(buffer3, "/sd/%d_BP.csv", pid); 00384 success = remove(buffer3); // Should return zero on success 00385 } 00386 00387 //------------New function added to print ECG data to Sd card using fwrite 00388 void sd_ecgwrite(uint32_t *ecg_ptr) 00389 { 00390 fwrite(ecg_ptr, sizeof(int), 1, fpeecg); 00391 } 00392 00393 00394 //------------ Function to write ECG data to main file 00395 void ecgfile_mainfile(uint32_t pid) 00396 { 00397 char buffer3[32]; 00398 sprintf(buffer3, "/sd/%d.csv", pid); 00399 fpmain = fopen(buffer3, "a"); // Main File is opened in Append mode 00400 snd.printf("opening main file\n"); 00401 sprintf(buffer3, "/sd/%d_ECG.csv", pid); // ECG file is opened in read mode 00402 fpeecg = fopen(buffer3, "r"); 00403 snd.printf("opening temp file\n"); 00404 for(int i=0; i<20; i++) //the loop runs as 20 times of 100 i.e., 2k 00405 { 00406 int bigbuf[100] = {0} ; 00407 fread(bigbuf, sizeof(int),100 , fpeecg); 00408 fwrite(bigbuf, sizeof(int), 100, fpmain); 00409 } 00410 snd.printf("to close temp file\n"); 00411 fclose(fpeecg); // Both files are Closed 00412 snd.printf("to come out of main file\n"); 00413 fclose(fpmain); 00414 00415 snd.printf("COPY complete Files Closed\n"); 00416 00417 sprintf(buffer3, "/sd/%d_ECG.csv", pid); // ECG file is opened in write mode to empty the file 00418 fpeecg = fopen(buffer3, "r"); 00419 fclose(fpeecg); 00420 // File is closed 00421 int success; 00422 sprintf(buffer3, "/sd/%d_ECG.csv", pid); 00423 success = remove(buffer3); 00424 snd.printf("DELETE STATUS = %d\n", success); 00425 success = 1; 00426 sprintf(buffer3, "/sd/%d_ECG_lpf.csv", pid); 00427 success = remove(buffer3); 00428 snd.printf("DELETE STATUS = %d\n", success); 00429 } 00430 00431 00432 //---------------------- Function to write GLC data to GLC file 00433 void sd_glcwrite(uint32_t *glc_ptr, uint32_t pid) 00434 { 00435 char buffer3[32]; 00436 sprintf(buffer3, "/sd/%d_GLC.csv", pid); 00437 fpbg = fopen(buffer3, "a"); 00438 00439 fwrite(glc_ptr, sizeof(uint32_t), 2, fpbg); 00440 fclose(fpbg); 00441 00442 } 00443 00444 // --------------------------Fuinction to write GLC data to Main file 00445 00446 void glcfile_mainfile(uint32_t pid) 00447 { 00448 char buffer3[32]; 00449 sprintf(buffer3, "/sd/%d.csv", pid); 00450 fpmain = fopen(buffer3, "a"); // Main File is opened in Append mode 00451 00452 sprintf(buffer3, "/sd/%d_GLC.csv", pid); // BG file is opened in read mode 00453 fpbg = fopen(buffer3, "r"); 00454 00455 for(int i=0; i<1; i++) 00456 { 00457 int bigbuf[2] = {0} ; 00458 fread(bigbuf, sizeof(uint32_t),2 , fpbg); 00459 fwrite(bigbuf, sizeof(uint32_t), 2, fpmain); 00460 } 00461 fclose(fpbg); // Both files are Closed 00462 fclose(fpmain); 00463 00464 int success; 00465 sprintf(buffer3, "/sd/%d_GLC.csv", pid); 00466 success = remove(buffer3); // GLC file is deleted 00467 } 00468 00469 00470 void delete_subfiles(uint32_t pid) 00471 { 00472 char buffer3[32]; 00473 int success1 , success2, success3; 00474 success1 = 1 ; 00475 sprintf(buffer3, "/sd/%d_BP.csv", pid); 00476 success1 = remove(buffer3); //Removes PPG file of BP and updates status with 0 if successful 00477 00478 if( success1 == 0 ) 00479 snd.printf("\nBP file delete : Successful"); // Checks for SUCCESS 00480 else 00481 snd.printf("\nBP file delete : UnSuccessful"); 00482 00483 success2 = 1 ; 00484 sprintf(buffer3, "/sd/%d_GLC.csv", pid); 00485 success2 = remove(buffer3); //Removes GLC file and updates status with 0 if successful 00486 00487 if( success2 == 0 ) 00488 snd.printf("\nGLC file delete : Successful"); // Checks for SUCCESS 00489 else 00490 snd.printf("\nGLC file delete : UnSuccessful"); 00491 00492 success3 = 1 ; 00493 sprintf(buffer3, "/sd/%d_ECG.csv", pid); 00494 success3 = remove(buffer3); //Removes ECG file and updates status with 0 if successful 00495 00496 if( success3 == 0 ) 00497 snd.printf("\nECG file delete : Successful"); // Checks for SUCCESS 00498 else 00499 snd.printf("\nECG file delete : UnSuccessful"); 00500 00501 success3 = 1; 00502 sprintf(buffer3, "/sd/%d_ECG_lpf.csv", pid); 00503 success3 = remove(buffer3); 00504 snd.printf("DELETE STATUS = %d\n", success3); 00505 00506 if( success3 == 0 ) 00507 snd.printf("\nECG_lpf file delete : Successful"); // Checks for SUCCESS 00508 else 00509 snd.printf("\nECG_lpf file delete : UnSuccessful"); 00510 00511 } 00512 00513 00514 void del_ppg_ecg_BPfile(uint32_t pid) 00515 { 00516 int status = 1 ; 00517 char buffer3[32]; 00518 sprintf(buffer3, "/sd/%d_BP_ECG.csv", pid); 00519 status = remove(buffer3); //Removes ECG file of BP and updates status with 0 if successful 00520 00521 if( status == 0 ) 00522 snd.printf("\n temp ECG file delete for error condition: Successful"); // Checks for SUCCESS 00523 else 00524 snd.printf("\n temp ECG file delete for error condition: UnSuccessful"); 00525 00526 00527 //char buffer1[32] = ""; 00528 status = 1 ; 00529 sprintf(buffer3, "/sd/%d_BP_PPG.csv", pid); 00530 status = remove(buffer3); //Removes PPG file of BP and updates status with 0 if successful 00531 00532 if( status == 0 ) 00533 snd.printf("\n temp PPG file delete for error condition: Successful"); // Checks for SUCCESS 00534 else 00535 snd.printf("\n temp PPG file delete for error condition: UnSuccessful"); 00536 00537 } 00538 00539 void sd_read(uint32_t *pid_btpid) //reading the data from the openend file 00540 { 00541 FILE *fp; 00542 uint32_t pid[2]={0,0}; 00543 fp= fopen("/sd/pid_info.txt","r"); 00544 if (fp==NULL) 00545 { 00546 fp= fopen("/sd/pid_info.txt","w"); 00547 fwrite(&pid, sizeof(uint32_t),2,fp); 00548 fclose(fp); 00549 fp= fopen("/sd/pid_info.txt","r"); 00550 } 00551 00552 fread(pid_btpid,sizeof(pid_btpid),2,fp); 00553 fclose(fp); 00554 00555 } 00556 00557 00558 void sd_write(uint32_t *pid_btpid) //reading the data from the openend file 00559 { 00560 FILE *fp; 00561 fp= fopen("/sd/pid_info.txt","w"); 00562 fwrite(pid_btpid,sizeof(pid_btpid),2,fp); 00563 fclose(fp); 00564 00565 } 00566 00567 void delete_sdcard(void) 00568 { 00569 FILE *fp; 00570 uint32_t pid[2] = {0,0}; 00571 fp= fopen("/sd/pid_info.txt","w"); 00572 fwrite(&pid, sizeof(uint32_t),2,fp); 00573 fclose(fp); 00574 00575 } 00576 00577 00578 /*void read_sdcard_file() 00579 { 00580 uint32_t pid=0; 00581 snd.printf("Enter the PID number......!!\n"); 00582 snd.scanf("%d", &pid); 00583 snd.printf("%d\n",pid); 00584 readfile(pid); 00585 snd.printf("Finished reading\n"); 00586 00587 }*/ 00588 00589 00590 00591 void read_sdcard_file() 00592 { 00593 00594 00595 00596 FILE *fp_read_sdcard_file ; // PPG and ECG File pointers for BP 00597 char buffer[32]; 00598 uint32_t pid = 0; 00599 snd.scanf("%d", &pid); 00600 snd.printf("%d\n",pid); 00601 00602 00603 00604 sprintf(buffer,"/sd/%d.csv",pid); 00605 fp_read_sdcard_file = fopen(buffer, "rb"); 00606 00607 if(fp_read_sdcard_file == NULL) 00608 { 00609 snd.printf("No FILE Found .... !!\n"); 00610 } 00611 00612 else 00613 { 00614 read_structure(fp_read_sdcard_file); 00615 snd.printf("Finished Reading File Content....!!\n"); 00616 fclose(fp_read_sdcard_file); 00617 } //end of else loop 00618 00619 } 00620 00621 void read_structure(FILE * fp_read_sdcard_file) 00622 00623 { 00624 BLEMsg_info pid_file; 00625 uint32_t buf[1]; // buffer to read the raw data 00626 uint16_t sample = 0; // variable to hold the no of samples 00627 00628 fread(&pid_file,sizeof(BLEMsg_info),1,fp_read_sdcard_file); // reading the structure data 00629 while (!feof(fp_read_sdcard_file)) 00630 { 00631 snd.printf("length = %d\n",pid_file.length); 00632 snd.printf("device_id = %d\n",pid_file.device_id); 00633 snd.printf("patient_id = %s\n",pid_file.patient_id); 00634 snd.printf("date = %d\n",pid_file.date_time.date); 00635 snd.printf("month = %d\n",pid_file.date_time.month); 00636 snd.printf("year = %d\n",pid_file.date_time.year); 00637 snd.printf("hour = %d\n",pid_file.date_time.hour); 00638 snd.printf("mins = %d\n",pid_file.date_time.mins); 00639 snd.printf("sec = %d\n",pid_file.date_time.sec); 00640 snd.printf("test_type = %d\n",pid_file.test_type); 00641 snd.printf("sampling_freq = %d\n",pid_file.sampling_freq); 00642 snd.printf("sample1 = %d\n",pid_file.num_samples.num_sample_ppg_dummy); 00643 snd.printf("samples2 = %d\n",pid_file.num_samples.num_sample_ecg_OTtyp); 00644 sample=(pid_file.num_samples.num_sample_ppg_dummy + pid_file.num_samples.num_sample_ecg_OTtyp); 00645 snd.printf("caldata1 = %d\n",pid_file.cal_data.cal_sbp_dummy); 00646 snd.printf("caldata2 = %d\n",pid_file.cal_data.cal_dbp_OTtyp); 00647 //snd.printf("sample=%d\n", sample); 00648 for(uint16_t file_start=0;file_start<sample;file_start++) //reading the raw data 00649 { 00650 fread(buf,sizeof(uint32_t),1,fp_read_sdcard_file); 00651 snd.printf("%d\n", buf[0]); 00652 } 00653 fread(&pid_file,sizeof(BLEMsg_info),1,fp_read_sdcard_file); 00654 00655 } 00656 00657 } 00658 00659 uint8_t dummy_file_create_delete() 00660 { 00661 uint8_t dummy_write[5] = {0}; 00662 uint8_t dummy_read[5] = {0}; 00663 uint8_t i = 0; 00664 for(i=0; i<5; i++) 00665 { 00666 dummy_write[i] = i+i; 00667 } 00668 fp = fopen("/sd/dummy_file.txt","w"); 00669 fwrite(&dummy_write, sizeof(uint8_t),5,fp); 00670 fclose(fp); 00671 fp = fopen("/sd/dummy_file.txt","r"); 00672 rewind(fp); 00673 fread(&dummy_read,sizeof(uint8_t),5,fp); 00674 for(i=0; i<5; i++) 00675 { 00676 00677 if (dummy_read[i] != dummy_write[i]) 00678 { 00679 fclose(fp); 00680 remove("/sd/dummy_file.txt"); 00681 return 1; 00682 } 00683 00684 } 00685 00686 00687 00688 fclose(fp); 00689 remove("/sd/dummy_file.txt"); 00690 return 0; 00691 } 00692 00693 00694 00695
Generated on Mon Jul 18 2022 19:19:02 by
1.7.2
