File manager

Dependencies:   SDFileSystem

Dependents:   RwSDCard_Xml_GPS

Revision:
11:e21d4c5bfd1b
Parent:
10:a8003d357cf2
Child:
12:0045fca3c160
--- a/FileManager.cpp	Wed May 18 10:46:16 2016 +0000
+++ b/FileManager.cpp	Wed May 18 12:16:12 2016 +0000
@@ -7,12 +7,18 @@
 Variable_Data_TypeDef m_varList[MAX_VAR];   // Variable List
 unsigned int m_amountVarList = 0;           // Amount of variable list
 
+#ifdef LED_SDCARD
+DigitalOut ledStatus(LED_SDCARD);
+#else
+DigitalOut ledStatus(NC);
+#endif
+
 /* ###############  Static function prototype  ################## */
 
 static void FileManager_RemoveSpaces(char* s , int size);
 static void FileManager_GetXmlText(char *str, char *ret);
 static void FileManager_GenerateFileNameWithTime(time_t timestamp, char * file_name);
-
+static void FileManager_SetLedStatus(bool on);
 
 /**
  * @brief Utility function to Remove space charector from given char array
@@ -113,6 +119,9 @@
     if (fp == NULL) {  
         /* In case of error, print the message */
         printf("\nError! Unable to open file! %s \n", SETUP_FILE_NAME);
+        
+        /* Indicate LED Status (OFF)*/
+        FileManager_SetLedStatus(false);
     } else { 
 
         /* Initialized state */
@@ -121,6 +130,9 @@
         /* Allocate buffer for reading file */
         char buf[1024];
         
+        /* Indicate LED Status (ON)*/
+        FileManager_SetLedStatus(true);
+        
         /* Read line from the file */
         while (fgets(buf, sizeof(buf), fp) != NULL) {
             
@@ -188,8 +200,15 @@
     {  
         /* if it can't open the file then print error message */
         printf("Error! Unable to open file %s!\n",file_name);
+        
+        /* Indicate LED Status (OFF)*/
+        FileManager_SetLedStatus(false);
     } 
-    else {  
+    else 
+    {  
+        /* Indicate LED Status (ON)*/
+        FileManager_SetLedStatus(true);
+        
         /* Print some message for information */
         printf("\r\n Writing to Gps Log File (%s)....",file_name);
 
@@ -228,9 +247,15 @@
     {  
         /* In case of error, print the error message */
         printf("Error! Unable to open file %s!\n",file_name);
+        
+        /* Indicate LED Status (OFF)*/
+        FileManager_SetLedStatus(false);
     } 
     else
     {  
+        /* Indicate LED Status (ON)*/
+        FileManager_SetLedStatus(true);
+        
         /* Print some message for information */
         printf("\r\n Writing to Log File (%s)....",file_name);
 
@@ -274,16 +299,22 @@
     {  
         /* In case of error, print the error message */
         printf("Error! Unable to open file %s!\n",file_name);
+        
+        /* Indicate LED Status (OFF)*/
+        FileManager_SetLedStatus(false);
     } 
     else 
     {  
+        /* Indicate LED Status (ON)*/
+        FileManager_SetLedStatus(true);
+        
         /* opened file so can write */
         printf("\r\n Writing to Log File (%s)....",file_name);
 
         /* Write the header to the file  */
         fprintf(fp, "%s",RMS_HEADER_TIME);
         
-        fprintf(fp, "%s",RMS_MSECOND);
+        fprintf(fp, "%s",RMS_HEADER_MSECOND);
         for(int i = 0; i < m_amountVarList; i++)
         {
             fprintf(fp, ",%s",m_varList[i].varName); 
@@ -311,9 +342,15 @@
     if (fp == NULL) {  
         /* In case of error, print the msg */
         printf("Error! Unable to open file!\n");
+        
+        /* Indicate LED Status (OFF)*/
+        FileManager_SetLedStatus(false);
     } 
     else 
     {
+        /* Indicate LED Status (ON)*/
+        FileManager_SetLedStatus(true);
+        
         /* Write some message, which is TBD */    
         fprintf(fp, "\nStart Mini-RMS System with Gps Interval = %f",gps_interval); 
         fclose(fp);  // ensure you close the file after writing
@@ -390,11 +427,15 @@
     {  
         /* if it can't open the file then print error message */ 
         printf("\nError! Unable to open file! %s \n", VARIABLE_FILE_NAME);
+        /* Indicate LED Status (OFF)*/
+        FileManager_SetLedStatus(false);
+        
         return NULL;
     } 
     else 
     {  
-        /* opened file so can write */ 
+        /* Indicate LED Status (ON)*/
+        FileManager_SetLedStatus(true);
 
         /* Allocate buffer for reading  */
         char buf[1024];
@@ -475,5 +516,17 @@
 {
     return m_varList;
 }
+/**
+ * @brief Utility to play with LED status
+ * @note  Libary user need to assign proper PinName to LED_SDCARD
+ * @param on  - True for turning LED ON, otherwise LED off
+ * @retval None
+ */
+static void FileManager_SetLedStatus(bool on)
+{
+    if (ledStatus.is_connected())
+    {
+        ledStatus = on;
+    } 
+}
 
-