Multi-Hackers / GpsParser

Dependents:   MTDOT-EVB-LinkCheck-AL MTDOT-BOX-EVB-Factory-Firmware-LIB-108 TelitSensorToCloud mDot_sensor_to_cloud ... more

Revision:
10:465f9db415ea
Parent:
9:a4d4ab3b0f23
Child:
11:73e776e41d23
--- a/GPSPARSER.cpp	Mon Dec 14 09:08:31 2015 -0600
+++ b/GPSPARSER.cpp	Mon Jan 11 11:42:19 2016 -0600
@@ -57,12 +57,7 @@
     _num_satellites =0;
     _gps_detected = false;
 
-    if (GPSPARSER::initGps() == 0) {
-        _gps_detected = true;
-        _getSentenceThread.signal_set(START_THREAD);
-    } else {
-        _fix_status = 0;
-    }
+    _getSentenceThread.signal_set(START_THREAD);
 
     return;
 }
@@ -73,58 +68,6 @@
         _getSentenceThread.terminate();
 }
 
-uint8_t GPSPARSER::initGps (void)
-{
-
-    // this code is specific to the Skytraq Venus GPS chip. This code could be re-written to detect another type of
-    // GPS device. Maybe read serial port for a specific time and detect $GP from NEMA string
-
-    // Sets Skytraq Venus GPS to output GGA,GSA,GSV every 10 seconds, and RMC every second, no ZDA,GLL,VTG
-    // setup string for GPS                       GGA  GSA  GSV  GLL  RMC  VTG  ZDA       cksum
-    char init_gps[16] = {0xA0,0xA1,0x00,0x09,0x08,0x0A,0x0A,0x0A,0x00,0x01,0x00,0x00,0x00,0x03,0x0D,0x0A};
-    char chk_char;
-    uint8_t ret = 0;
-
-    _gps_uart->rxClear();
-
-    _gps_uart->write(init_gps,16);
-
-    do {
-        osDelay(10);
-    } while (!_gps_uart->txEmpty());
-
-    osDelay(15);
-
-    if (_gps_uart->readable()) {
-        do {
-            _gps_uart->read(chk_char,20);
-        } while ((chk_char != 0xA0) && (!_gps_uart->rxEmpty()));
-
-        if (chk_char == 0xA0) {
-            _gps_uart->read(chk_char,15);
-            if (chk_char != 0xA1) {
-                ret = 1;
-            } else {
-                _gps_uart->read(chk_char);
-                _gps_uart->read(chk_char);
-                _gps_uart->read(chk_char);
-                if (chk_char != 0x83) {
-                    ret = 1;
-                } else {
-                    _gps_uart->read(chk_char);
-                    //printf("config message acknowledged - ID - %x\r\n",chk_char);
-                }
-            }
-        } else {
-            ret = 1;
-        }
-    } else {
-        ret = 1;
-    }
-
-    return ret;
-}
-
 void GPSPARSER::startSentenceThread(void const *p)
 {
     GPSPARSER *instance = (GPSPARSER*)p;
@@ -133,6 +76,12 @@
 
 void GPSPARSER::readNemaSentence (void)
 {
+    // this code is specific to the Skytraq Venus GPS chip. This code could be re-written to detect another type of
+    // GPS device. Maybe read serial port for a specific time and detect $GP from NEMA string
+
+    // Sets Skytraq Venus GPS to output GGA,GSA,GSV every 10 seconds, and RMC every second, no ZDA,GLL,VTG
+    // setup string for GPS                       GGA  GSA  GSV  GLL  RMC  VTG  ZDA       cksum
+    char init_gps[16] = {0xA0,0xA1,0x00,0x09,0x08,0x0A,0x0A,0x0A,0x00,0x01,0x00,0x00,0x00,0x03,0x0D,0x0A};
     char chk_char;
     uint8_t calc_cksum;
     uint8_t nema_cksum;
@@ -141,6 +90,39 @@
     char cksum_str[2];
 
     _getSentenceThread.signal_wait(START_THREAD);
+    //printf("GPS starting\r\n");
+
+    _gps_uart->rxClear();
+    _gps_uart->write(init_gps, sizeof(init_gps));
+    while (! _gps_uart->readable())
+        osDelay(100);
+    do {
+        _gps_uart->read(chk_char);
+        //printf("read char %#X\r\n", chk_char);
+    } while ((chk_char != 0xA0) && (!_gps_uart->rxEmpty()));
+    if (chk_char == 0xA0) {
+        _gps_uart->read(chk_char);
+        //printf("read char %#X\r\n", chk_char);
+        if (chk_char == 0xA1) {
+            _gps_uart->read(chk_char);
+            //printf("read char %#X\r\n", chk_char);
+            _gps_uart->read(chk_char);
+            //printf("read char %#X\r\n", chk_char);
+            _gps_uart->read(chk_char);
+            //printf("read char %#X\r\n", chk_char);
+            if (chk_char == 0x83) {
+                _gps_detected = true;
+            }
+        }
+    }
+
+    //printf("GPS detected %s\r\n", _gps_detected ? "true" : "false");
+
+    if (! _gps_detected) {
+        _fix_status = 0;
+        return;
+    }
+
     if (_led) {
         _tick.attach(this, &GPSPARSER::blinker, 0.5);
         _tick_running = true;