Library that implements the CellularInterface using PPP and LWIP on the mbed MCU. May be used on the C027 and C030 (non-N2xx flavour) boards from mbed 5.5 onwards.

Dependents:   example-ublox-cellular-interface HelloMQTT example-ublox-cellular-interface_r410M example-ublox-mbed-client

Revision:
1:80ec3fccad9e
Parent:
0:44dd95724bc2
Child:
3:9863dcade75d
diff -r 44dd95724bc2 -r 80ec3fccad9e TESTS/unit_tests/default/main.cpp
--- a/TESTS/unit_tests/default/main.cpp	Wed Jun 14 09:27:55 2017 +0000
+++ b/TESTS/unit_tests/default/main.cpp	Thu Jun 15 14:05:47 2017 +0100
@@ -9,10 +9,10 @@
 #include "mbed_trace.h"
 #define TRACE_GROUP "TEST"
 #else
-#define tr_debug(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
-#define tr_info(format, ...)  debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
-#define tr_warn(format, ...)  debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
-#define tr_error(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
+#define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__)
+#define tr_info(format, ...)  debug(format "\n", ## __VA_ARGS__)
+#define tr_warn(format, ...)  debug(format "\n", ## __VA_ARGS__)
+#define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__)
 #endif
 
 using namespace utest::v1;
@@ -21,7 +21,12 @@
 
 // IMPORTANT!!! if you make a change to the tests here you should
 // check whether the same change should be made to the tests under
-// the AT DATA driver.
+// the AT interface.
+
+// NOTE: these test are only as reliable as UDP across the internet
+// over a radio link.  The tests expect an NTP server to respond
+// to UDP packets and, if configured, an echo server to respond
+// to UDP packets.  This simply may not happen.  Please be patient.
 
 // ----------------------------------------------------------------
 // COMPILE-TIME MACROS
@@ -336,20 +341,34 @@
     char timeString[25];
     time_t TIME1970 = 2208988800U;
     int len;
+    UDPSocket sock;
+    SocketAddress ntp_address;
     bool comms_done = false;
 
     ntp_values[0] = '\x1b';
 
+    TEST_ASSERT(sock.open(interface) == 0)
+
+    TEST_ASSERT(interface->gethostbyname(MBED_CONF_APP_NTP_SERVER, &ntp_address) == 0);
+    ntp_address.set_port(MBED_CONF_APP_NTP_PORT);
+
+    tr_debug("UDP: NIST server %s address: %s on port %d.", MBED_CONF_APP_NTP_SERVER,
+             ntp_address.get_ip_address(), ntp_address.get_port());
+
+    sock.set_timeout(10000);
+
     // Retry this a few times, don't want to fail due to a flaky link
     for (unsigned int x = 0; !comms_done && (x < NUM_UDP_RETRIES); x++) {
-        sock->sendto(ntp_address, (void*) ntp_values, sizeof(ntp_values));
-        len = sock->recvfrom(&ntp_address, (void*) ntp_values, sizeof(ntp_values));
+        sock.sendto(ntp_address, (void*) ntp_values, sizeof(ntp_values));
+        len = sock.recvfrom(&ntp_address, (void*) ntp_values, sizeof(ntp_values));
         if (len > 0) {
             comms_done = true;
         }
     }
     TEST_ASSERT (comms_done);
-
+    
+    sock.close();
+    
     tr_debug("UDP: %d byte(s) returned by NTP server.", len);
     if (len >= 43) {
         timestamp |= ((int) *(ntp_values + 40)) << 24;
@@ -659,7 +678,7 @@
 
 // IMPORTANT!!! if you make a change to the tests here you should
 // check whether the same change should be made to the tests under
-// the AT DATA driver.
+// the AT interface.
 
 // Test cases
 Case cases[] = {
@@ -694,10 +713,10 @@
 
     mbed_trace_mutex_wait_function_set(lock);
     mbed_trace_mutex_release_function_set(unlock);
-
-    interface->connection_status_cb(callback(connection_down_cb));
 #endif
     
+    interface->connection_status_cb(callback(connection_down_cb));
+
     // Run tests
     return !Harness::run(specification);
 }