Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Revision:
7:872984a67d5b
Parent:
6:6d1683c8b26b
Child:
8:d6287c33b54a
--- 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