Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 51:6a158dcc7457
- Parent:
- 50:84723ac07ea5
- Child:
- 52:4c282feb57eb
diff -r 84723ac07ea5 -r 6a158dcc7457 main.cpp
--- a/main.cpp Thu Jun 02 11:07:31 2022 +0000
+++ b/main.cpp Thu Jun 02 13:56:39 2022 +0200
@@ -1,10 +1,10 @@
-#include "mbed.h"
-#include "greentea-client/test_env.h"
-#include "unity.h"
-#include "utest.h"
-#include "gnss.h"
+#include <mbed.h>
+//#include "greentea-client/test_env.h"
+//#include "unity.h"
+//#include "utest.h"
+#include <gnss.h>
-using namespace utest::v1;
+//using namespace utest::v1;
// ----------------------------------------------------------------
// COMPILE-TIME MACROS
@@ -58,7 +58,7 @@
bool gotAck = false;
Timer timer;
- GnssSerial *pGnss = new GnssSerial();
+ GnssSerial *pGnss = new GnssSerial(PA_9, PA_10, 38400);
// Initialise the GNSS chip
pGnss->init(NC);
@@ -73,10 +73,10 @@
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));
+ //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)) {
+ while ((!gotAck) && (std::chrono::duration_cast<std::chrono::milliseconds>(timer.elapsed_time()).count() < 1000)) {
// Wait for the required Ack
returnCode = pGnss->getMessage(buffer, sizeof(buffer));
if ((returnCode != GnssSerial::WAIT) && (returnCode != GnssSerial::NOT_FOUND)) {
@@ -85,14 +85,14 @@
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]);
+ //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);
@@ -100,7 +100,7 @@
printHex(buffer, responseLength);
}
}
- wait_ms (100);
+ thread_sleep_for(100); //wait_ms (100);
}
timer.stop();
timer.reset();
@@ -109,7 +109,7 @@
// Test getting a response from GNSS using the serial interface
void test_serial_time() {
- GnssSerial *pGnss = new GnssSerial();
+ GnssSerial *pGnss = new GnssSerial(PA_9, PA_10, 38400);
bool gotLatLong = false;
bool gotElevation = false;
@@ -186,42 +186,27 @@
}
}
- wait_ms(1000);
+ thread_sleep_for(1000); //wait_ms(1000);
}
printf("\n");
// Depending on antenna positioning we may not be able to get a GNSS fix but we
// should at least be able to receive the time from a satellite
- TEST_ASSERT(gotTime);
-}
-
-// ----------------------------------------------------------------
-// TEST ENVIRONMENT
-// ----------------------------------------------------------------
-
-// Setup the test environment
-utest::v1::status_t test_setup(const size_t number_of_cases) {
- // Setup Greentea with a timeout
- GREENTEA_SETUP(120, "default_auto");
- return verbose_test_setup_handler(number_of_cases);
+ //TEST_ASSERT(gotTime);
}
-// Test cases
-Case cases[] = {
- Case("Ubx command", test_serial_ubx),
- Case("Get time", test_serial_time),
-};
-
-Specification specification(test_setup, cases);
-
-// ----------------------------------------------------------------
-// MAIN
-// ----------------------------------------------------------------
-
int main() {
- return !Harness::run(specification);
+ DigitalOut user_led(LED1); // create DigitalOut object to command user led
+
+ test_serial_time();
+
+ while (true) {
+ printf(" main ended\r\n");
+ user_led = !user_led;
+ thread_sleep_for(1000);
+ }
}
// End Of File