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: FileManager GPSGms6 SDFileSystem mbed
Fork of 2545_SD_Card by
Diff: main.cpp
- Revision:
- 2:c96b02fcb98e
- Parent:
- 1:f911149acd35
- Child:
- 3:78eaf4291b84
diff -r f911149acd35 -r c96b02fcb98e main.cpp
--- a/main.cpp Fri May 06 19:30:02 2016 +0000
+++ b/main.cpp Fri May 06 20:16:30 2016 +0000
@@ -13,13 +13,8 @@
#include "mbed.h"
#include "SDFileSystem.h"
#include "GPSGms6.h"
+#include "FileManager.h"
-#define GPS_TAG "<Gps>"
-#define DATA_TAG "<Data>"
-#define UPDATE_INTERVAL_TAG "<Update_Interval>"
-
-
-#define XMLTEXT_SIZE 20
// Connections to SD card holder on K64F (SPI interface)
SDFileSystem sd(PA_7, PA_6, PA_5, PA_0, "sd"); // MOSI, MISO, SCK, CS
@@ -28,16 +23,9 @@
Timeout t1;
DigitalOut myled(LED1);
-char m_GpsInterval[XMLTEXT_SIZE];
-char m_DataInterval[XMLTEXT_SIZE];
-typedef enum {
- STATE_FINDING, /** Finding */
- STATE_FOUND_DATA, /** Found Data tag */
- STATE_FOUND_DATA_INTERVAL, /**< Found update internal of tag*/
- STATE_FOUND_GPS, /** Found GPS tag */
- STATE_FOUND_GPS_INTERVAL, /** Found update internal of GPS*/
-}ReadingFileState;
-void delete_file(char filename[]);
+float gps_interval = 3;
+
+
void t1out(void)
{
myled = !myled;
@@ -48,63 +36,18 @@
printf("\r\nGps lat = %s", gps.latestGPRMC().latitude);
printf("\r\nGps long = %s", gps.latestGPRMC().longitude);
printf("\r\nGps indicator = %s", gps.latestGPRMC().indicator);
- t1.attach(&t1out,5);
+
+ logGPSData( gps.latestGPRMC().date, gps.latestGPRMC().time);
+ serial.printf("\n#### Restart Timer #####");
+ t1.attach(&t1out,gps_interval);
}
-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;
-}
-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);
-}
int main()
{
serial.baud(9600); // full-speed!
- serial.printf("#### SD Card Example #####\n");
- FILE *fp; // this is our file pointer
+ serial.printf("\n#### SD Card Initialization #####");
wait(1);
- // Various examples below - can comment out ones you don't need
-
- /////////////////////// Deleting file example ////////////////////////
-
// comment this line out if you don't want to delete the file!
delete_file("/sd/test.txt");
@@ -114,96 +57,19 @@
// if it does. If you wish to add a score onto a list, then you can
// append instead 'a'. This will open the file if it exists and start
// writing at the end. It will create the file if it doesn't exist.
- fp = fopen("/sd/topscore.txt", "w");
- int top_score = 56; // random example
- if (fp == NULL) { // if it can't open the file then print error message
- serial.printf("Error! Unable to open file!\n");
- } else { // opened file so can write
- serial.printf("Writing to file....");
- fprintf(fp, "%d",top_score); // ensure data type matches
- serial.printf("Done.\n");
- fclose(fp); // ensure you close the file after writing
- }
-
- ////////////////////// Simple reading example //////////////////////////
-
- // now open file for reading
- fp = fopen("/sd/RMS_Tester.xml", "r");
-
- if (fp == NULL) { // if it can't open the file then print error message
- serial.printf("Error! Unable to open file!\n");
- } 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
- }
-
- ///////////////////// Writing list to file example //////////////////////
-
- // for this example, I'll create some numbers to write to file in a big list
- // a data logger for example will usually append to a file - at a reading
- // at the end rather than creating a new file
- fp = fopen("/sd/test.txt", "a");
-
- if (fp == NULL) { // if it can't open the file then print error message
- serial.printf("Error! Unable to open file!\n");
- } else { // opened file so can write
- serial.printf("Writing to file....");
- for(int i = 1; i <= 50; i++) {
- float dummy = 1000.0F/i; // dummy variable
- fprintf(fp, "%d,%f\n",i,dummy); // print formatted string to file (CSV)
- }
- serial.printf("Done.\n");
- fclose(fp); // ensure you close the file after writing
- }
+ ////////////////////// read Setup File //////////////////////////
+ readSetupFile();
+ gps_interval = (float)GPSInterval()/1000;
+ logSystemData(gps_interval);
///////////////////////////////////////////////////
- serial.printf("End of SD card example\n");
+ serial.printf("\n End of SD Card Initialization ");
- t1.attach(&t1out,5);
+ t1.attach(&t1out,gps_interval);
while(1);
}
-void delete_file(char filename[])
-{
- serial.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
- serial.printf("Done!\n");
- }
- // if we can't open it, it doesn't exist and so we can't delete it
-}
+
