Log measurements on SD card added on DISCO-L476VG board acceleration, omega, compass & 5 Analog values
Dependencies: BSP_DISCO_L476VG COMPASS_DISCO_L476VG ConfigFile GYRO_DISCO_L476VG SDFileSystem mbed
DataFile/DataFile.cpp
- Committer:
- flowh
- Date:
- 2016-02-13
- Revision:
- 2:f53340e49cc0
- Parent:
- 1:e1f3b4b8b99b
File content as of revision 2:f53340e49cc0:
#include "DataFile.h" #include "ConfigFile.h" //pour lire le fichier de configuration #include "mbed.h" #include "util.h" //tDataFile::tDataFile(DigitalOut* apLedRecord) tDataFile::tDataFile() { Opened=0; //pLedRecord=apLedRecord; } void tDataFile::New() { char DataFileName[40] ; char NumFich[40]; char *keyIndex = "Index"; char value[BUFSIZ]; ConfigFile cfg; if (Opened==0) { //récupère le n° d'index dans un fichier de configuration if (!cfg.read("/sd/index.txt")) { error("Failure to read index file.\n"); } cfg.getValue(keyIndex, &value[0], sizeof(value)); Index=atoi(value); //printf("Index=%d\r\n", Index); //crèe le non de fichier à créer // printf("OpenDataFile\n\r"); strcpy(DataFileName,"/sd/"); // printf("DataFileName=%s\n\r",DataFileName); itoa(Index,NumFich); // printf("numFich=%s\n\r",NumFich); strcat (DataFileName,NumFich); // printf("DataFileName=%s\n\r",DataFileName); strcat (DataFileName,".txt"); printf("New Data file opened : %s\n\r",DataFileName); //met à jour l'index itoa(Index+1,NumFich); //printf("Prochain fichier a ecrire=%s\n\r",NumFich); cfg.setValue(keyIndex, NumFich); cfg.write("/sd/index.txt","index",cfg.DOS); //ouvre le fichier fp= fopen(DataFileName, "a"); // Open "xxx.txt" on the local file system for writing fprintf(fp, "Gx\tGy\tGz\tWx\tWy\tWz\tMx\tMy\tMz\tI0\tAI1\tAI2\tAI3\tAI4\n"); Opened=1; // printf("DataFile opened\n\r"); } } void tDataFile::Close() { if (Opened==1) { fclose(fp); Opened=0; printf("DataFile Closed\n\n\r"); } } void tDataFile::SaveMesures(tMesure * apMesure) { if (Opened==1) { // printf("sauvegarde en cours\r\n"); apMesure->Save(fp); } }