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: BSP_DISCO_L476VG COMPASS_DISCO_L476VG ConfigFile GYRO_DISCO_L476VG SDFileSystem mbed
DataFile.cpp
00001 #include "DataFile.h" 00002 #include "ConfigFile.h" //pour lire le fichier de configuration 00003 00004 #include "mbed.h" 00005 #include "util.h" 00006 00007 //tDataFile::tDataFile(DigitalOut* apLedRecord) 00008 tDataFile::tDataFile() 00009 { 00010 Opened=0; 00011 //pLedRecord=apLedRecord; 00012 } 00013 00014 00015 00016 00017 void tDataFile::New() 00018 { 00019 00020 char DataFileName[40] ; 00021 char NumFich[40]; 00022 char *keyIndex = "Index"; 00023 char value[BUFSIZ]; 00024 ConfigFile cfg; 00025 if (Opened==0) 00026 { 00027 //récupère le n° d'index dans un fichier de configuration 00028 if (!cfg.read("/sd/index.txt")) { 00029 error("Failure to read index file.\n"); 00030 } 00031 cfg.getValue(keyIndex, &value[0], sizeof(value)); 00032 Index=atoi(value); 00033 //printf("Index=%d\r\n", Index); 00034 00035 //crèe le non de fichier à créer 00036 // printf("OpenDataFile\n\r"); 00037 strcpy(DataFileName,"/sd/"); 00038 // printf("DataFileName=%s\n\r",DataFileName); 00039 itoa(Index,NumFich); 00040 // printf("numFich=%s\n\r",NumFich); 00041 strcat (DataFileName,NumFich); 00042 // printf("DataFileName=%s\n\r",DataFileName); 00043 strcat (DataFileName,".txt"); 00044 printf("New Data file opened : %s\n\r",DataFileName); 00045 00046 //met à jour l'index 00047 00048 itoa(Index+1,NumFich); 00049 //printf("Prochain fichier a ecrire=%s\n\r",NumFich); 00050 cfg.setValue(keyIndex, NumFich); 00051 cfg.write("/sd/index.txt","index",cfg.DOS); 00052 00053 //ouvre le fichier 00054 fp= fopen(DataFileName, "a"); // Open "xxx.txt" on the local file system for writing 00055 00056 fprintf(fp, "Gx\tGy\tGz\tWx\tWy\tWz\tMx\tMy\tMz\tI0\tAI1\tAI2\tAI3\tAI4\n"); 00057 Opened=1; 00058 // printf("DataFile opened\n\r"); 00059 00060 00061 } 00062 } 00063 00064 void tDataFile::Close() 00065 { 00066 if (Opened==1) 00067 { 00068 fclose(fp); 00069 Opened=0; 00070 printf("DataFile Closed\n\n\r"); 00071 } 00072 } 00073 00074 void tDataFile::SaveMesures(tMesure * apMesure) 00075 { 00076 00077 if (Opened==1) 00078 { 00079 // printf("sauvegarde en cours\r\n"); 00080 apMesure->Save(fp); 00081 } 00082 } 00083 00084 00085
Generated on Thu Jul 14 2022 08:24:02 by
1.7.2