Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Committer:
gert_lauritsen
Date:
Tue Jul 09 09:54:41 2019 +0000
Branch:
MbedBMAGThrRev
Revision:
64:06b9b8ffd5a6
Parent:
28:ed0d29f63b55
Child:
55:06c5f76e1a8c
dataline version to 4 and fw til 1.0.0.7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MAA 8:d6287c33b54a 1 #include "BMAG.h"
MAA 8:d6287c33b54a 2
MAA 14:400ecb93c6a2 3 //! The default constructor. No arguments are needed for this class ever.
MAA 14:400ecb93c6a2 4 /*!
MAA 14:400ecb93c6a2 5 Initializes private members needed when the object is operational.
MAA 14:400ecb93c6a2 6 */
MAA 8:d6287c33b54a 7 BMAG::BMAG(){
MAA 8:d6287c33b54a 8 lastMagTime.resize(25);
MAA 8:d6287c33b54a 9 lastMagNT.resize(25);
MAA 8:d6287c33b54a 10 lastMagSq.resize(25);
MAA 8:d6287c33b54a 11
MAA 8:d6287c33b54a 12 };
MAA 8:d6287c33b54a 13
MAA 14:400ecb93c6a2 14 //! Parser method. Parsing the GSM-19T RS232 strings.
MAA 14:400ecb93c6a2 15 /*!
MAA 14:400ecb93c6a2 16 Parses the RS232 string received from the GSM-19T and ensures splitting,
MAA 14:400ecb93c6a2 17 and storage of the different data elements of the string.
MAA 14:400ecb93c6a2 18
MAA 14:400ecb93c6a2 19 \param str The complete rs232 string from GSM-19T.
MAA 14:400ecb93c6a2 20
MAA 14:400ecb93c6a2 21 */
MAA 8:d6287c33b54a 22 void BMAG::parseBMAGString(string str){
MAA 8:d6287c33b54a 23 string tmpmagStr = "";
MAA 8:d6287c33b54a 24
MAA 8:d6287c33b54a 25 //get first mag string column
MAA 8:d6287c33b54a 26 tmpmagStr.assign(getColumn(str, 0));
MAA 8:d6287c33b54a 27
MAA 8:d6287c33b54a 28
MAA 8:d6287c33b54a 29 setMagTimeStr(tmpmagStr);
MAA 8:d6287c33b54a 30 tmpmagStr = "";
MAA 8:d6287c33b54a 31
MAA 8:d6287c33b54a 32 //get second mag string column
MAA 8:d6287c33b54a 33 tmpmagStr.assign(getColumn(str, 1));
MAA 28:ed0d29f63b55 34 setMagNTStr(tmpmagStr.substr(1));
MAA 8:d6287c33b54a 35
MAA 8:d6287c33b54a 36 tmpmagStr = "";
MAA 8:d6287c33b54a 37
MAA 8:d6287c33b54a 38 //get third mag string column
MAA 8:d6287c33b54a 39 tmpmagStr.assign(getColumn(str, 2));
MAA 8:d6287c33b54a 40
MAA 8:d6287c33b54a 41 setMagSqStr(tmpmagStr);
MAA 8:d6287c33b54a 42
MAA 8:d6287c33b54a 43
MAA 8:d6287c33b54a 44 };
MAA 8:d6287c33b54a 45
MAA 14:400ecb93c6a2 46
MAA 14:400ecb93c6a2 47 //! magTimeString string setting method.
MAA 14:400ecb93c6a2 48 /*!
MAA 14:400ecb93c6a2 49 sets the lastMagTime string to the received magT argument string value
MAA 14:400ecb93c6a2 50
MAA 14:400ecb93c6a2 51 \param magT Mag time data field as a string
MAA 14:400ecb93c6a2 52 */
MAA 8:d6287c33b54a 53 void BMAG::setMagTimeStr(string magT){
MAA 8:d6287c33b54a 54 lastMagTime.assign(magT);
MAA 8:d6287c33b54a 55 };
MAA 8:d6287c33b54a 56
MAA 8:d6287c33b54a 57
MAA 14:400ecb93c6a2 58 //! magMeasurement string setting method.
MAA 14:400ecb93c6a2 59 /*!
MAA 14:400ecb93c6a2 60 sets the lastMagNt string to the received magNT argument string value
MAA 14:400ecb93c6a2 61
MAA 14:400ecb93c6a2 62 \param magNT Mag nanoTesla data field as a string
MAA 14:400ecb93c6a2 63 */
MAA 8:d6287c33b54a 64 void BMAG::setMagNTStr(string magNT){
MAA 8:d6287c33b54a 65 lastMagNT.assign(magNT);
MAA 8:d6287c33b54a 66 };
MAA 8:d6287c33b54a 67
MAA 14:400ecb93c6a2 68 //! magMeasurementQuality string setting method.
MAA 14:400ecb93c6a2 69 /*!
MAA 14:400ecb93c6a2 70 sets the lastMagSq string to the received magSq argument string value
MAA 14:400ecb93c6a2 71
MAA 14:400ecb93c6a2 72 \param magSq Mag measurement quality data field as a string
MAA 14:400ecb93c6a2 73 */
MAA 8:d6287c33b54a 74 void BMAG::setMagSqStr(string magSq){
MAA 8:d6287c33b54a 75 lastMagSq.assign(magSq);
MAA 8:d6287c33b54a 76 };
MAA 8:d6287c33b54a 77
MAA 14:400ecb93c6a2 78
MAA 14:400ecb93c6a2 79 //! Mag time data field string getter method.
MAA 14:400ecb93c6a2 80 /*!
MAA 14:400ecb93c6a2 81 Returns the lastMagTime string
MAA 14:400ecb93c6a2 82
MAA 14:400ecb93c6a2 83 \return A string with the mag time data field
MAA 14:400ecb93c6a2 84 */
MAA 8:d6287c33b54a 85 string BMAG::getMagTimeStr(void){
MAA 8:d6287c33b54a 86 return lastMagTime;
MAA 8:d6287c33b54a 87 };
MAA 8:d6287c33b54a 88
MAA 14:400ecb93c6a2 89 //! Mag nanoTesla measurement data field string getter method.
MAA 14:400ecb93c6a2 90 /*!
MAA 14:400ecb93c6a2 91 Returns Mag nanoTesla measurement
MAA 14:400ecb93c6a2 92
MAA 14:400ecb93c6a2 93 \return A string with the Mag nanoTesla measurement
MAA 14:400ecb93c6a2 94 */
MAA 8:d6287c33b54a 95 string BMAG::getMagNTStr(void){
MAA 8:d6287c33b54a 96 return lastMagNT;
MAA 8:d6287c33b54a 97 };
MAA 8:d6287c33b54a 98
MAA 14:400ecb93c6a2 99
MAA 14:400ecb93c6a2 100 //! Mag measurement quality data field string getter method.
MAA 14:400ecb93c6a2 101 /*!
MAA 14:400ecb93c6a2 102 Returns Mag measurement quality
MAA 14:400ecb93c6a2 103
MAA 14:400ecb93c6a2 104 \return Mag measurement quality data field string
MAA 14:400ecb93c6a2 105 */
MAA 8:d6287c33b54a 106 string BMAG::getMagSq(void){
MAA 8:d6287c33b54a 107 return lastMagSq;
MAA 8:d6287c33b54a 108 };
MAA 8:d6287c33b54a 109
MAA 14:400ecb93c6a2 110 //! mag string column search method.
MAA 14:400ecb93c6a2 111 /*!
MAA 14:400ecb93c6a2 112 Returns the desired data column of the original GSM-19T measurement string.
MAA 14:400ecb93c6a2 113
MAA 14:400ecb93c6a2 114 \param str Iriginal GSM-19T measurement string
MAA 14:400ecb93c6a2 115 \param n Desired data column, 0 indexed. Eg. First column(Time): n = 0. Second column(mag measurement in nT): n = 1. Third column(Measurement Quality): n = 2.
MAA 14:400ecb93c6a2 116 \return desired data column as string.
MAA 14:400ecb93c6a2 117 */
MAA 8:d6287c33b54a 118 string BMAG::getColumn(string str, char n){
MAA 8:d6287c33b54a 119
MAA 8:d6287c33b54a 120 char count = 0;
MAA 8:d6287c33b54a 121 string tmpStr = "";
MAA 21:325cb82f1838 122 string result = "";
MAA 21:325cb82f1838 123
MAA 8:d6287c33b54a 124 tmpStr.resize(40);
MAA 8:d6287c33b54a 125 char indexcnt = 0;
MAA 8:d6287c33b54a 126
MAA 8:d6287c33b54a 127
MAA 8:d6287c33b54a 128 for(int i = 0; i < str.size(); i++){
MAA 8:d6287c33b54a 129 if(count == n && (str[i] != '\r') || count == n && (str[i] != '\n')){
MAA 8:d6287c33b54a 130 tmpStr[indexcnt] = str[i];
MAA 8:d6287c33b54a 131 indexcnt += 1;
MAA 8:d6287c33b54a 132 }
MAA 8:d6287c33b54a 133
MAA 8:d6287c33b54a 134 if(str[i] == '\r' || str[i] == ' '){
MAA 8:d6287c33b54a 135 count += 1;
MAA 8:d6287c33b54a 136 }
MAA 8:d6287c33b54a 137
MAA 8:d6287c33b54a 138 if(count > n){
MAA 8:d6287c33b54a 139 break;
MAA 8:d6287c33b54a 140 }
MAA 8:d6287c33b54a 141 }
MAA 8:d6287c33b54a 142
MAA 21:325cb82f1838 143 for(int i = 0; i < tmpStr.size(); i++){
MAA 21:325cb82f1838 144 if(tmpStr[i] != ' ' && tmpStr[i] != '\n' && tmpStr[i] != '\r'){
MAA 21:325cb82f1838 145 result += tmpStr[i];
MAA 21:325cb82f1838 146 }
MAA 21:325cb82f1838 147 }
MAA 21:325cb82f1838 148
MAA 21:325cb82f1838 149 return result;
MAA 8:d6287c33b54a 150
MAA 8:d6287c33b54a 151 };
MAA 8:d6287c33b54a 152
MAA 8:d6287c33b54a 153
MAA 8:d6287c33b54a 154