avec dfu

Fork of Utils by POTLESS

Files at this revision

API Documentation at this revision

Comitter:
POTLESS_2
Date:
Tue Feb 13 08:32:46 2018 +0000
Parent:
2:5af7a1fb1903
Child:
4:872676dd87a4
Commit message:
d'autres fonctions sd

Changed in this revision

Utils.cpp Show annotated file Show diff for this revision Revisions of this file
Utils.h Show annotated file Show diff for this revision Revisions of this file
--- a/Utils.cpp	Mon Feb 12 07:22:14 2018 +0000
+++ b/Utils.cpp	Tue Feb 13 08:32:46 2018 +0000
@@ -4,20 +4,29 @@
 SDBlockDevice bd(SD_MOSI, SD_MISO, SD_SCK, SD_CS);
 FATFileSystem Root("Root");
 
+int Exist_Val = 0;
+
 void return_error(int ret_val)
 {
-    if (ret_val)
+    
+    if (ret_val){
         printf("  Problème carte SD = %d\r\n", ret_val);
-    else
+        Exist_Val = 0;
+    }else{
         printf("  SD -> OK.\r\n");
+        Exist_Val = 1;
+        }
 }
 
 void errno_error(void* ret_val)
 {
-    if (ret_val == NULL)
+    if (ret_val == NULL){
         printf("  Problème carte SD = %d \r\n", errno);
-    else
+        Exist_Val = 0;
+    }else{
         printf("  SD -> OK.\r\n");
+        Exist_Val = 1;
+        }
 }
 
 void UTILS::Store_A_Val(float Val_To_Store, char* File_Name)
@@ -90,16 +99,33 @@
     FILE* fd = fopen(filename, "r");
     errno_error(fd);
 
-    printf("Contenu du fichier :\r\n\r\n");
+    printf("  Contenu du fichier :\r\n\r\n");
     char buff[16] = {0};
     while (!feof(fd)) {
         int size = fread(&buff[0], 1, 15, fd);
         fwrite(&buff[0], 1, size, stdout);
     }
-    printf("Fin du fichier.\n");
+    printf("\r\n  Fin du fichier.\r\n");
     fclose(fd);
 }
 
+bool UTILS::File_Exist(char* File_Name)
+{
+    char filename[20];
+    sprintf(filename, "/Root/%s.txt", File_Name);
+    
+    FILE* fd = fopen(filename, "r");
+    errno_error(fd);
+    
+    if (Exist_Val == 0){
+        printf("  Le fichier recherché n'existe pas....\r\n");
+        return false;
+    }else{
+        fclose(fd);
+        return true;
+    }   
+}
+
 void UTILS::Delete_SD_File(char* File_Name)
 {
     char filename[20];
@@ -157,10 +183,11 @@
     return_error(error);
 }
 
-void UTILS::DIR_SD(char* Dir_Name)
+void UTILS::Dir_SD(char* Dir_Name)
 {
     int error = 0;
-    printf("Ouverture du répertoire %s\r\n.", Dir_Name);
+    int nb = 0;
+    printf("\r\n  Ouverture du répertoire %s\r\n", Dir_Name);
     char Dirname[20];
     sprintf(Dirname, "/Root/%s", Dir_Name);
     
@@ -168,18 +195,36 @@
     //errno_error(fd);
 
     struct dirent* de;
-    printf("Fichier du répertoire :\r\n");
+    printf("  Fichier du répertoire :\r\n\r\n");
     while((de = readdir(dir)) != NULL)
     {
     printf("  %s\r\n", &(de->d_name)[0]);
+    nb++;
     //wait_ms(100);
   }
-
-    printf("Fermeture du répertoire. ");
+    printf("\r\n  Nombre de fichiers = %d\r\n", nb);
+    printf("  Fermeture du répertoire.\r\n");
     error = closedir(dir);
     return_error(error);
 }
 
+int UTILS::File_Index()
+{
+    int error = 0;
+    int nb = 0;
+    
+    DIR* dir = opendir("/Root/");
+    struct dirent* de;
+    while((de = readdir(dir)) != NULL)
+    {
+    nb++;
+    }
+    error = closedir(dir);
+    return_error(error);
+    
+    return nb - 2;
+}
+
 //Remapping d'une valeur dans une autre échelle
 float UTILS::Remap(float x, float in_min, float in_max, float out_min, float out_max)
 {
--- a/Utils.h	Mon Feb 12 07:22:14 2018 +0000
+++ b/Utils.h	Tue Feb 13 08:32:46 2018 +0000
@@ -110,7 +110,21 @@
     /**Fonction DIR.
     * @param char* Nom du répertoire
     */
-    static void DIR_SD(char* Dir_Name = "");
+    static void Dir_SD(char* Dir_Name = "");
+    
+    /**Fonction de numérotage des fichiers log.
+    * @returns
+    *   Index du nouveau fichier log
+    */
+    static int File_Index();
+    
+    /**Fonction de test si un fichier existe.
+    * @param char* Nom du fichier
+    * @returns
+    *   true si le fichier existe, false s'il n'existe pas
+    */
+    static bool File_Exist(char* File_Name);
+
 
 private:
 //Rien...