Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Committer:
MAA
Date:
Thu Mar 02 14:04:56 2017 +0000
Revision:
4:c70ef089a3fd
Parent:
2:39c4a85dc2a4
Child:
5:11782a2008c2
Long and Lat calculation in decimal degrees implemented.; SPS file format begun.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MAA 0:b3313c5ffca3 1 #include "SPS.h"
MAA 0:b3313c5ffca3 2
MAA 0:b3313c5ffca3 3 SPS::SPS(){
MAA 2:39c4a85dc2a4 4
MAA 2:39c4a85dc2a4 5 currentString = "";
MAA 2:39c4a85dc2a4 6 currentErrString = "";
MAA 4:c70ef089a3fd 7 headerString = "/tag identifier_id group_id date time zzz | s1 source_id interpreter_id data_line_version encoding source_firmware_version interpreter_firmware_version | latitude longitude gpsFixFlag mag_time mag_nt mag_sq checksum";
MAA 2:39c4a85dc2a4 8
MAA 2:39c4a85dc2a4 9 };
MAA 2:39c4a85dc2a4 10
MAA 2:39c4a85dc2a4 11 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 encoding, string source_firmware_version, string interpreter_firmware_version, string latitude, string longitude, char gpsFixFlag, string mag_time, string mag_nt, string mag_sq){
MAA 2:39c4a85dc2a4 12
MAA 2:39c4a85dc2a4 13 currentString = "";
MAA 2:39c4a85dc2a4 14 string checkSum = "";
MAA 0:b3313c5ffca3 15
MAA 2:39c4a85dc2a4 16 //create current string
MAA 2:39c4a85dc2a4 17 currentString.push_back(LINESTART);
MAA 2:39c4a85dc2a4 18 currentString.append(tag);
MAA 2:39c4a85dc2a4 19 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 20 currentString.append(identifier_id);
MAA 2:39c4a85dc2a4 21 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 22 currentString.append(group_id);
MAA 2:39c4a85dc2a4 23 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 24 currentString.append(date);
MAA 2:39c4a85dc2a4 25 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 26 currentString.append(time);
MAA 2:39c4a85dc2a4 27 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 28 currentString.append("ZZZ");
MAA 2:39c4a85dc2a4 29 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 30 currentString.push_back(HEADEREND);
MAA 2:39c4a85dc2a4 31 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 32 currentString.append(s1);
MAA 2:39c4a85dc2a4 33 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 34 currentString.append(source_id);
MAA 2:39c4a85dc2a4 35 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 36 currentString.append(interpreter_id);
MAA 2:39c4a85dc2a4 37 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 38 currentString.append(data_line_version);
MAA 2:39c4a85dc2a4 39 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 40 currentString.append(encoding);
MAA 2:39c4a85dc2a4 41 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 42 currentString.append(source_firmware_version);
MAA 2:39c4a85dc2a4 43 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 44 currentString.append(interpreter_firmware_version);
MAA 2:39c4a85dc2a4 45 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 46 currentString.push_back(HEADEREND);
MAA 2:39c4a85dc2a4 47 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 48 currentString.append(latitude);
MAA 2:39c4a85dc2a4 49 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 50 currentString.append(longitude);
MAA 2:39c4a85dc2a4 51 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 52 currentString.push_back(gpsFixFlag);
MAA 2:39c4a85dc2a4 53 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 54 currentString.append(mag_time);
MAA 2:39c4a85dc2a4 55 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 56 currentString.append(mag_nt);
MAA 2:39c4a85dc2a4 57 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 58 currentString.append(mag_sq);
MAA 2:39c4a85dc2a4 59
MAA 2:39c4a85dc2a4 60 //calculate checksum
MAA 2:39c4a85dc2a4 61 checkSum = this->checkSumCalc();
MAA 2:39c4a85dc2a4 62
MAA 2:39c4a85dc2a4 63 //append rest of string
MAA 2:39c4a85dc2a4 64 currentString.push_back(SPACE);
MAA 2:39c4a85dc2a4 65 currentString.append(checkSum);
MAA 2:39c4a85dc2a4 66 currentString.push_back(LINESTOP);
MAA 2:39c4a85dc2a4 67
MAA 2:39c4a85dc2a4 68 };
MAA 2:39c4a85dc2a4 69
MAA 4:c70ef089a3fd 70 //Fills the array for calculation of the CRC-16 with values
MAA 4:c70ef089a3fd 71 void SPS::init_crc16_tab()
MAA 4:c70ef089a3fd 72 {
MAA 4:c70ef089a3fd 73 int i, j;
MAA 4:c70ef089a3fd 74 unsigned short crc, c;
MAA 4:c70ef089a3fd 75
MAA 4:c70ef089a3fd 76 for (i = 0; i < 256; i++)
MAA 4:c70ef089a3fd 77 {
MAA 4:c70ef089a3fd 78 crc = 0;
MAA 4:c70ef089a3fd 79 c = (unsigned short) i;
MAA 4:c70ef089a3fd 80
MAA 4:c70ef089a3fd 81 for (j = 0; j < 8; j++)
MAA 4:c70ef089a3fd 82 {
MAA 4:c70ef089a3fd 83 if ((crc ^ c) & 0x0001)
MAA 4:c70ef089a3fd 84 crc = (crc >> 1) ^ P_16;
MAA 4:c70ef089a3fd 85 else
MAA 4:c70ef089a3fd 86 crc = crc >> 1;
MAA 4:c70ef089a3fd 87
MAA 4:c70ef089a3fd 88 c = c >> 1;
MAA 4:c70ef089a3fd 89 }
MAA 4:c70ef089a3fd 90 crc_tab16[i] = crc;
MAA 4:c70ef089a3fd 91 }
MAA 4:c70ef089a3fd 92 crc_tab16_init = 1;
MAA 4:c70ef089a3fd 93 };
MAA 4:c70ef089a3fd 94
MAA 4:c70ef089a3fd 95
MAA 4:c70ef089a3fd 96 // The function update_crc_16 calculates a new CRC-16 value based on the
MAA 4:c70ef089a3fd 97 // previous value of the CRC and the next byte of the data to be checked.
MAA 4:c70ef089a3fd 98 unsigned short SPS::update_crc_16(unsigned short crc, char c)
MAA 4:c70ef089a3fd 99 {
MAA 4:c70ef089a3fd 100 unsigned short tmp, short_c;
MAA 4:c70ef089a3fd 101
MAA 4:c70ef089a3fd 102 short_c = 0x00ff & (unsigned short) c;
MAA 4:c70ef089a3fd 103
MAA 4:c70ef089a3fd 104 if (!crc_tab16_init)
MAA 4:c70ef089a3fd 105 init_crc16_tab();
MAA 4:c70ef089a3fd 106
MAA 4:c70ef089a3fd 107 tmp = crc ^ short_c;
MAA 4:c70ef089a3fd 108 crc = (crc >> 8) ^ crc_tab16[tmp & 0xff];
MAA 4:c70ef089a3fd 109
MAA 4:c70ef089a3fd 110 return crc;
MAA 4:c70ef089a3fd 111 };
MAA 4:c70ef089a3fd 112 //***************************************************************************