Bmag incl gps rettelse
Dependencies: mbed WDT MODSERIAL BME280
Diff: SPS/SPS.cpp
- Revision:
- 21:325cb82f1838
- Parent:
- 20:73fa202c73db
- Child:
- 22:9f5955f051f5
diff -r 73fa202c73db -r 325cb82f1838 SPS/SPS.cpp --- a/SPS/SPS.cpp Wed May 10 14:33:20 2017 +0000 +++ b/SPS/SPS.cpp Thu May 11 13:42:32 2017 +0000 @@ -45,8 +45,10 @@ */ void SPS::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 barcode, string latitude, string longitude, bool gpsFixFlag, string batteryvoltage, string mag_time, string mag_nt, string mag_sq, Serial * dbg){ - currentString = ""; - currentString.resize(256); + this->currentString = ""; + this->currentString.resize(256); + + int strLength = 0; char checkSum[5]; memset(checkSum,'\0',5); unsigned short chkSum = 0; @@ -103,17 +105,20 @@ addToCurrentString(SPACE); addToCurrentString(mag_sq); + + strLength = strlen(this->currentString.c_str()); + //calculate checksum - for(int i = 0; i < strlen(currentString.c_str()); i++){ - if(currentString[i] != '>' || currentString[i] != '<'){ + for(int i = 0; i < strLength; i++){ + if(this->currentString[i] != '>'){ - chkSum = update_crc_16(chkSum, currentString[i]); + chkSum = update_crc_16(chkSum, this->currentString[i]); } } sprintf(checkSum, "%04X", chkSum); - + //append rest of string addToCurrentString(SPACE); addToCurrentString(checkSum); @@ -149,8 +154,8 @@ */ 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); + this->currentErrString = ""; + this->currentErrString.resize(256); char checkSum[5]; memset(checkSum,'\0',5); unsigned short chkSum = 0; @@ -191,14 +196,14 @@ addToCurrentErrString("C03"); //calculate checksum - for(int i = 0; i < strlen(currentString.c_str()); i++){ - if(currentString[i] != '>' || currentString[i] != '<'){ + for(int i = 0; i < strlen(this->currentString.c_str()); i++){ + if(this->currentString[i] != '>' || this->currentString[i] != '<'){ - chkSum = update_crc_16(chkSum, currentErrString[i]); + chkSum = update_crc_16(chkSum, this->currentErrString[i]); } } - + sprintf(checkSum, "%04X", chkSum); //append rest of string @@ -251,6 +256,7 @@ if (!crc_tab16_init) init_crc16_tab(); + tmp = crc ^ short_c; crc = (crc >> 8) ^ crc_tab16[tmp & 0xff]; @@ -299,7 +305,7 @@ \param data: string containing data */ void SPS::addToCurrentString(string data){ - int currentStartIndex = strlen(currentString.c_str()); + int currentStartIndex = strlen(this->currentString.c_str()); char dataStrLen = 0; int index = 0; @@ -307,9 +313,9 @@ for(int i = 0; i < dataStrLen; i++){ - if((currentString[currentStartIndex+i] != '\r') || (currentString[currentStartIndex+i] != '\n')){ + if((this->currentString[currentStartIndex+i] != '\r') || (this->currentString[currentStartIndex+i] != '\n')){ - currentString[currentStartIndex+i] = data[index]; + this->currentString[currentStartIndex+i] = data[index]; index += 1; } @@ -322,8 +328,8 @@ \param data: data character */ void SPS::addToCurrentString(char data){ - int currentStartIndex = strlen(currentString.c_str()); - currentString[currentStartIndex] = data; + int currentStartIndex = strlen(this->currentString.c_str()); + this->currentString[currentStartIndex] = data; }; //! addToCurrentErrString, appends string to the sps err_string currently being manipulated. @@ -331,12 +337,12 @@ \param data: data string */ void SPS::addToCurrentErrString(string data){ - int currentStartIndex = strlen(currentErrString.c_str()); + int currentStartIndex = strlen(this->currentErrString.c_str()); char dataStrLen = 0; dataStrLen = strlen(data.c_str()); for(int i = 0; i < dataStrLen; i++){ - currentErrString[currentStartIndex+i] = data[i]; + this->currentErrString[currentStartIndex+i] = data[i]; } };