spiralray gps decoder

Dependents:   SakuraIO_Evaluation_Board_Standard SakuraIO_Evalution_Board_Standard sakuraio_plus_rental_server

Files at this revision

API Documentation at this revision

Comitter:
misodengaku
Date:
Tue Jan 15 06:51:48 2019 +0000
Parent:
3:fd806214d7cc
Commit message:
add GGA message support

Changed in this revision

gps.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r fd806214d7cc -r 82d2fced184b gps.cpp
--- a/gps.cpp	Wed Nov 29 06:25:52 2017 +0000
+++ b/gps.cpp	Tue Jan 15 06:51:48 2019 +0000
@@ -13,9 +13,9 @@
         printf("invalid message\n");
         return;
     }
-    
+
     uint8_t nmea_line_index = split(nmea_line, ',', nmea_lines, MAXTOKEN);
-    #if 0
+#if 0
     for (int i = 0; i < nmea_line_index; i++) {
         printf("[%2d]%s\r\n", i, nmea_lines[i]);
     }
@@ -71,6 +71,36 @@
             longitude = 0;
             latitude = 0;
         }
+    } else if (strcmp((nmea_lines[0]) + 3, "GGA") == 0) {
+        double decimal_part[2] = {0};
+
+        /* 時刻のデコード */
+        hour = (uint8_t)str2int(nmea_lines[1], 2);
+        min = (uint8_t)str2int(nmea_lines[1] + 2, 2);
+        sec = (uint8_t)str2int(nmea_lines[1] + 4, 2);
+        msec = (uint16_t)str2int(nmea_lines[1] + 7, 3);
+
+        // GGAでは日付は不明
+
+        /* 位置情報のデコード */
+        decimal_part[0] = modf(strtof(nmea_lines[2], NULL), &latitude); // 秒
+        latitude /= 100;
+        decimal_part[1] = floor((modf(latitude, &latitude) * 100) + 0.5); // 分
+        latitude += (decimal_part[1] + decimal_part[0]) / 60;
+
+        if (nmea_lines[3][0] == 'S')
+            latitude = -latitude;
+
+        decimal_part[0] = modf(strtof(nmea_lines[4], NULL), &longitude); // 秒
+        longitude /= 100;
+        decimal_part[1] = floor((modf(longitude, &longitude) * 100) + 0.5); // 分
+        longitude += (decimal_part[1] + decimal_part[0]) / 60;
+
+        if (nmea_lines[5][0] == 'W')
+            longitude = -longitude;
+
+        // 移動速度と移動方向はGGAではわからない
+
     }
 }
 
@@ -82,6 +112,7 @@
     char checksum_str[3] = {0};
 
     if (nmea_line[0] != '$') {
+//        printf("invalid preamble %02X\n", nmea_line[0]);
         return 1;
     }
 
@@ -100,8 +131,10 @@
         }
     }
     if (checksum != nmea_checksum) {
+//        printf("invalid checksum\n");
         return 2;
     }
+//    printf("validation passed\n");
     return 0;
 }
 
@@ -139,7 +172,7 @@
     t.tm_mday = day;
     t.tm_mon = month - 1;
     t.tm_year = year - 1900;
- 
+
     return mktime(&t);
 }