Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Committer:
MAA
Date:
Thu Aug 31 09:27:37 2017 +0000
Branch:
MbedBMAGThrRev
Revision:
28:ed0d29f63b55
Parent:
26:68277a308839
Child:
30:072e918663b8
Initial commit with threaded display update functionality.; BME280 pth sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MAA 0:b3313c5ffca3 1 #include "SPS.h"
MAA 0:b3313c5ffca3 2
MAA 19:5d25cffef662 3 //! SPS, class default constructor
MAA 19:5d25cffef662 4 /*!
MAA 19:5d25cffef662 5 Initializing different class member values, creating a header string.
MAA 19:5d25cffef662 6 */
MAA 0:b3313c5ffca3 7 SPS::SPS(){
MAA 2:39c4a85dc2a4 8
MAA 6:6d1683c8b26b 9 fileNameString = "";
MAA 2:39c4a85dc2a4 10 currentString = "";
MAA 2:39c4a85dc2a4 11 currentErrString = "";
MAA 6:6d1683c8b26b 12 lastString = "";
MAA 24:099df3fa2b13 13 headerString = "";
MAA 5:11782a2008c2 14 crc_tab16_init = 0;
MAA 5:11782a2008c2 15 errStatus = true;
MAA 2:39c4a85dc2a4 16
MAA 2:39c4a85dc2a4 17 };
MAA 2:39c4a85dc2a4 18
MAA 19:5d25cffef662 19
MAA 19:5d25cffef662 20 //! UpdateCurrentString, sps string creation method, taking data and info as parameters.
MAA 19:5d25cffef662 21 /*!
MAA 19:5d25cffef662 22
MAA 19:5d25cffef662 23 Generates an sps string containing everything needed in a BMAG sps string including crc, brackets etc.
MAA 19:5d25cffef662 24
MAA 19:5d25cffef662 25 \param tag: string containing the tag for the sps logging unit eg. "BMAG"
MAA 19:5d25cffef662 26 \param identifier_id: string containing the identifier id of the unit.
MAA 19:5d25cffef662 27 \param group_id: string containing the group id of the unit.
MAA 19:5d25cffef662 28 \param date: string containing the date in the format "YYYY/MM/DD"
MAA 19:5d25cffef662 29 \param time: string containing the current time in format "HH:MM:SS.FFF"
MAA 19:5d25cffef662 30 \param ZZZ: string containing "ZZZ" :)
MAA 23:2e914b705b99 31 \param encoding: string containing encoding as described in the *.sps documentation
MAA 19:5d25cffef662 32 \param source_id: string containing the source id of the unit eg. "0000"
MAA 19:5d25cffef662 33 \param interpreter_id: string containing the interpreter id of the unit eg. "00"
MAA 19:5d25cffef662 34 \param data_line_version: string containing data line version as described in the *.sps documentation, eg. "01"
MAA 19:5d25cffef662 35 \param source_firmware_version: string containing the firmware version of the unit eg. "1.2"
MAA 19:5d25cffef662 36 \param barcode: string containing the barcode of the unit, eg. "12345"
MAA 19:5d25cffef662 37 \param latitude: string containing the latitude of the unit in decimal degrees. For further info read the *.sps documentation.
MAA 19:5d25cffef662 38 \param longitude: string containing the longitude of the unit in decimal degrees. For further info read the *.sps documentation.
MAA 19:5d25cffef662 39 \param gpsFixFlag: bool containing the gps fix status, 1 if gps fix is present, else 0.
MAA 19:5d25cffef662 40 \param batteryvoltage: string containing the battery voltage of the units battery pack, eg. "14.2"
MAA 28:ed0d29f63b55 41 \param preassure: string containing preassure measurement in hPa
MAA 28:ed0d29f63b55 42 \param temperature: string containing temperature measured in deg C
MAA 28:ed0d29f63b55 43 \param humidity: string containing air humidity percentage
MAA 19:5d25cffef662 44 \param mag_time: string containing the last timestamp received from GSM-19 device eg. "000048.0"
MAA 19:5d25cffef662 45 \param mag_nt: string containing the last mag measurement in nT eg. "036418.77"
MAA 19:5d25cffef662 46 \param mag_sq: string containing info about the measurement quality of the last mag measurement eg. "99"
MAA 19:5d25cffef662 47
MAA 19:5d25cffef662 48 */
MAA 28:ed0d29f63b55 49 void SPS::UpdateCurrentString(string tag, string identifier_id, string group_id, string date, string time, string ZZZ,string encoding, 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 preassure, string temperature, string humidity, string mag_time, string mag_nt, string mag_sq, Serial * dbg){
MAA 2:39c4a85dc2a4 50
MAA 21:325cb82f1838 51 this->currentString = "";
MAA 21:325cb82f1838 52 this->currentString.resize(256);
MAA 21:325cb82f1838 53
MAA 21:325cb82f1838 54 int strLength = 0;
MAA 5:11782a2008c2 55 char checkSum[5];
MAA 5:11782a2008c2 56 memset(checkSum,'\0',5);
MAA 5:11782a2008c2 57 unsigned short chkSum = 0;
MAA 0:b3313c5ffca3 58
MAA 5:11782a2008c2 59 addToCurrentString(LINESTART);
MAA 5:11782a2008c2 60 addToCurrentString(tag);
MAA 5:11782a2008c2 61 addToCurrentString(SPACE);
MAA 5:11782a2008c2 62 addToCurrentString(identifier_id);
MAA 5:11782a2008c2 63 addToCurrentString(SPACE);
MAA 5:11782a2008c2 64 addToCurrentString(group_id);
MAA 5:11782a2008c2 65 addToCurrentString(SPACE);
MAA 5:11782a2008c2 66 addToCurrentString(date);
MAA 5:11782a2008c2 67 addToCurrentString(SPACE);
MAA 5:11782a2008c2 68 addToCurrentString(time);
MAA 25:57f9e3273979 69 addToCurrentString(SPACE);
MAA 25:57f9e3273979 70 if(!gpsFixFlag){
MAA 25:57f9e3273979 71 addToCurrentString("NOC");
MAA 25:57f9e3273979 72 }
MAA 25:57f9e3273979 73 if(gpsFixFlag){
MAA 25:57f9e3273979 74 addToCurrentString("ZZZ");
MAA 25:57f9e3273979 75 }
MAA 5:11782a2008c2 76 addToCurrentString(SPACE);
MAA 5:11782a2008c2 77 addToCurrentString(HEADEREND);
MAA 5:11782a2008c2 78 addToCurrentString(SPACE);
MAA 5:11782a2008c2 79 addToCurrentString(source_id);
MAA 5:11782a2008c2 80 addToCurrentString(SPACE);
MAA 5:11782a2008c2 81 addToCurrentString(interpreter_id);
MAA 5:11782a2008c2 82 addToCurrentString(SPACE);
MAA 5:11782a2008c2 83 addToCurrentString(data_line_version);
MAA 5:11782a2008c2 84 addToCurrentString(SPACE);
MAA 23:2e914b705b99 85 addToCurrentString(encoding);
MAA 23:2e914b705b99 86 addToCurrentString(SPACE);
MAA 5:11782a2008c2 87 addToCurrentString(source_firmware_version);
MAA 5:11782a2008c2 88 addToCurrentString(SPACE);
MAA 5:11782a2008c2 89 addToCurrentString(interpreter_firmware_version);
MAA 5:11782a2008c2 90 addToCurrentString(SPACE);
MAA 5:11782a2008c2 91 addToCurrentString(HEADEREND);
MAA 5:11782a2008c2 92 addToCurrentString(SPACE);
MAA 8:d6287c33b54a 93 addToCurrentString(barcode);
MAA 8:d6287c33b54a 94 addToCurrentString(SPACE);
MAA 24:099df3fa2b13 95 if(gpsFixFlag){
MAA 24:099df3fa2b13 96 addToCurrentString(latitude);
MAA 24:099df3fa2b13 97 }
MAA 24:099df3fa2b13 98 if(!gpsFixFlag){
MAA 24:099df3fa2b13 99 addToCurrentString("NaN");
MAA 24:099df3fa2b13 100 }
MAA 5:11782a2008c2 101 addToCurrentString(SPACE);
MAA 25:57f9e3273979 102 if(gpsFixFlag && (strlen(longitude.c_str()) > 5)){
MAA 24:099df3fa2b13 103 addToCurrentString(longitude);
MAA 24:099df3fa2b13 104 }
MAA 25:57f9e3273979 105 if(!gpsFixFlag || (strlen(longitude.c_str()) < 5)){
MAA 24:099df3fa2b13 106 addToCurrentString("NaN");
MAA 24:099df3fa2b13 107 }
MAA 24:099df3fa2b13 108 addToCurrentString(SPACE);
MAA 5:11782a2008c2 109 if(gpsFixFlag){
MAA 5:11782a2008c2 110 addToCurrentString('1');
MAA 5:11782a2008c2 111 }
MAA 5:11782a2008c2 112 if(!gpsFixFlag){
MAA 5:11782a2008c2 113 addToCurrentString('0');
MAA 5:11782a2008c2 114 }
MAA 5:11782a2008c2 115 addToCurrentString(SPACE);
MAA 8:d6287c33b54a 116 addToCurrentString(batteryvoltage);
MAA 8:d6287c33b54a 117 addToCurrentString(SPACE);
MAA 28:ed0d29f63b55 118 addToCurrentString(preassure);
MAA 28:ed0d29f63b55 119 addToCurrentString(SPACE);
MAA 28:ed0d29f63b55 120 addToCurrentString(temperature);
MAA 28:ed0d29f63b55 121 addToCurrentString(SPACE);
MAA 28:ed0d29f63b55 122 addToCurrentString(humidity);
MAA 28:ed0d29f63b55 123 addToCurrentString(SPACE);
MAA 5:11782a2008c2 124 addToCurrentString(mag_time);
MAA 5:11782a2008c2 125 addToCurrentString(SPACE);
MAA 5:11782a2008c2 126 addToCurrentString(mag_nt);
MAA 5:11782a2008c2 127 addToCurrentString(SPACE);
MAA 5:11782a2008c2 128 addToCurrentString(mag_sq);
MAA 5:11782a2008c2 129
MAA 21:325cb82f1838 130
MAA 21:325cb82f1838 131 strLength = strlen(this->currentString.c_str());
MAA 21:325cb82f1838 132
MAA 2:39c4a85dc2a4 133 //calculate checksum
MAA 21:325cb82f1838 134 for(int i = 0; i < strLength; i++){
MAA 21:325cb82f1838 135 if(this->currentString[i] != '>'){
MAA 5:11782a2008c2 136
MAA 21:325cb82f1838 137 chkSum = update_crc_16(chkSum, this->currentString[i]);
MAA 5:11782a2008c2 138
MAA 5:11782a2008c2 139 }
MAA 5:11782a2008c2 140 }
MAA 5:11782a2008c2 141
MAA 6:6d1683c8b26b 142 sprintf(checkSum, "%04X", chkSum);
MAA 21:325cb82f1838 143
MAA 2:39c4a85dc2a4 144 //append rest of string
MAA 5:11782a2008c2 145 addToCurrentString(SPACE);
MAA 5:11782a2008c2 146 addToCurrentString(checkSum);
MAA 8:d6287c33b54a 147 addToCurrentString(LINESTOP);
MAA 2:39c4a85dc2a4 148 };
MAA 2:39c4a85dc2a4 149
MAA 26:68277a308839 150 //! UpdateHeaderString, header / RMRK update method
MAA 26:68277a308839 151 /*!
MAA 26:68277a308839 152
MAA 26:68277a308839 153 Updates header / RMRK string
MAA 26:68277a308839 154
MAA 26:68277a308839 155 \param identifier_id: string containing the identifier id of the unit.
MAA 26:68277a308839 156 \param group_id: string containing the group id of the unit.
MAA 26:68277a308839 157 \param ZZZ: string containing "ZZZ" :)
MAA 26:68277a308839 158 \param encoding: string containing encoding as described in the *.sps documentation
MAA 26:68277a308839 159 \param source_id: string containing the source id of the unit eg. "0000"
MAA 26:68277a308839 160 \param interpreter_id: string containing the interpreter id of the unit eg. "00"
MAA 26:68277a308839 161 \param data_line_version: string containing data line version as described in the *.sps documentation, eg. "01"
MAA 26:68277a308839 162 \param source_firmware_version: string containing the firmware version of the unit eg. "1.2"
MAA 26:68277a308839 163 \param barcode: string containing the barcode of the unit, eg. "12345"
MAA 26:68277a308839 164 \param interpreter_firmware_version: string containing interpreter firmware version
MAA 26:68277a308839 165
MAA 26:68277a308839 166 */
MAA 24:099df3fa2b13 167 void SPS::UpdateHeaderString(string barcode, string identifier_id, string group_id, string ZZZ, string encoding,string source_id, string interpreter_id, string data_line_version, string source_firmware_version, string interpreter_firmware_version){
MAA 19:5d25cffef662 168
MAA 24:099df3fa2b13 169 this->headerString = "";
MAA 24:099df3fa2b13 170 this->headerString.resize(256);
MAA 24:099df3fa2b13 171
MAA 24:099df3fa2b13 172 int strLength = 0;
MAA 24:099df3fa2b13 173 char checkSum[5];
MAA 24:099df3fa2b13 174 memset(checkSum,'\0',5);
MAA 24:099df3fa2b13 175 unsigned short chkSum = 0;
MAA 24:099df3fa2b13 176
MAA 24:099df3fa2b13 177 addToCurrentHeaderString(LINESTART);
MAA 24:099df3fa2b13 178 addToCurrentHeaderString("RMRK");
MAA 24:099df3fa2b13 179 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 180 addToCurrentHeaderString(identifier_id);
MAA 24:099df3fa2b13 181 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 182 addToCurrentHeaderString(group_id);
MAA 24:099df3fa2b13 183 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 184 addToCurrentHeaderString("0000/00/00");
MAA 24:099df3fa2b13 185 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 186 addToCurrentHeaderString("00:00:00.000");
MAA 24:099df3fa2b13 187 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 188 addToCurrentHeaderString("ZZZ");
MAA 24:099df3fa2b13 189 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 190 addToCurrentHeaderString(HEADEREND);
MAA 24:099df3fa2b13 191 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 192 addToCurrentHeaderString(source_id);
MAA 24:099df3fa2b13 193 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 194 addToCurrentHeaderString(interpreter_id);
MAA 24:099df3fa2b13 195 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 196 addToCurrentHeaderString("01");
MAA 24:099df3fa2b13 197 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 198 addToCurrentHeaderString(encoding);
MAA 24:099df3fa2b13 199 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 200 addToCurrentHeaderString(source_firmware_version);
MAA 24:099df3fa2b13 201 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 202 addToCurrentHeaderString(interpreter_firmware_version);
MAA 24:099df3fa2b13 203 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 204 addToCurrentHeaderString(HEADEREND);
MAA 24:099df3fa2b13 205 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 206 addToCurrentHeaderString("Barcode");
MAA 24:099df3fa2b13 207 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 208 addToCurrentHeaderString("Latitude");
MAA 24:099df3fa2b13 209 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 210 addToCurrentHeaderString("Longitude");
MAA 24:099df3fa2b13 211 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 212 addToCurrentHeaderString("gpsFixFlag");
MAA 24:099df3fa2b13 213 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 214 addToCurrentHeaderString("batteryVoltage");
MAA 24:099df3fa2b13 215 addToCurrentHeaderString(SPACE);
MAA 28:ed0d29f63b55 216 addToCurrentHeaderString("preassure");
MAA 28:ed0d29f63b55 217 addToCurrentHeaderString(SPACE);
MAA 28:ed0d29f63b55 218 addToCurrentHeaderString("temperature");
MAA 28:ed0d29f63b55 219 addToCurrentHeaderString(SPACE);
MAA 28:ed0d29f63b55 220 addToCurrentHeaderString("humidity");
MAA 28:ed0d29f63b55 221 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 222 addToCurrentHeaderString("mag_time");
MAA 24:099df3fa2b13 223 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 224 addToCurrentHeaderString("mag_value");
MAA 24:099df3fa2b13 225 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 226 addToCurrentHeaderString("mag_quality");
MAA 24:099df3fa2b13 227
MAA 24:099df3fa2b13 228
MAA 24:099df3fa2b13 229 strLength = strlen(this->headerString.c_str());
MAA 24:099df3fa2b13 230
MAA 24:099df3fa2b13 231 //calculate checksum
MAA 24:099df3fa2b13 232 for(int i = 0; i < strLength; i++){
MAA 24:099df3fa2b13 233 if(this->headerString[i] != '>'){
MAA 24:099df3fa2b13 234
MAA 24:099df3fa2b13 235 chkSum = update_crc_16(chkSum, this->headerString[i]);
MAA 24:099df3fa2b13 236
MAA 24:099df3fa2b13 237 }
MAA 24:099df3fa2b13 238 }
MAA 24:099df3fa2b13 239
MAA 24:099df3fa2b13 240 sprintf(checkSum, "%04X", chkSum);
MAA 24:099df3fa2b13 241
MAA 24:099df3fa2b13 242 //append rest of string
MAA 24:099df3fa2b13 243 addToCurrentHeaderString(SPACE);
MAA 24:099df3fa2b13 244 addToCurrentHeaderString(checkSum);
MAA 24:099df3fa2b13 245 addToCurrentHeaderString(LINESTOP);
MAA 24:099df3fa2b13 246 }
MAA 19:5d25cffef662 247
MAA 19:5d25cffef662 248 //! UpdateCurrentErrString, sps ERR string creation method, taking data and info as parameters.
MAA 19:5d25cffef662 249 /*!
MAA 19:5d25cffef662 250
MAA 19:5d25cffef662 251 Generates the current sps ERR string containing everything needed in a BMAG sps string including crc, brackets etc.
MAA 19:5d25cffef662 252
MAA 19:5d25cffef662 253 \param tag: string containing the tag for the sps logging unit eg. "BMAG"
MAA 19:5d25cffef662 254 \param identifier_id: string containing the identifier id of the unit.
MAA 19:5d25cffef662 255 \param group_id: string containing the group id of the unit.
MAA 19:5d25cffef662 256 \param date: string containing the date in the format "YYYY/MM/DD"
MAA 19:5d25cffef662 257 \param time: string containing the current time in format "HH:MM:SS.FFF"
MAA 19:5d25cffef662 258 \param ZZZ: string containing "ZZZ" :)
MAA 23:2e914b705b99 259 \param encoding: string containing encoding as described in the *.sps documentation
MAA 19:5d25cffef662 260 \param source_id: string containing the source id of the unit eg. "0000"
MAA 19:5d25cffef662 261 \param interpreter_id: string containing the interpreter id of the unit eg. "00"
MAA 19:5d25cffef662 262 \param data_line_version: string containing data line version as described in the *.sps documentation, eg. "01"
MAA 19:5d25cffef662 263 \param source_firmware_version: string containing the firmware version of the unit eg. "1.2"
MAA 19:5d25cffef662 264 \param barcode: string containing the barcode of the unit, eg. "12345"
MAA 19:5d25cffef662 265 \param latitude: string containing the latitude of the unit in decimal degrees. For further info read the *.sps documentation.
MAA 19:5d25cffef662 266 \param longitude: string containing the longitude of the unit in decimal degrees. For further info read the *.sps documentation.
MAA 19:5d25cffef662 267 \param gpsFixFlag: bool containing the gps fix status, 1 if gps fix is present, else 0.
MAA 19:5d25cffef662 268 \param mag_time: string containing the last timestamp received from GSM-19 device eg. "000048.0"
MAA 19:5d25cffef662 269 \param mag_nt: string containing the last mag measurement in nT eg. "036418.77"
MAA 19:5d25cffef662 270 \param mag_sq: string containing info about the measurement quality of the last mag measurement eg. "99"
MAA 19:5d25cffef662 271
MAA 19:5d25cffef662 272 */
MAA 23:2e914b705b99 273 void SPS::UpdateCurrentErrString(string tag, string identifier_id, string group_id, string date, string time, string ZZZ,string encoding, 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){
MAA 7:872984a67d5b 274
MAA 21:325cb82f1838 275 this->currentErrString = "";
MAA 21:325cb82f1838 276 this->currentErrString.resize(256);
MAA 7:872984a67d5b 277 char checkSum[5];
MAA 7:872984a67d5b 278 memset(checkSum,'\0',5);
MAA 7:872984a67d5b 279 unsigned short chkSum = 0;
MAA 24:099df3fa2b13 280 int strLength = 0;
MAA 7:872984a67d5b 281
MAA 7:872984a67d5b 282 addToCurrentErrString(LINESTART);
MAA 7:872984a67d5b 283 addToCurrentErrString(tag);
MAA 7:872984a67d5b 284 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 285 addToCurrentErrString(identifier_id);
MAA 7:872984a67d5b 286 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 287 addToCurrentErrString(group_id);
MAA 7:872984a67d5b 288 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 289 addToCurrentErrString(date);
MAA 7:872984a67d5b 290 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 291 addToCurrentErrString(time);
MAA 25:57f9e3273979 292 addToCurrentErrString(SPACE);
MAA 25:57f9e3273979 293 addToCurrentErrString("ZZZ");
MAA 24:099df3fa2b13 294 addToCurrentErrString(SPACE);
MAA 24:099df3fa2b13 295 addToCurrentErrString(HEADEREND);
MAA 25:57f9e3273979 296 addToCurrentErrString(SPACE);
MAA 24:099df3fa2b13 297 addToCurrentErrString(source_id);
MAA 24:099df3fa2b13 298 addToCurrentErrString(SPACE);
MAA 24:099df3fa2b13 299 addToCurrentErrString(interpreter_id);
MAA 24:099df3fa2b13 300 addToCurrentErrString(SPACE);
MAA 25:57f9e3273979 301 addToCurrentErrString("02");
MAA 24:099df3fa2b13 302 addToCurrentErrString(SPACE);
MAA 24:099df3fa2b13 303 addToCurrentErrString(encoding);
MAA 24:099df3fa2b13 304 addToCurrentErrString(SPACE);
MAA 24:099df3fa2b13 305 addToCurrentErrString(source_firmware_version);
MAA 24:099df3fa2b13 306 addToCurrentErrString(SPACE);
MAA 24:099df3fa2b13 307 addToCurrentErrString(interpreter_firmware_version);
MAA 24:099df3fa2b13 308 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 309 addToCurrentErrString(HEADEREND);
MAA 7:872984a67d5b 310 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 311 addToCurrentErrString("BMAG");
MAA 25:57f9e3273979 312 if(!gpsFixFlag){
MAA 25:57f9e3273979 313 addToCurrentErrString(SPACE);
MAA 25:57f9e3273979 314 addToCurrentErrString("RTC");
MAA 25:57f9e3273979 315 }
MAA 7:872984a67d5b 316 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 317 addToCurrentErrString("C02");
MAA 7:872984a67d5b 318 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 319 addToCurrentErrString("C03");
MAA 7:872984a67d5b 320
MAA 24:099df3fa2b13 321 strLength = strlen(this->currentErrString.c_str());
MAA 24:099df3fa2b13 322
MAA 7:872984a67d5b 323 //calculate checksum
MAA 24:099df3fa2b13 324 for(int i = 0; i < strLength; i++){
MAA 24:099df3fa2b13 325 if(this->currentErrString[i] != '>'){
MAA 7:872984a67d5b 326
MAA 21:325cb82f1838 327 chkSum = update_crc_16(chkSum, this->currentErrString[i]);
MAA 7:872984a67d5b 328
MAA 7:872984a67d5b 329 }
MAA 7:872984a67d5b 330 }
MAA 21:325cb82f1838 331
MAA 7:872984a67d5b 332 sprintf(checkSum, "%04X", chkSum);
MAA 7:872984a67d5b 333
MAA 7:872984a67d5b 334 //append rest of string
MAA 7:872984a67d5b 335 addToCurrentErrString(SPACE);
MAA 7:872984a67d5b 336 addToCurrentErrString(checkSum);
MAA 8:d6287c33b54a 337 addToCurrentErrString(LINESTOP);
MAA 7:872984a67d5b 338 };
MAA 7:872984a67d5b 339
MAA 19:5d25cffef662 340 //! init_crc16_tab, creates a crc tab.
MAA 19:5d25cffef662 341 /*!
MAA 19:5d25cffef662 342 Populates a crc array for later use
MAA 19:5d25cffef662 343 */
MAA 4:c70ef089a3fd 344 void SPS::init_crc16_tab()
MAA 4:c70ef089a3fd 345 {
MAA 4:c70ef089a3fd 346 int i, j;
MAA 4:c70ef089a3fd 347 unsigned short crc, c;
MAA 4:c70ef089a3fd 348
MAA 4:c70ef089a3fd 349 for (i = 0; i < 256; i++)
MAA 4:c70ef089a3fd 350 {
MAA 4:c70ef089a3fd 351 crc = 0;
MAA 4:c70ef089a3fd 352 c = (unsigned short) i;
MAA 4:c70ef089a3fd 353
MAA 4:c70ef089a3fd 354 for (j = 0; j < 8; j++)
MAA 4:c70ef089a3fd 355 {
MAA 4:c70ef089a3fd 356 if ((crc ^ c) & 0x0001)
MAA 4:c70ef089a3fd 357 crc = (crc >> 1) ^ P_16;
MAA 4:c70ef089a3fd 358 else
MAA 4:c70ef089a3fd 359 crc = crc >> 1;
MAA 4:c70ef089a3fd 360
MAA 4:c70ef089a3fd 361 c = c >> 1;
MAA 4:c70ef089a3fd 362 }
MAA 4:c70ef089a3fd 363 crc_tab16[i] = crc;
MAA 4:c70ef089a3fd 364 }
MAA 4:c70ef089a3fd 365 crc_tab16_init = 1;
MAA 4:c70ef089a3fd 366 };
MAA 4:c70ef089a3fd 367
MAA 4:c70ef089a3fd 368
MAA 19:5d25cffef662 369
MAA 19:5d25cffef662 370 //! update_crc_16, updates crc tab.
MAA 19:5d25cffef662 371 /*!
MAA 20:73fa202c73db 372 \param crc: the crc currently getting calculated
MAA 20:73fa202c73db 373 \param c: next character to be part of crc
MAA 19:5d25cffef662 374 \return returns crc value
MAA 19:5d25cffef662 375 */
MAA 4:c70ef089a3fd 376 unsigned short SPS::update_crc_16(unsigned short crc, char c)
MAA 4:c70ef089a3fd 377 {
MAA 4:c70ef089a3fd 378 unsigned short tmp, short_c;
MAA 4:c70ef089a3fd 379
MAA 4:c70ef089a3fd 380 short_c = 0x00ff & (unsigned short) c;
MAA 4:c70ef089a3fd 381
MAA 4:c70ef089a3fd 382 if (!crc_tab16_init)
MAA 4:c70ef089a3fd 383 init_crc16_tab();
MAA 21:325cb82f1838 384
MAA 4:c70ef089a3fd 385
MAA 4:c70ef089a3fd 386 tmp = crc ^ short_c;
MAA 4:c70ef089a3fd 387 crc = (crc >> 8) ^ crc_tab16[tmp & 0xff];
MAA 4:c70ef089a3fd 388
MAA 4:c70ef089a3fd 389 return crc;
MAA 4:c70ef089a3fd 390 };
MAA 5:11782a2008c2 391
MAA 5:11782a2008c2 392
MAA 20:73fa202c73db 393
MAA 20:73fa202c73db 394 //! getCurrentString, returns the current sps data string
MAA 20:73fa202c73db 395 /*!
MAA 20:73fa202c73db 396 \return returns current sps data string
MAA 20:73fa202c73db 397 */
MAA 5:11782a2008c2 398 string SPS::getCurrentString(void){
MAA 5:11782a2008c2 399 return this->currentString;
MAA 5:11782a2008c2 400 };
MAA 5:11782a2008c2 401
MAA 5:11782a2008c2 402
MAA 20:73fa202c73db 403 //! getErrStatus, returns the current error status flag
MAA 20:73fa202c73db 404 /*!
MAA 20:73fa202c73db 405 \return returns the current error status flag (bool)
MAA 20:73fa202c73db 406 */
MAA 5:11782a2008c2 407 bool SPS::getErrStatus(void){
MAA 5:11782a2008c2 408 return this->errStatus;
MAA 5:11782a2008c2 409 };
MAA 5:11782a2008c2 410
MAA 20:73fa202c73db 411 //! setErrStatus, sets error status flag
MAA 20:73fa202c73db 412 /*!
MAA 20:73fa202c73db 413 \param status: boolean value assigned to errorStatus
MAA 20:73fa202c73db 414 */
MAA 5:11782a2008c2 415 void SPS::setErrStatus(bool status){
MAA 5:11782a2008c2 416 this->errStatus = status;
MAA 5:11782a2008c2 417 };
MAA 5:11782a2008c2 418
MAA 20:73fa202c73db 419 //! getHeaderString, getter method, returning header string for *.sps file
MAA 20:73fa202c73db 420 /*!
MAA 20:73fa202c73db 421 \return returns the header string for the *.sps file
MAA 20:73fa202c73db 422 */
MAA 5:11782a2008c2 423 string SPS::getHeaderString(void){
MAA 5:11782a2008c2 424 return this->headerString;
MAA 5:11782a2008c2 425 };
MAA 5:11782a2008c2 426
MAA 5:11782a2008c2 427 //add data to current string
MAA 20:73fa202c73db 428 //! addToCurrentString, appends string of data to the sps string currently being manipulated.
MAA 20:73fa202c73db 429 /*!
MAA 20:73fa202c73db 430 \param data: string containing data
MAA 20:73fa202c73db 431 */
MAA 5:11782a2008c2 432 void SPS::addToCurrentString(string data){
MAA 21:325cb82f1838 433 int currentStartIndex = strlen(this->currentString.c_str());
MAA 5:11782a2008c2 434 char dataStrLen = 0;
MAA 8:d6287c33b54a 435 int index = 0;
MAA 8:d6287c33b54a 436
MAA 5:11782a2008c2 437 dataStrLen = strlen(data.c_str());
MAA 5:11782a2008c2 438
MAA 5:11782a2008c2 439 for(int i = 0; i < dataStrLen; i++){
MAA 8:d6287c33b54a 440
MAA 21:325cb82f1838 441 if((this->currentString[currentStartIndex+i] != '\r') || (this->currentString[currentStartIndex+i] != '\n')){
MAA 8:d6287c33b54a 442
MAA 21:325cb82f1838 443 this->currentString[currentStartIndex+i] = data[index];
MAA 8:d6287c33b54a 444 index += 1;
MAA 8:d6287c33b54a 445
MAA 8:d6287c33b54a 446 }
MAA 8:d6287c33b54a 447
MAA 5:11782a2008c2 448 }
MAA 5:11782a2008c2 449 }
MAA 5:11782a2008c2 450
MAA 20:73fa202c73db 451 //! addToCurrentString, appends char to the sps string currently being manipulated.
MAA 20:73fa202c73db 452 /*!
MAA 20:73fa202c73db 453 \param data: data character
MAA 20:73fa202c73db 454 */
MAA 5:11782a2008c2 455 void SPS::addToCurrentString(char data){
MAA 21:325cb82f1838 456 int currentStartIndex = strlen(this->currentString.c_str());
MAA 21:325cb82f1838 457 this->currentString[currentStartIndex] = data;
MAA 6:6d1683c8b26b 458 };
MAA 6:6d1683c8b26b 459
MAA 24:099df3fa2b13 460
MAA 26:68277a308839 461
MAA 26:68277a308839 462 //! addToCurrentHeaderString, appends string to the current header string
MAA 26:68277a308839 463 /*!
MAA 26:68277a308839 464 \param data: data string
MAA 26:68277a308839 465 */
MAA 24:099df3fa2b13 466 void SPS::addToCurrentHeaderString(string data){
MAA 24:099df3fa2b13 467 int currentStartIndex = strlen(this->headerString.c_str());
MAA 24:099df3fa2b13 468 char dataStrLen = 0;
MAA 24:099df3fa2b13 469 int index = 0;
MAA 24:099df3fa2b13 470
MAA 24:099df3fa2b13 471 dataStrLen = strlen(data.c_str());
MAA 24:099df3fa2b13 472
MAA 24:099df3fa2b13 473 for(int i = 0; i < dataStrLen; i++){
MAA 24:099df3fa2b13 474
MAA 24:099df3fa2b13 475 if((this->headerString[currentStartIndex+i] != '\r') || (this->headerString[currentStartIndex+i] != '\n')){
MAA 24:099df3fa2b13 476
MAA 24:099df3fa2b13 477 this->headerString[currentStartIndex+i] = data[index];
MAA 24:099df3fa2b13 478 index += 1;
MAA 24:099df3fa2b13 479
MAA 24:099df3fa2b13 480 }
MAA 24:099df3fa2b13 481
MAA 24:099df3fa2b13 482 }
MAA 24:099df3fa2b13 483 };
MAA 24:099df3fa2b13 484
MAA 24:099df3fa2b13 485
MAA 26:68277a308839 486 //! addToCurrentHeaderString, appends char to the current header string
MAA 26:68277a308839 487 /*!
MAA 26:68277a308839 488 \param data: data char
MAA 26:68277a308839 489 */
MAA 24:099df3fa2b13 490 void SPS::addToCurrentHeaderString(char data){
MAA 24:099df3fa2b13 491 int currentStartIndex = strlen(this->headerString.c_str());
MAA 24:099df3fa2b13 492 this->headerString[currentStartIndex] = data;
MAA 24:099df3fa2b13 493 };
MAA 24:099df3fa2b13 494
MAA 20:73fa202c73db 495 //! addToCurrentErrString, appends string to the sps err_string currently being manipulated.
MAA 20:73fa202c73db 496 /*!
MAA 20:73fa202c73db 497 \param data: data string
MAA 20:73fa202c73db 498 */
MAA 7:872984a67d5b 499 void SPS::addToCurrentErrString(string data){
MAA 21:325cb82f1838 500 int currentStartIndex = strlen(this->currentErrString.c_str());
MAA 7:872984a67d5b 501 char dataStrLen = 0;
MAA 7:872984a67d5b 502 dataStrLen = strlen(data.c_str());
MAA 7:872984a67d5b 503
MAA 7:872984a67d5b 504 for(int i = 0; i < dataStrLen; i++){
MAA 21:325cb82f1838 505 this->currentErrString[currentStartIndex+i] = data[i];
MAA 7:872984a67d5b 506 }
MAA 7:872984a67d5b 507
MAA 7:872984a67d5b 508 };
MAA 20:73fa202c73db 509
MAA 20:73fa202c73db 510 //! addToCurrentErrString, appends a character to the sps err_string currently being manipulated.
MAA 20:73fa202c73db 511 /*!
MAA 20:73fa202c73db 512 \param data: data char
MAA 20:73fa202c73db 513 */
MAA 7:872984a67d5b 514 void SPS::addToCurrentErrString(char data){
MAA 7:872984a67d5b 515 int currentStartIndex = strlen(currentErrString.c_str());
MAA 7:872984a67d5b 516 currentErrString[currentStartIndex] = data;
MAA 7:872984a67d5b 517
MAA 7:872984a67d5b 518 };
MAA 7:872984a67d5b 519
MAA 20:73fa202c73db 520 //! generateSpsFilename, generates a sps file name, including file postfix, using the current date as input.
MAA 20:73fa202c73db 521 /*!
MAA 20:73fa202c73db 522 \param formattedDate: Date string using a formatted date witht he format: "YYYY/MM/DD"
MAA 20:73fa202c73db 523 */
MAA 6:6d1683c8b26b 524 void SPS::generateSpsFilename(string formattedDate){
MAA 6:6d1683c8b26b 525
MAA 7:872984a67d5b 526 fileNameString.resize(25);
MAA 6:6d1683c8b26b 527
MAA 7:872984a67d5b 528 fileNameString.replace(0, 10, "/usb/BMAG_");
MAA 6:6d1683c8b26b 529
MAA 7:872984a67d5b 530 fileNameString[10] = formattedDate[0];
MAA 7:872984a67d5b 531 fileNameString[11] = formattedDate[1];
MAA 7:872984a67d5b 532 fileNameString[12] = formattedDate[2];
MAA 7:872984a67d5b 533 fileNameString[13] = formattedDate[3];
MAA 7:872984a67d5b 534 fileNameString[14] = '-';
MAA 7:872984a67d5b 535 fileNameString[15] = formattedDate[5];
MAA 7:872984a67d5b 536 fileNameString[16] = formattedDate[6];
MAA 7:872984a67d5b 537 fileNameString[17] = '-';
MAA 7:872984a67d5b 538 fileNameString[18] = formattedDate[8];
MAA 7:872984a67d5b 539 fileNameString[19] = formattedDate[9];
MAA 6:6d1683c8b26b 540
MAA 7:872984a67d5b 541 fileNameString[20] = '.';
MAA 7:872984a67d5b 542 fileNameString[21] = 's';
MAA 7:872984a67d5b 543 fileNameString[22] = 'p';
MAA 7:872984a67d5b 544 fileNameString[23] = 's';
MAA 6:6d1683c8b26b 545
MAA 6:6d1683c8b26b 546 };
MAA 6:6d1683c8b26b 547
MAA 20:73fa202c73db 548 //! getSpsFileName, getter method, returning a *.sps filename based on the formatted date generated using generateSpsFilename(string formattedDate) method.
MAA 20:73fa202c73db 549 /*!
MAA 20:73fa202c73db 550 \return fileNameString returns file name including postfix.
MAA 20:73fa202c73db 551 */
MAA 6:6d1683c8b26b 552 string SPS::getSpsFileName(void){
MAA 6:6d1683c8b26b 553
MAA 6:6d1683c8b26b 554 return this->fileNameString;
MAA 6:6d1683c8b26b 555
MAA 7:872984a67d5b 556 };
MAA 7:872984a67d5b 557
MAA 20:73fa202c73db 558 //! getCurrentErrString, getter method returning current sps error string
MAA 20:73fa202c73db 559 /*!
MAA 20:73fa202c73db 560 \return currentErrString: returns the current sps error string.
MAA 20:73fa202c73db 561 */
MAA 7:872984a67d5b 562 string SPS::getCurrentErrString(void){
MAA 7:872984a67d5b 563 return this->currentErrString;
MAA 5:11782a2008c2 564 };