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: mbed WDT MODSERIAL BME280
Revision 7:872984a67d5b, committed 2017-03-15
- Comitter:
- MAA
- Date:
- Wed Mar 15 13:56:53 2017 +0000
- Parent:
- 6:6d1683c8b26b
- Child:
- 8:d6287c33b54a
- Commit message:
- ERR og ERRS tilf?jet til SPS klassen.; ; Filnavn?ndring ved dato?ndring i GPRMC streng tilf?jet.
Changed in this revision
--- a/SPS/SPS.cpp Thu Mar 09 15:26:22 2017 +0000
+++ b/SPS/SPS.cpp Wed Mar 15 13:56:53 2017 +0000
@@ -20,8 +20,6 @@
memset(checkSum,'\0',5);
unsigned short chkSum = 0;
- //dbg->printf("Commencing sps line generation\r\n");
- //create current string
addToCurrentString(LINESTART);
addToCurrentString(tag);
addToCurrentString(SPACE);
@@ -92,6 +90,69 @@
};
+//Updates current ERR string
+void SPS::UpdateCurrentErrString(string tag, string identifier_id, string group_id, string date, string time, string ZZZ,string s1, string source_id, string interpreter_id, string data_line_version, string source_firmware_version, string interpreter_firmware_version, string latitude, string longitude, bool gpsFixFlag, string mag_time, string mag_nt, string mag_sq, Serial * dbg){
+
+ currentErrString = "";
+ currentErrString.resize(256);
+ char checkSum[5];
+ memset(checkSum,'\0',5);
+ unsigned short chkSum = 0;
+
+ addToCurrentErrString(LINESTART);
+ addToCurrentErrString(tag);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(identifier_id);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(group_id);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(date);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(time);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString("ZZZ");
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(HEADEREND);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(s1);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(source_id);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(interpreter_id);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(data_line_version);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(source_firmware_version);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(interpreter_firmware_version);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(HEADEREND);
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString("BMAG");
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString("C02");
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString("C03");
+
+ //calculate checksum
+ for(int i = 0; i < strlen(currentString.c_str()); i++){
+ if(currentString[i] != '>' || currentString[i] != '<'){
+
+ chkSum = update_crc_16(chkSum, currentErrString[i]);
+
+ }
+ }
+
+ sprintf(checkSum, "%04X", chkSum);
+
+ //append rest of string
+ addToCurrentErrString(SPACE);
+ addToCurrentErrString(checkSum);
+ addToCurrentErrString(LINESTOP);
+
+
+};
+
//Fills the array for calculation of the CRC-16 with values
void SPS::init_crc16_tab()
{
@@ -173,16 +234,45 @@
currentString[currentStartIndex] = data;
};
+//add data to current Errstring
+void SPS::addToCurrentErrString(string data){
+ int currentStartIndex = strlen(currentErrString.c_str());
+ char dataStrLen = 0;
+ dataStrLen = strlen(data.c_str());
+
+ for(int i = 0; i < dataStrLen; i++){
+ currentErrString[currentStartIndex+i] = data[i];
+ }
+
+};
+void SPS::addToCurrentErrString(char data){
+ int currentStartIndex = strlen(currentErrString.c_str());
+ currentErrString[currentStartIndex] = data;
+
+};
+
void SPS::generateSpsFilename(string formattedDate){
- fileNameString = "";
+ fileNameString.resize(25);
- fileNameString.append("/usb/BMAG_");
+ fileNameString.replace(0, 10, "/usb/BMAG_");
- fileNameString.append(formattedDate);
+ fileNameString[10] = formattedDate[0];
+ fileNameString[11] = formattedDate[1];
+ fileNameString[12] = formattedDate[2];
+ fileNameString[13] = formattedDate[3];
+ fileNameString[14] = '-';
+ fileNameString[15] = formattedDate[5];
+ fileNameString[16] = formattedDate[6];
+ fileNameString[17] = '-';
+ fileNameString[18] = formattedDate[8];
+ fileNameString[19] = formattedDate[9];
- fileNameString.append(".sps");
+ fileNameString[20] = '.';
+ fileNameString[21] = 's';
+ fileNameString[22] = 'p';
+ fileNameString[23] = 's';
};
@@ -191,4 +281,9 @@
return this->fileNameString;
+};
+
+//Gets / returns current sps err string
+string SPS::getCurrentErrString(void){
+ return this->currentErrString;
};
\ No newline at end of file
--- a/SPS/SPS.h Thu Mar 09 15:26:22 2017 +0000
+++ b/SPS/SPS.h Wed Mar 15 13:56:53 2017 +0000
@@ -17,6 +17,9 @@
//Updates current string
void UpdateCurrentString(string tag, string identifier_id, string group_id, string date, string time, string ZZZ,string s1, string source_id, string interpreter_id, string data_line_version, string source_firmware_version, string interpreter_firmware_version, string latitude, string longitude, bool gpsFixFlag, string mag_time, string mag_nt, string mag_sq, Serial * dbg);
+
+ //Updates current ERR
+ void UpdateCurrentErrString(string tag, string identifier_id, string group_id, string date, string time, string ZZZ,string s1, string source_id, string interpreter_id, string data_line_version, string source_firmware_version, string interpreter_firmware_version, string latitude, string longitude, bool gpsFixFlag, string mag_time, string mag_nt, string mag_sq, Serial * dbg);
//Fills the array for calculation of the CRC-16 with values
void init_crc16_tab();
@@ -28,6 +31,9 @@
//Gets / returns current sps data string
string getCurrentString(void);
+ //Gets / returns current sps err string
+ string getCurrentErrString(void);
+
//get headerstring
string getHeaderString(void);
@@ -41,6 +47,10 @@
void addToCurrentString(string data);
void addToCurrentString(char data);
+ //add data to current Errstring
+ void addToCurrentErrString(string data);
+ void addToCurrentErrString(char data);
+
//generate sps filename
void generateSpsFilename(string formattedDate);
--- a/main.cpp Thu Mar 09 15:26:22 2017 +0000
+++ b/main.cpp Wed Mar 15 13:56:53 2017 +0000
@@ -7,6 +7,9 @@
bool GGA_Fix_Present = false;
bool firstLineWritten = false;
bool fileNameUpdated = false;
+bool lastErrStatus = true;
+bool firstErrsWritten = false;
+
//global system variables
bool run = true;
@@ -18,7 +21,8 @@
bool writeToUsb(string line, FILE * f);
int main(void){
- //initializing watchdog
+
+ //initializing watchdog, timeout 10 seconds
Watchdog wd;
wd.init(10.0);
@@ -57,7 +61,8 @@
//Start comms with the GPS, Enabling GPRMC and GPGGA
gps.printf("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n");
- dbg.printf("Init.... Done!\r\n");
+ dbg.printf("Init.... Done!\r\n");
+
//infinite loop running after initialization
while(run) {
@@ -66,6 +71,7 @@
gps.rxBufferFlush();
}
+
if(GPS_Data_Rdy){
//update filename when date is available with gga fix
@@ -78,10 +84,19 @@
fopen(currentFilename.c_str(), "a");
- fileNameUpdated = true;
+ fileNameUpdated = true;
+
+ //add header to top of file
+ writeToUsb(spsGen.getHeaderString(), fp);
}
+ //if date has changed, ensure new file creation.
+ spsGen.generateSpsFilename(gpsNMEA.currentDATEFromGPRMC);
+ if(currentFilename != spsGen.getSpsFileName()){
+ fileNameUpdated = false;
+ }
+
gps.scanf("%s", &tmpGpsRxString);
//copy c_string to string
@@ -105,6 +120,9 @@
//Get gga fix flag
GGA_Fix_Present = gpsNMEA.GGAFixVerification();
+ //Assign value to error flag
+ spsGen.setErrStatus(GGA_Fix_Present);
+
//Clearing RX buffer.
GPS_String_Buff = "";
GPS_String_Buff.resize(128);
@@ -122,15 +140,21 @@
//clearing flags
GPS_Data_Valid = false;
GPS_Data_Rdy = false;
-
-
- if(GGA_Fix_Present){
+
+ if(!GGA_Fix_Present){
- spsGen.UpdateCurrentString(TAG, IDENTIFIERID, GROUP, gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, TIMEZONE, ENCODING, SOURCEIDENTIFICATION, INTERPRETERID, DATALINEVERSION, FWSRCVERSION, FWIVERSION, gpsNMEA.currentLatitude, gpsNMEA.currentLongitude, GGA_Fix_Present, "magtime", "mag_nt", "mag_sq", &dbg);
-
+ spsGen.UpdateCurrentString(TAG, IDENTIFIERID, GROUP, gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, TIMEZONE, ENCODING, SOURCEIDENTIFICATION, INTERPRETERID, DATALINEVERSION, FWSRCVERSION, FWIVERSION, gpsNMEA.currentLatitude, gpsNMEA.currentLongitude, GGA_Fix_Present, "magtime", "mag_nt", "mag_sq", &dbg);
+
//write data strings to sps file
if(firstLineWritten){
- writeToUsb(spsGen.getCurrentString(), fp);
+ writeToUsb(spsGen.getCurrentString(), fp);
+
+ if(lastErrStatus && !firstErrsWritten){
+ spsGen.UpdateCurrentErrString("ERRS", IDENTIFIERID, GROUP, gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, TIMEZONE, ENCODING, SOURCEIDENTIFICATION, INTERPRETERID, DATALINEVERSION, FWSRCVERSION, FWIVERSION, gpsNMEA.currentLatitude, gpsNMEA.currentLongitude, GGA_Fix_Present, "magtime", "mag_nt", "mag_sq", &dbg);
+ writeToUsb(spsGen.getCurrentErrString(), fp);
+ firstErrsWritten = true;
+ lastErrStatus = false;
+ }
}
if(!firstLineWritten){
@@ -138,7 +162,34 @@
writeToUsb(spsGen.getCurrentString(), fp);
firstLineWritten = true;
}
- }
+ }
+
+
+ if(GGA_Fix_Present){
+
+ spsGen.UpdateCurrentString(TAG, IDENTIFIERID, GROUP, gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, TIMEZONE, ENCODING, SOURCEIDENTIFICATION, INTERPRETERID, DATALINEVERSION, FWSRCVERSION, FWIVERSION, gpsNMEA.currentLatitude, gpsNMEA.currentLongitude, GGA_Fix_Present, "magtime", "mag_nt", "mag_sq", &dbg);
+
+ //write data strings to sps file
+ if(firstLineWritten){
+ writeToUsb(spsGen.getCurrentString(), fp);
+
+ if(!lastErrStatus){
+ spsGen.UpdateCurrentErrString("ERRE", IDENTIFIERID, GROUP, gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, TIMEZONE, ENCODING, SOURCEIDENTIFICATION, INTERPRETERID, DATALINEVERSION, FWSRCVERSION, FWIVERSION, gpsNMEA.currentLatitude, gpsNMEA.currentLongitude, GGA_Fix_Present, "magtime", "mag_nt", "mag_sq", &dbg);
+ writeToUsb(spsGen.getCurrentErrString(), fp);
+ lastErrStatus = true;
+ firstErrsWritten = false;
+ firstLineWritten = false;
+ }
+ }
+
+ if(!firstLineWritten){
+ writeToUsb(spsGen.getHeaderString(), fp);
+ writeToUsb(spsGen.getCurrentString(), fp);
+ firstLineWritten = true;
+ }
+ }
+
+
}
@@ -153,6 +204,10 @@
//Reopening a file on usb disk
fp = fopen(currentFilename.c_str(), "a");
+
+ writeToUsb("\r\n", fp);
+ writeToUsb(spsGen.getHeaderString(), fp);
+
}
@@ -178,7 +233,7 @@
}
}
-//Write to file prototype
+//Write to file
bool writeToUsb(string line, FILE * f){
if (f != NULL) {
--- a/mbed.bld Thu Mar 09 15:26:22 2017 +0000 +++ b/mbed.bld Wed Mar 15 13:56:53 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90 \ No newline at end of file