positioning updates

Dependents:   example-gnss

Fork of gnss by u-blox

Revision:
6:56eda66d585b
Parent:
1:ef70a58a6c98
--- a/TESTS/unit_tests/default/main.cpp	Sun Jun 11 13:45:56 2017 +0000
+++ b/TESTS/unit_tests/default/main.cpp	Wed Jun 14 20:44:42 2017 +0100
@@ -3,9 +3,6 @@
 #include "unity.h"
 #include "utest.h"
 #include "gnss.h"
-extern "C" {
-#include "c030_api.h"
-}
  
 using namespace utest::v1;
 
@@ -58,47 +55,55 @@
     char buffer[64];
     int responseLength = 0;
     int returnCode;
+    bool gotAck = false;
+    Timer timer;
 
     GnssSerial *pGnss = new GnssSerial();
 
-    // Initialise the GNSS chip and wait for it to start up
+    // Initialise the GNSS chip
     pGnss->init(NC);
-    wait_ms(1000);
 
-    // See ublox7-V14_ReceiverDescrProtSpec section 30.11.15 (CFG-NAV5)
-    // Set automotive mode, which should be acknowledged
-    memset (buffer, 0, sizeof (buffer));
-    buffer[0] = 0x00;
-    buffer[1] = 0x01; // Set dynamic config only
-    buffer[2] = 0x04; // Automotive
-    // Send length is 32 bytes of payload + 6 bytes header + 2 bytes CRC
-    TEST_ASSERT_EQUAL_INT (40, pGnss->sendUbx(0x06, 0x24, buffer, 32));
-    while (responseLength == 0) {
-        // Wait for the required Ack
-        returnCode = pGnss->getMessage(buffer, sizeof(buffer));
-        if ((returnCode != GnssSerial::WAIT) && (returnCode != GnssSerial::NOT_FOUND)) {
-            responseLength = LENGTH(returnCode);
-            if ((PROTOCOL(returnCode) == GnssSerial::UBX)) {
-                printHex(buffer, responseLength);
-                // Ack is  0xb5-62-05-00-02-00-msgclass-msgid-crcA-crcB
-                // Nack is 0xb5-62-05-01-02-00-msgclass-msgid-crcA-crcB
-                TEST_ASSERT_EQUAL_UINT8(0xb5, buffer[0]);
-                TEST_ASSERT_EQUAL_UINT8(0x62, buffer[1]);
-                TEST_ASSERT_EQUAL_UINT8(0x05, buffer[2]);
-                TEST_ASSERT_EQUAL_UINT8(0x00, buffer[3]);
-                TEST_ASSERT_EQUAL_UINT8(0x02, buffer[4]);
-                TEST_ASSERT_EQUAL_UINT8(0x00, buffer[5]);
-                TEST_ASSERT_EQUAL_UINT8(0x06, buffer[6]);
-                TEST_ASSERT_EQUAL_UINT8(0x24, buffer[7]);
-            } else if ((PROTOCOL(returnCode) == GnssSerial::NMEA)) {
-                printf ("%.*s", responseLength, buffer);
-                responseLength = 0;
-            } else {
-                printHex(buffer, responseLength);
-                responseLength = 0;
+    // Try this a few times as we might get no response
+    // if the GNSS chip is busy
+    for (int x = 0; (x < 3) && !gotAck; x++) {
+        // See ublox7-V14_ReceiverDescrProtSpec section 30.11.15 (CFG-NAV5)
+        // Set automotive mode, which should be acknowledged
+        memset (buffer, 0, sizeof (buffer));
+        buffer[0] = 0x00;
+        buffer[1] = 0x01; // Mask: set dynamic config only
+        buffer[2] = 0x04; // Dynamic platform model: automotive
+        // Send length is 32 bytes of payload + 6 bytes header + 2 bytes CRC
+        TEST_ASSERT_EQUAL_INT (40, pGnss->sendUbx(0x06, 0x24, buffer, 32));
+        printf ("CFG_NAV5 command sent, try %d.\n", x);
+        timer.start();
+        while ((!gotAck) && (timer.read_ms() < 1000)) {
+            // Wait for the required Ack
+            returnCode = pGnss->getMessage(buffer, sizeof(buffer));
+            if ((returnCode != GnssSerial::WAIT) && (returnCode != GnssSerial::NOT_FOUND)) {
+                responseLength = LENGTH(returnCode);
+                if ((PROTOCOL(returnCode) == GnssSerial::UBX)) {
+                    printHex(buffer, responseLength);
+                    // Ack is  0xb5-62-05-00-02-00-msgclass-msgid-crcA-crcB
+                    // Nack is 0xb5-62-05-01-02-00-msgclass-msgid-crcA-crcB
+                    TEST_ASSERT_EQUAL_UINT8(0xb5, buffer[0]);
+                    TEST_ASSERT_EQUAL_UINT8(0x62, buffer[1]);
+                    TEST_ASSERT_EQUAL_UINT8(0x05, buffer[2]);
+                    TEST_ASSERT_EQUAL_UINT8(0x00, buffer[3]);
+                    TEST_ASSERT_EQUAL_UINT8(0x02, buffer[4]);
+                    TEST_ASSERT_EQUAL_UINT8(0x00, buffer[5]);
+                    TEST_ASSERT_EQUAL_UINT8(0x06, buffer[6]);
+                    TEST_ASSERT_EQUAL_UINT8(0x24, buffer[7]);
+                    gotAck = true;
+                } else if ((PROTOCOL(returnCode) == GnssSerial::NMEA)) {
+                    printf ("%.*s", responseLength, buffer);
+                } else {
+                    printHex(buffer, responseLength);
+                }
             }
+            wait_ms (100);
         }
-        wait_ms (100);
+        timer.stop();
+        timer.reset();
     }
 }
 
@@ -216,8 +221,6 @@
 
 int main() {
 
-    c030_init(); // HACK
-
     return !Harness::run(specification);
 }