Lucy Luz / Mbed 2 deprecated RwSDCard_Xml_GPS

Dependencies:   FileManager GPSGms6 SDFileSystem mbed

Fork of 2545_SD_Card by Craig Evans

Revision:
2:c96b02fcb98e
Child:
4:aa7ac2ac6913
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FileManager.cpp	Fri May 06 20:16:30 2016 +0000
@@ -0,0 +1,144 @@
+#include "FileManager.h"
+#include "SDFileSystem.h"
+
+char m_GpsInterval[XMLTEXT_SIZE];
+char m_DataInterval[XMLTEXT_SIZE];
+
+static void removeSpaces(char* s , int size);
+static void getXmlText(char *str, char *ret);
+
+
+static void removeSpaces(char* s , int size)
+{
+    char* cpy = s;  // an alias to iterate through s without moving s
+    char* temp = s;
+
+    for (int i = 0 ; i < size ; i++)
+    {
+        if (*cpy != ' ')
+            *temp++ = *cpy;
+        cpy++;
+    }
+    *temp = 0;
+    return;
+}    
+static void getXmlText(char *str, char *ret)
+{
+    int size = strlen(str);
+    int i;
+    bool begin_text = false;
+    char * ret_addr = ret;
+    memset (ret,' ',XMLTEXT_SIZE);
+    
+    for(i = 0; i < size ; i++)
+    {
+        
+        if (*str == '>')
+        {
+            begin_text = true;
+        }
+        else if (begin_text && *str == '<')
+        {
+            begin_text = false;
+            break;
+        }
+        else if (begin_text && *str != ' ')
+        {
+            *ret = *str;
+            ret++;
+        }
+        
+        str++;
+    }
+    removeSpaces(ret_addr, XMLTEXT_SIZE);
+}
+void readSetupFile()
+{
+    // now open file for reading
+    FILE *fp = fopen(SETUP_FILE_NAME, "r");
+
+    if (fp == NULL) {  // if it can't open the file then print error message
+        printf("\nError! Unable to open file! %s \n", SETUP_FILE_NAME);
+    } else {  // opened file so can write
+//        fscanf(fp, "%d",&stored_top_score); // ensure data type matches - note address operator (&)
+//        serial.printf("Read %d from file.\n",stored_top_score);
+
+        ReadingFileState  state = STATE_FINDING;
+        char buf[1024];
+        while (fgets(buf, sizeof(buf), fp) != NULL)
+        {
+            if (strstr (buf,DATA_TAG))
+            {
+                state = STATE_FOUND_DATA;
+            }
+            else if (strstr (buf,GPS_TAG))
+            {
+                state = STATE_FOUND_GPS;
+            }
+            else if (strstr (buf,UPDATE_INTERVAL_TAG))
+            {
+                if (state == STATE_FOUND_GPS)
+                {
+                    getXmlText(buf, m_GpsInterval);
+                    printf("\r\n-found GPS interval %s ", m_GpsInterval);
+                    state = STATE_FINDING;
+                }
+                else if(state == STATE_FOUND_DATA)
+                {
+                    getXmlText(buf, m_DataInterval);
+                    printf("\r\n-found Data interval %s ", m_DataInterval);
+                    state = STATE_FINDING;
+                }
+            }
+        } 
+        fclose(fp);  // ensure you close the file after reading
+    }   
+}
+void logGPSData(char date[], char time[])
+{
+    FILE *fp  = fopen(GPS_LOG_FILE_NAME, "a");
+
+    if (fp == NULL) {  // if it can't open the file then print error message
+        printf("Error! Unable to open file!\n");
+    } else {  // opened file so can write
+        printf("\n Writing to Gps Log File....");
+
+        fprintf(fp, "%s,%s\n",date,time);  // print formatted string to file (CSV)
+
+        printf("Done");
+        fclose(fp);  // ensure you close the file after writing
+    }    
+}
+void logSystemData(float gps_interval)
+{
+    FILE *fp = fopen(MINIRMS_LOG_FILE_NAME, "a");
+
+    
+    if (fp == NULL) {  // if it can't open the file then print error message
+        printf("Error! Unable to open file!\n");
+    } else {  // opened file so can write
+        fprintf(fp, "Start Mini-RMS System with Gps Interval = %f",gps_interval); // ensure data type matches
+        fclose(fp);  // ensure you close the file after writing
+    }  
+}
+void delete_file(char filename[])
+{
+    printf("Deleting file '%s'...",filename);
+    FILE *fp = fopen(filename, "r");  // try and open file
+    if (fp != NULL) {  // if it does open...
+        fclose(fp);    // close it
+        remove(filename);  // and then delete
+        printf("Done!\n");
+    }
+    // if we can't open it, it doesn't exist and so we can't delete it
+}
+int GPSInterval()
+{
+    //Return whether or not CRC is enabled
+    return atoi( m_GpsInterval );
+}
+int DataInterval()
+{
+    //Return whether or not CRC is enabled
+    return atoi( m_DataInterval );
+}
\ No newline at end of file