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
BMAG.cpp
00001 #include "BMAG.h" 00002 00003 //! The default constructor. No arguments are needed for this class ever. 00004 /*! 00005 Initializes private members needed when the object is operational. 00006 */ 00007 BMAG::BMAG(){ 00008 lastMagTime.resize(25); 00009 lastMagNT.resize(25); 00010 lastMagSq.resize(25); 00011 00012 }; 00013 00014 //! Parser method. Parsing the GSM-19T RS232 strings. 00015 /*! 00016 Parses the RS232 string received from the GSM-19T and ensures splitting, 00017 and storage of the different data elements of the string. 00018 00019 \param str The complete rs232 string from GSM-19T. 00020 00021 */ 00022 void BMAG::parseBMAGString(string str){ 00023 string tmpmagStr = ""; 00024 00025 //get first mag string column 00026 tmpmagStr.assign(getColumn(str, 0)); 00027 00028 00029 setMagTimeStr(tmpmagStr); 00030 tmpmagStr = ""; 00031 00032 //get second mag string column 00033 tmpmagStr.assign(getColumn(str, 1)); 00034 setMagNTStr(tmpmagStr.substr(1)); 00035 00036 tmpmagStr = ""; 00037 00038 //get third mag string column 00039 tmpmagStr.assign(getColumn(str, 2)); 00040 00041 setMagSqStr(tmpmagStr); 00042 00043 00044 }; 00045 00046 00047 //! magTimeString string setting method. 00048 /*! 00049 sets the lastMagTime string to the received magT argument string value 00050 00051 \param magT Mag time data field as a string 00052 */ 00053 void BMAG::setMagTimeStr(string magT){ 00054 lastMagTime.assign(magT); 00055 }; 00056 00057 00058 //! magMeasurement string setting method. 00059 /*! 00060 sets the lastMagNt string to the received magNT argument string value 00061 00062 \param magNT Mag nanoTesla data field as a string 00063 */ 00064 void BMAG::setMagNTStr(string magNT){ 00065 lastMagNT.assign(magNT); 00066 }; 00067 00068 //! magMeasurementQuality string setting method. 00069 /*! 00070 sets the lastMagSq string to the received magSq argument string value 00071 00072 \param magSq Mag measurement quality data field as a string 00073 */ 00074 void BMAG::setMagSqStr(string magSq){ 00075 lastMagSq.assign(magSq); 00076 }; 00077 00078 00079 //! Mag time data field string getter method. 00080 /*! 00081 Returns the lastMagTime string 00082 00083 \return A string with the mag time data field 00084 */ 00085 string BMAG::getMagTimeStr(void){ 00086 return lastMagTime; 00087 }; 00088 00089 //! Mag nanoTesla measurement data field string getter method. 00090 /*! 00091 Returns Mag nanoTesla measurement 00092 00093 \return A string with the Mag nanoTesla measurement 00094 */ 00095 string BMAG::getMagNTStr(void){ 00096 return lastMagNT; 00097 }; 00098 00099 00100 //! Mag measurement quality data field string getter method. 00101 /*! 00102 Returns Mag measurement quality 00103 00104 \return Mag measurement quality data field string 00105 */ 00106 string BMAG::getMagSq(void){ 00107 return lastMagSq; 00108 }; 00109 00110 //! mag string column search method. 00111 /*! 00112 Returns the desired data column of the original GSM-19T measurement string. 00113 00114 \param str Iriginal GSM-19T measurement string 00115 \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. 00116 \return desired data column as string. 00117 */ 00118 string BMAG::getColumn(string str, char n){ 00119 00120 char count = 0; 00121 string tmpStr = ""; 00122 string result = ""; 00123 00124 tmpStr.resize(40); 00125 char indexcnt = 0; 00126 00127 00128 for(int i = 0; i < str.size(); i++){ 00129 if(count == n && (str[i] != '\r') || count == n && (str[i] != '\n')){ 00130 tmpStr[indexcnt] = str[i]; 00131 indexcnt += 1; 00132 } 00133 00134 if(str[i] == '\r' || str[i] == ' '){ 00135 count += 1; 00136 } 00137 00138 if(count > n){ 00139 break; 00140 } 00141 } 00142 00143 for(int i = 0; i < tmpStr.size(); i++){ 00144 if(tmpStr[i] != ' ' && tmpStr[i] != '\n' && tmpStr[i] != '\r'){ 00145 result += tmpStr[i]; 00146 } 00147 } 00148 00149 return result; 00150 00151 }; 00152 00153 00154
Generated on Wed Jul 13 2022 08:04:14 by
