GPS module (GYSFDMAXB) 57600 bps
Dependents: HAPS_GPS_Test_0001
GYSFDMAXB GPSセンサーGYSFDMAXBのライブラリ 57600 bps
手順 [1] シリアルピンを設定 GYSFDMAXB gps(tx_pin, rx_pin); [2] 零点を設定する(NED座標系における零点) gps.Initialize(); [3] 自動的にデータを受信しては更新していくので、適宜メンバ変数を読み込んで使う
Diff: GYSFDMAXB.cpp
- Revision:
- 6:db9f8d2afab7
- Parent:
- 5:6fc37ae3f262
- Child:
- 9:8595608c56ca
diff -r 6fc37ae3f262 -r db9f8d2afab7 GYSFDMAXB.cpp --- a/GYSFDMAXB.cpp Fri Apr 23 11:25:01 2021 +0000 +++ b/GYSFDMAXB.cpp Fri Apr 23 11:52:33 2021 +0000 @@ -19,7 +19,7 @@ } serial.baud(57600); serial.attach(this, &GYSFDMAXB::Receive, Serial::RxIrq); - timer.attach(this, &GYSFDMAXB::Punctuate, 0.01); + timer.attach(this, &GYSFDMAXB::Punctuate, 0.1); } void GYSFDMAXB::Receive() @@ -70,138 +70,135 @@ void GYSFDMAXB::Update() { -// if (receive_flag){ - for (int i = 0; i < start_size; i++) + for (int i = 0; i < start_size; i++) + { + if (uart_start[i] != NULL) { - if (uart_start[i] != NULL) + char str[256]; + char* p[64]; + int p_index = 0; + for (int j = 0; j < 64; j++) + { + p[j] = NULL; + } + strcpy(str, uart_start[i]); + + + char checksum = 0; + int c_i = 1; + while (str[c_i] !='*') { - char str[256]; - char* p[16]; - int p_index = 0; - for (int j = 0; j < 16; j++) + checksum ^= str[c_i]; + c_i++; + } + char data_checksum = 0; + char cc; + cc = str[c_i+1]; + if ('0' <= cc && cc <= '9') + data_checksum += (cc-'0')*16; + else + data_checksum += ((cc-'A')+10)*16; + cc = str[c_i+2]; + if ('0' <= cc && cc <= '9') + data_checksum += (cc-'0'); + else + data_checksum += ((cc-'A')+10); + if (data_checksum != checksum) + { + continue; + } + + + int j = 0; + p[p_index] = str; + p_index++; + while (1) + { + if (str[j] == ',') { - p[j] = NULL; - } - strcpy(str, uart_start[i]); - - - char checksum = 0; - int c_i = 1; - while (str[c_i] !='*') - { - checksum ^= str[c_i]; - c_i++; + p[p_index] = &(str[j + 1]); + p_index++; + str[j] = '\0'; } - char data_checksum = 0; - char cc; - cc = str[c_i+1]; - if ('0' <= cc && cc <= '9') - data_checksum += (cc-'0')*16; - else - data_checksum += ((cc-'A')+10)*16; - cc = str[c_i+2]; - if ('0' <= cc && cc <= '9') - data_checksum += (cc-'0'); - else - data_checksum += ((cc-'A')+10); - if (data_checksum != checksum) - { - continue; - } - - - int j = 0; - p[p_index] = str; - p_index++; - while (1) - { - if (str[j] == ',') - { - p[p_index] = &(str[j + 1]); - p_index++; - str[j] = '\0'; - } - else if (str[j] == '\0') - { - break; - } - j++; - } - - - if (strcmp(p[0], "$GPGGA") == 0) + else if (str[j] == '\0') { - if (p[6][0] != '\0') - Quality = atoi(p[6]); - Satellites = 0; - if (p[7][0] != '\0') - Satellites = atoi(p[7]); - if (p[8][0] != '\0') - HDOP = atof(p[8]); - if (p[9][0] != '\0') - Elevation = atof(p[9]); - UnitElevation = p[10][0]; - if (p[11][0] != '\0') - GeoidElevation = atof(p[11]); - UnitGeoidElevation = p[10][0]; + break; } - else if (strcmp(p[0], "$GPGLL") == 0) - { - } - else if (strcmp(p[0], "$GPGSA") == 0) - { - } - else if (strcmp(p[0], "$GPGSV") == 0) - { - } - else if (strcmp(p[0], "$GPRMC") == 0) + j++; + } + + + if (strcmp(p[0], "$GPGGA") == 0) + { + if (p[6][0] != '\0') + Quality = atoi(p[6]); + Satellites = 0; + if (p[7][0] != '\0') + Satellites = atoi(p[7]); + if (p[8][0] != '\0') + HDOP = atof(p[8]); + if (p[9][0] != '\0') + Elevation = atof(p[9]); + UnitElevation = p[10][0]; + if (p[11][0] != '\0') + GeoidElevation = atof(p[11]); + UnitGeoidElevation = p[10][0]; + } + else if (strcmp(p[0], "$GPGLL") == 0) + { + } + else if (strcmp(p[0], "$GPGSA") == 0) + { + } + else if (strcmp(p[0], "$GPGSV") == 0) + { + } + else if (strcmp(p[0], "$GPRMC") == 0) + { + float _ms_deg_1; + int _ms_deg_2; + Hours = (p[1][0]-'0')*10+(p[1][1]-'0'); + Minutes = (p[1][2]-'0')*10+(p[1][3]-'0'); + Seconds = (p[1][4]-'0')*10+(p[1][5]-'0'); + Milliseconds = (p[1][7]-'0')*100+(p[1][8]-'0')*10+(p[1][9]-'0'); + Status = p[2][0]; + if (p[3][0] != '\0') { - float _ms_deg_1; - int _ms_deg_2; - Hours = (p[1][0]-'0')*10+(p[1][1]-'0'); - Minutes = (p[1][2]-'0')*10+(p[1][3]-'0'); - Seconds = (p[1][4]-'0')*10+(p[1][5]-'0'); - Milliseconds = (p[1][7]-'0')*100+(p[1][8]-'0')*10+(p[1][9]-'0'); - Status = p[2][0]; - if (p[3][0] != '\0') - { - _ms_deg_1 = atof(p[3]); - _ms_deg_2 = (int)_ms_deg_1 / 100; - Latitude = _ms_deg_2 + (_ms_deg_1-100.0f*_ms_deg_2)/60.0f; - } - N_S = p[4][0]; - if (p[5][0] != '\0') - { - _ms_deg_1 = atof(p[5]); - _ms_deg_2 = (int)_ms_deg_1 / 100; - Longitude = _ms_deg_2 + (_ms_deg_1-100.0f*_ms_deg_2)/60.0f; - } - E_W = p[6][0]; - if (p[7][0] != '\0') - Speed = atof(p[7]); - if (p[8][0] != '\0') - Direction = atof(p[8]); - Day = (p[9][0]-'0')*10+(p[9][1]-'0'); - Month = (p[9][2]-'0')*10+(p[9][3]-'0'); - Year = (p[9][4]-'0')*10+(p[9][5]-'0'); - if (p[10][0] != '\0') - GeomagneticDeclination = atof(p[10]); - GeomagneticE_W = p[11][0]; - Mode = p[12][0]; + _ms_deg_1 = atof(p[3]); + _ms_deg_2 = (int)_ms_deg_1 / 100; + Latitude = _ms_deg_2 + (_ms_deg_1-100.0f*_ms_deg_2)/60.0f; + } + N_S = p[4][0]; + if (p[5][0] != '\0') + { + _ms_deg_1 = atof(p[5]); + _ms_deg_2 = (int)_ms_deg_1 / 100; + Longitude = _ms_deg_2 + (_ms_deg_1-100.0f*_ms_deg_2)/60.0f; } - else if (strcmp(p[0], "$GPVTG") == 0) - { - } - else if (strcmp(p[0], "$GPZDA") == 0) - { - uart_index = 0; - } - - uart_start[i] = NULL; + E_W = p[6][0]; + if (p[7][0] != '\0') + Speed = atof(p[7]); + if (p[8][0] != '\0') + Direction = atof(p[8]); + Day = (p[9][0]-'0')*10+(p[9][1]-'0'); + Month = (p[9][2]-'0')*10+(p[9][3]-'0'); + Year = (p[9][4]-'0')*10+(p[9][5]-'0'); + if (p[10][0] != '\0') + GeomagneticDeclination = atof(p[10]); + GeomagneticE_W = p[11][0]; + Mode = p[12][0]; } + else if (strcmp(p[0], "$GPVTG") == 0) + { + } + else if (strcmp(p[0], "$GPZDA") == 0) + { + uart_index = 0; + } + + uart_start[i] = NULL; } -// receive_flag = false; -// } + } } void GYSFDMAXB::Initialize() @@ -209,7 +206,6 @@ Satellites = 0; while (Satellites <= 4 || Latitude == 0.0f || Longitude == 0.0f || Elevation == 0.0f) { - Update(); } CalcurateUnit(); }