GPS test

Dependencies:   mbed GYSFDMAXB

Revision:
1:020b393621e5
Parent:
0:f7f81e36e9d7
Child:
3:25e3289b0411
diff -r f7f81e36e9d7 -r 020b393621e5 main.cpp
--- a/main.cpp	Mon Apr 05 09:18:42 2021 +0000
+++ b/main.cpp	Tue Apr 06 08:05:10 2021 +0000
@@ -1,73 +1,53 @@
 #include "mbed.h"
-#include "AsyncSerial.hpp"
 #include <string.h>
-//"include <strlib.h>
+#include "GYSFDMAXB.hpp"
 
 Serial pc(USBTX, USBRX);
-Serial gps(PC_12, PD_2);
-
-void GPS_Read();
+GYSFDMAXB gps(PC_12, PD_2);
 
-const int uart_max = 1000;
-int uart_start = 0;
-int uart_index = 0;
-char uart_buffer[uart_max];
-
-void gps_receive()
+void Display()
 {
-    while (gps.readable())
-    {
-        char c;
-        c = gps.getc();
-        uart_buffer[uart_index] = c;
-        if (c == '$')
-        {
-            uart_start = uart_index;
-        }
-        if (c == '\n')
-        {
-            GPS_Read();
-        }
-        uart_index = (uart_index + 1) % uart_max;
-    }
-}
-
-
-void GPS_Read()
-{
-    char line[256];
-    for (int i = 0 ;i < 256; i++)
-    {
-        line[i] = 0;
-    }
-    bool flag = false;
-    int counts = 0;
-    for (int i = 0; i < 256; i++)
-    {
-        line[i] = uart_buffer[(uart_start + i) % uart_max];
-        counts++;
-        if (line[i] == '\n')
-        {
-            flag = true;
-            break;
-        }
-    }
-    if (flag)
-    {
-        pc.printf("Counts:%d\r\n", counts);
-        pc.printf("%s\r\n", line);
-    }
+    pc.printf("################################\r\n");
+    pc.printf("%d h %d m %d s %d ms\r\n", gps.Hours, gps.Minutes, gps.Seconds, gps.Milliseconds);
+    pc.printf("%d / %d / %d\r\n", gps.Year, gps.Month, gps.Day);
+    pc.printf("latitude  : %c %f\r\n", gps.N_S, gps.Latitude);
+    pc.printf("longitude : %c %f\r\n", gps.E_W, gps.Longitude);
+    pc.printf("elevation : %f\r\n", gps.Elevation);
+    gps.Calcurate();
+    pc.printf("Local X : %f\r\n", gps.Position.x);
+    pc.printf("Local Y : %f\r\n", gps.Position.y);
+    pc.printf("Local Z : %f\r\n", gps.Position.z);
 }
 
 int main()
 {
     pc.baud(115200);
-    gps.baud(57600);
-    gps.attach(gps_receive, Serial::RxIrq);
+    Ticker ticker;
+    ticker.attach(&Display, 0.3);
+    gps.CalcurateUnit();
+    
     while (1)
     {
-//        GPS_Read();
-//        pc.printf("A\n");
-        
+        gps.Update();
     }
-}
\ No newline at end of file
+}
+
+
+// GPS baud rate
+/*
+Serial gps(PC_12, PD_2);
+int main()
+{
+    gps.baud(9600);
+    while (1)
+    {
+        gps.printf("$PMTK251,57600*2C\r\n");
+    }
+}
+*/
+
+/*
+$PMTK251,115200*1F\r\n
+$PMTK251,57600*2C\r\n
+$PMTK251,9600*17\r\n
+*/
\ No newline at end of file