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
Revision 6:a05ec997c496, committed 2016-05-09
- Comitter:
- Lucyjungz
- Date:
- Mon May 09 09:31:44 2016 +0000
- Parent:
- 5:07aaa6e3784c
- Child:
- 7:ffaa90a12f00
- Commit message:
- Formatted Code
Changed in this revision
--- a/FileManager.cpp Mon May 09 09:02:56 2016 +0000
+++ b/FileManager.cpp Mon May 09 09:31:44 2016 +0000
@@ -15,15 +15,14 @@
char* cpy = s; // an alias to iterate through s without moving s
char* temp = s;
- for (int i = 0 ; i < size ; i++)
- {
+ 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);
@@ -31,25 +30,19 @@
bool begin_text = false;
char * ret_addr = ret;
memset (ret,' ',XMLTEXT_SIZE);
-
- for(i = 0; i < size ; i++)
- {
-
- if (*str == '>')
- {
+
+ for(i = 0; i < size ; i++) {
+
+ if (*str == '>') {
begin_text = true;
- }
- else if (begin_text && *str == '<')
- {
+ } else if (begin_text && *str == '<') {
begin_text = false;
break;
- }
- else if (begin_text && *str != ' ')
- {
+ } else if (begin_text && *str != ' ') {
*ret = *str;
ret++;
}
-
+
str++;
}
removeSpaces(ret_addr, XMLTEXT_SIZE);
@@ -67,34 +60,25 @@
ReadingFileState state = STATE_FINDING;
char buf[1024];
- while (fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (strstr (buf,DATA_TAG))
- {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ if (strstr (buf,DATA_TAG)) {
state = STATE_FOUND_DATA;
- }
- else if (strstr (buf,GPS_TAG))
- {
+ } else if (strstr (buf,GPS_TAG)) {
state = STATE_FOUND_GPS;
- }
- else if (strstr (buf,UPDATE_INTERVAL_TAG))
- {
- if (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)
- {
+ } 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[])
{
@@ -109,19 +93,19 @@
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[])
{
@@ -158,30 +142,28 @@
char buf[1024];
int index = 0;
memset(m_varList, ' ', sizeof(m_varList));
- while (fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (strstr (buf,VAR_NAME_TAG))
- {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ if (strstr (buf,VAR_NAME_TAG)) {
getXmlText(buf , m_varList[index].varName);
-
- }
- else if (strstr (buf,VAR_ADDR_TAG))
- {
+
+ } else if (strstr (buf,VAR_ADDR_TAG)) {
getXmlText(buf , m_varList[index].varAddress);
index++;
}
- }
+ }
fclose(fp); // ensure you close the file after reading
m_amountVarList = index;
return m_varList;
- }
+ }
}
-int getAmountVarList(){
+int getAmountVarList()
+{
return m_amountVarList;
-}
-Variable_Data_TypeDef * getVarList(){
+}
+Variable_Data_TypeDef * getVarList()
+{
return m_varList;
-}
+}
-
+
--- a/FileManager.h Mon May 09 09:02:56 2016 +0000
+++ b/FileManager.h Mon May 09 09:31:44 2016 +0000
@@ -15,19 +15,18 @@
#define MAX_VAR 50
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;
+ 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;
-typedef struct
-{
+typedef struct {
char varName[VAR_NAME_MAX_SIZE];
char varAddress[VAR_ADDR_MAX_SIZE+1];
-} Variable_Data_TypeDef;
+} Variable_Data_TypeDef;
void readSetupFile();
void delete_file(char filename[]);
--- a/GPSGms6.cpp Mon May 09 09:02:56 2016 +0000
+++ b/GPSGms6.cpp Mon May 09 09:31:44 2016 +0000
@@ -13,131 +13,113 @@
bool m_available;
int m_index;
Serial serial_gps(PA_9, PA_10);
-GPRMC_Tbl_TypeDef gprms_tbl[] =
+GPRMC_Tbl_TypeDef gprms_tbl[] = {
+ // index , section size , variable
+ {GPS_Process_Start , INVALID_VALUE ,(char *)INVALID_VALUE},
+ {GPS_Process_Header , HEADER_SIZE , m_gprmc.header},
+ {GPS_Process_Time , GPRMC_TIME_SIZE , m_gprmc.time},
+ {GPS_Process_Status , GPRMC_STATUS_SIZE , m_gprmc.status},
+ {GPS_Process_Latitude , GPRMC_LATITUDE_SIZE , m_gprmc.latitude},
+ {GPS_Process_Latitude_hemis , GPRMC_LATITUDE_HEMI_SIZE , m_gprmc.latitude_hemi},
+ {GPS_Process_Longitude , GPRMC_LONGITUDE_SIZE , m_gprmc.longitude},
+ {GPS_Process_Longitude_hemis , GPRMC_LONGITUDE_HEMI_SIZE , m_gprmc.longitude_hemi},
+ {GPS_Process_Speed , GPRMC_SPEED_SIZE , m_gprmc.speed},
+ {GPS_Process_Course , GPRMC_COURSE_SIZE , m_gprmc.course},
+ {GPS_Process_Date , GPRMC_DATE_SIZE , m_gprmc.date},
+ {GPS_Process_Magnetic , GPRMC_MAGNETIC_SIZE , m_gprmc.magnetic},
+ {GPS_Process_Magnetic_Dir , GPRMC_MAGNETIC_DIR_SIZE , m_gprmc.magnetic_dir},
+ {GPS_Process_Indicator , GPRMC_INDICATOR_SIZE , m_gprmc.indicator},
+ {GPS_Process_Complete ,INVALID_VALUE ,(char *)INVALID_VALUE}
+
+};
+static GPS_ProcessStatus GPS_ProcessGprmcSection(GPS_ProcessState state,char * buf , unsigned int buf_index,unsigned int buf_size, unsigned int section_size, char * ret_value)
{
- // index , section size , variable
- {GPS_Process_Start , INVALID_VALUE ,(char *)INVALID_VALUE},
- {GPS_Process_Header , HEADER_SIZE , m_gprmc.header},
- {GPS_Process_Time , GPRMC_TIME_SIZE , m_gprmc.time},
- {GPS_Process_Status , GPRMC_STATUS_SIZE , m_gprmc.status},
- {GPS_Process_Latitude , GPRMC_LATITUDE_SIZE , m_gprmc.latitude},
- {GPS_Process_Latitude_hemis , GPRMC_LATITUDE_HEMI_SIZE , m_gprmc.latitude_hemi},
- {GPS_Process_Longitude , GPRMC_LONGITUDE_SIZE , m_gprmc.longitude},
- {GPS_Process_Longitude_hemis , GPRMC_LONGITUDE_HEMI_SIZE , m_gprmc.longitude_hemi},
- {GPS_Process_Speed , GPRMC_SPEED_SIZE , m_gprmc.speed},
- {GPS_Process_Course , GPRMC_COURSE_SIZE , m_gprmc.course},
- {GPS_Process_Date , GPRMC_DATE_SIZE , m_gprmc.date},
- {GPS_Process_Magnetic , GPRMC_MAGNETIC_SIZE , m_gprmc.magnetic},
- {GPS_Process_Magnetic_Dir , GPRMC_MAGNETIC_DIR_SIZE , m_gprmc.magnetic_dir},
- {GPS_Process_Indicator , GPRMC_INDICATOR_SIZE , m_gprmc.indicator},
- {GPS_Process_Complete ,INVALID_VALUE ,(char *)INVALID_VALUE}
-
-};
-static GPS_ProcessStatus GPS_ProcessGprmcSection(GPS_ProcessState state,char * buf , unsigned int buf_index,unsigned int buf_size, unsigned int section_size, char * ret_value){
GPS_ProcessStatus status = GPS_Status_Valid;
- if (buf_index >= (buf_size - section_size)){
+ if (buf_index >= (buf_size - section_size)) {
status = GPS_Status_NotEnough;
- }
- else if (buf[buf_index] == ','){
+ } else if (buf[buf_index] == ',') {
status = GPS_Status_Empty;
memset(ret_value,' ', section_size);
- }
- else{
+ } else {
unsigned int idx;
// printf("\r\n state = %d =",state);
- for(idx = 0;idx < section_size;idx++)
- {
+ for(idx = 0; idx < section_size; idx++) {
ret_value[idx] = buf[buf_index + idx];
}
}
return status;
-
+
}
-static void GPS_ProcessGpsData(char * buf, unsigned int size){
- unsigned int index;
+static void GPS_ProcessGpsData(char * buf, unsigned int size)
+{
+ unsigned int index;
unsigned int adv_index = 0;
GPS_ProcessStatus status = GPS_Status_Valid;
GPS_ProcessState state = GPS_Process_Start;
- for(index = 0; index < size;index++)
- {
- if (state == GPS_Process_Start)
- {
- if (buf[index] == '$')
- {
+ for(index = 0; index < size; index++) {
+ if (state == GPS_Process_Start) {
+ if (buf[index] == '$') {
state = GPS_Process_Header;
- }
- else
- {
+ } else {
continue;
}
- }
- else if (state == GPS_Process_Header)
- {
- if (index < (size - HEADER_SIZE))
- {
- if (buf[index] == 'G' &&
- buf[index+1] == 'P' &&
- buf[index+2] == 'R' &&
- buf[index+3] == 'M' &&
+ } else if (state == GPS_Process_Header) {
+ if (index < (size - HEADER_SIZE)) {
+ if (buf[index] == 'G' &&
+ buf[index+1] == 'P' &&
+ buf[index+2] == 'R' &&
+ buf[index+3] == 'M' &&
buf[index+4] == 'C'
- ){
+ ) {
unsigned int h_index;
- for(h_index = 0;h_index < HEADER_SIZE;h_index++)
- {
+ for(h_index = 0; h_index < HEADER_SIZE; h_index++) {
m_gprmc.header[h_index] = buf[index + h_index];
}
index += HEADER_SIZE;
state = GPS_Process_Time;
}
- }
- else
- {
+ } else {
break;
}
-
- }
- else
- {
+
+ } else {
status = GPS_ProcessGprmcSection(state, buf ,index, size, GET_GPRMC_SECTION_SIZE(state), GET_GPRMC_VARIABLE_ADDR(state));
adv_index = GET_GPRMC_SECTION_SIZE(state);
state = GET_GPRMC_NEXT_STATE(state) ;
}
-
- if (status == GPS_Status_NotEnough || state == GPS_Process_Complete)
- {
+
+ if (status == GPS_Status_NotEnough || state == GPS_Process_Complete) {
break;
- }
- else if (status == GPS_Status_Valid)
- {
+ } else if (status == GPS_Status_Valid) {
index += adv_index;
}
}
-
- if (m_gprmc.indicator[0] == (char)'A' &&
+
+ if (m_gprmc.indicator[0] == (char)'A' &&
m_gprmc.indicator[0] == (char)'D' &&
- m_gprmc.indicator[0] == (char)'E'
- )
- {
+ m_gprmc.indicator[0] == (char)'E'
+ ) {
m_available= true;
memcpy(&m_valid_gprmc, &m_gprmc , sizeof(m_gprmc));
}
}
-void complete_callback() {
- GPS_ProcessGpsData(m_RxBuf, RX_BUF_SIZE);
+void complete_callback()
+{
+ GPS_ProcessGpsData(m_RxBuf, RX_BUF_SIZE);
}
-void byte_callback() {
+void byte_callback()
+{
// Note: you need to actually read from the serial to clear the RX interrupt
//printf("%c", gps.getc());
m_RxBuf[m_index] = serial_gps.getc();
//printf("%c", m_RxBuf[m_index]);
m_index++;
- if (m_index == RX_BUF_SIZE)
- {
+ if (m_index == RX_BUF_SIZE) {
m_index = 0;
complete_callback();
}
@@ -145,12 +127,12 @@
}
GPSGms6::GPSGms6()
{
-
+
m_index = 0;
m_available = false;
-
+
serial_gps.baud(9600);
-
+
}
void GPSGms6::start_GPS()
{
--- a/GPSGms6.h Mon May 09 09:02:56 2016 +0000
+++ b/GPSGms6.h Mon May 09 09:31:44 2016 +0000
@@ -17,8 +17,7 @@
#define INVALID_VALUE 0xFFFF
#define RX_BUF_SIZE 100
-typedef struct
-{
+typedef struct {
char header[HEADER_SIZE+1];
char time[GPRMC_TIME_SIZE+1];
char status[GPRMC_TIME_SIZE+1];
@@ -32,10 +31,9 @@
char magnetic[GPRMC_MAGNETIC_SIZE+1];
char magnetic_dir[GPRMC_MAGNETIC_DIR_SIZE+1];
char indicator[GPRMC_INDICATOR_SIZE+1];
-} GPRMC_Data_TypeDef;
+} GPRMC_Data_TypeDef;
-typedef enum GPS_ProcessState
-{
+typedef enum GPS_ProcessState {
GPS_Process_Start = 0,
GPS_Process_Header,
GPS_Process_Time,
@@ -54,26 +52,24 @@
GPS_Process_SIZE
} GPS_ProcessState;
-typedef enum GPS_ProcessStatus
-{
+typedef enum GPS_ProcessStatus {
GPS_Status_Valid,
GPS_Status_Empty,
GPS_Status_NotEnough,
} GPS_ProcessStatus;
-typedef struct
-{
+typedef struct {
GPS_ProcessState state;
int size;
char * p_val;
-} GPRMC_Tbl_TypeDef;
+} GPRMC_Tbl_TypeDef;
-class GPSGms6
+class GPSGms6
{
public:
-
+
GPSGms6();
void start_GPS();
@@ -90,7 +86,7 @@
* Valid Data Interval
*/
GPRMC_Data_TypeDef validGPRMC();
-
+
/** Get availability of gprmc
*
* @returns
@@ -102,13 +98,13 @@
private:
// States
-
+
//Member variables
-
-
-
+
+
+
//void GPS_ProcessGpsData(char * buf, unsigned int size, char * t, char * d);
//GPS_ProcessStatus GPS_ProcessGprmcSection(GPS_ProcessState state,char * buf , unsigned int buf_index,unsigned int buf_size, unsigned int section_size, char * ret_value);
-
+
};
\ No newline at end of file
--- a/main.cpp Mon May 09 09:02:56 2016 +0000
+++ b/main.cpp Mon May 09 09:31:44 2016 +0000
@@ -1,15 +1,3 @@
-/* 2545_SD_Card Example
-
-Example of writing data to SD card.
-
-Based on FTF2014_lab4 Example
-
-https://developer.mbed.org/teams/Freescale/wiki/FTF2014_workshop
-
-Craig A. Evans, University of Leeds, Mar 2016
-
-*/
-
#include "mbed.h"
#include "SDFileSystem.h"
#include "GPSGms6.h"
@@ -26,9 +14,9 @@
float gps_interval = 3;
-void t1out(void)
-{
- myled = !myled;
+void t1out(void)
+{
+ myled = !myled;
printf("\r\nGps header = %s", gps.latestGPRMC().header);
printf("\r\nGps status = %s", gps.latestGPRMC().status);
printf("\r\nGps time = %s", gps.latestGPRMC().time);
@@ -36,7 +24,7 @@
printf("\r\nGps lat = %s", gps.latestGPRMC().latitude);
printf("\r\nGps long = %s", gps.latestGPRMC().longitude);
printf("\r\nGps indicator = %s", gps.latestGPRMC().indicator);
-
+
logGPSData( gps.latestGPRMC().date, gps.latestGPRMC().time);
serial.printf("\r\n#### Restart Timer #####");
t1.attach(&t1out,gps_interval);
@@ -51,17 +39,16 @@
////////////////////// read Setup File //////////////////////////
readSetupFile();
gps_interval = (float)GPSInterval()/1000;
-
+
Variable_Data_TypeDef * var_list = readVarFile();
logSystemData(gps_interval);
-
+
unsigned int amount = getAmountVarList();
- for (int i = 0; i < amount ; i++)
- {
+ for (int i = 0; i < amount ; i++) {
serial.printf("\r\n var name = %s ",var_list[i].varName);
serial.printf("\r\n first addr name = %s ",var_list[i].varAddress);
}
-
+
///////////////////////////////////////////////////
serial.printf("\n End of SD Card Initialization ");
gps.start_GPS();
