:)

Dependencies:   mbed

Revision:
1:cfbdc934e8c6
Parent:
0:447ddbf579d9
--- a/main.cpp	Fri Mar 10 21:41:16 2017 +0000
+++ b/main.cpp	Sat Mar 18 20:49:10 2017 +0000
@@ -8,36 +8,43 @@
 Serial pc(SERIAL_TX,SERIAL_RX);
 DigitalOut myled(LED1);
 
-char nmea[MESS_LEN] = {0xA0};
+char nmea[MESS_LEN] = {0x00};
+char test[100];
 char gp[MAX_STR][STR_LEN]; 
 
 
 void read_nmea(void);           // read nmea message from gps module
 int chop_message(void);         // chop the nmea messeage
-void present_array(void);       // send a part of the available info to the laptop
-void setNmeaMessages(const bool , const bool , const bool , const bool , const bool , const bool ); 
+void present_gga_array(void);       // send a part of the available info to the laptop
+void present_vtg_array(void);       // send a part of the available info to the laptop
+void setNmeaMessages( bool ,  bool ,  bool ,  bool ,  bool ,  bool ); 
 void setUpdateRate(const uint8_t );
+void vtgMessage(bool);
+
 
 int main() {
      printf("HERE!\n");
      _gps.baud(9600);
-    setUpdateRate(10);
-    setNmeaMessages(true,true,true,true,true,true);    
-    
-    while (1) {
-    
+     //pc.baud(4800);
+    setUpdateRate(1);
+    setNmeaMessages(true,false,false,false,false,true);    
+    vtgMessage(true);
+    //setNavigationMode(0);
+    while(1){
         read_nmea();
+        
         chop_message();
-        present_array();
-        wait(1);
-        
+        present_gga_array();
+       // present_vtg_array();
+      
+       
     }
-   
 }
 
 //--------------------read nmea from GPS unit--------------------
 void read_nmea(void) {
     _gps.scanf("%s,",nmea);
+
     pc.printf("Raw message %s \n\r",nmea); // just for testing
 }
  
@@ -77,7 +84,7 @@
 }
  
 // --------------- Dump only $GPGGA on the screen------------------
-void present_array(void) {
+void present_gga_array(void) {
     if ((gp[0][2]=='P') and (gp[0][3]=='G') and (gp[0][4]=='G') and (gp[0][5]=='A')) {
         pc.printf("Chop results ");
         for (int k=0; k<MAX_STR; k++) {
@@ -86,15 +93,32 @@
         pc.printf("\n\r");
     }
 }
+
+// --------------- Dump only $GPVTG on the screen------------------
+void present_vtg_array(void) {
+    if ( (gp[0][3]=='V') and (gp[0][4]=='T') and (gp[0][5]=='G')) {
+        pc.printf("Chop results ");
+        for (int k=0; k<MAX_STR; k++) {
+            pc.printf("r%d=%s ",k, gp[k]);
+        }
+        pc.printf("\n\r");
+    }
+}
 //----------------Set Msg Command-----------------------------
-void setNmeaMessages(const bool gga, const bool gsa, const bool gsv, const bool gll, const bool rmc, const bool vtg) {
-    char cmd[16] = {
+void setNmeaMessages( bool gga,  bool gsa,  bool gsv,  bool gll,  bool rmc,  bool vtg) {
+   
+   //A0, A1, 00, 09 
+   //08, 01, 01, 01, 00, 01, 00, 00, 00, 
+   //08 0D 0A 
+   
+    char cmd[15] = {
         0xA0, 0xA1, 0x00, 0x09,
-        0x08, gga, gsa, gsv, gll, rmc, vtg, 0x00, 0x01,
+        0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,0,
         0x00, 0x0D, 0x0A
     };
-    for(int i = 4; i < 13; i++) cmd[13] ^= cmd[i];
-    for(int i = 0; i < 16; i++) _gps.putc(cmd[i]);
+    
+    for(int i = 4; i < 12; i++) cmd[12] ^= cmd[i];
+    for(int i = 0; i < 15; i++) _gps.putc(cmd[i]);
 }
 
 //----------------Set Update Rate-----------------------------
@@ -106,4 +130,26 @@
     };
     for(int i = 4; i < 7; i++) cmd[7] ^= cmd[i];
     for(int i = 0; i < 10; i++) _gps.putc(cmd[i]);
-}
\ No newline at end of file
+}
+
+//----------------Enable VTG---------------------------------
+void vtgMessage(bool enable){
+     if (enable) {
+        _gps.printf("$PSRF103,05,00,01,01*20\r\n");     // Enable VTG 
+    } 
+    else {
+        _gps.printf("$PSRF103,05,00,00,01*21\r\n");     // Disable VTG 
+    }
+}
+
+//---------------Set Navigation Mode--------------------------
+void setNavigationMode(const int mode) {
+    char cmd[] = {
+       0xA0, 0xA1, 0x00, 0x02,
+       0xB5, 0x00,
+       0x00, 0x0D, 0x0A 
+    };
+    for(int i = 4; i < 6; i++) cmd[6] ^= cmd[i];
+    for(int i = 0; i < 10; i++) _gps.putc(cmd[i]);
+}
+ 
\ No newline at end of file