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

Files at this revision

API Documentation at this revision

Comitter:
rob.meades@u-blox.com
Date:
Thu Jun 15 14:05:47 2017 +0100
Parent:
0:44dd95724bc2
Child:
2:4c533665168c
Commit message:
Bring PPP interface code up to date with AT interface code and test on both C030 and C027 platforms.

Changed in this revision

TESTS/unit_tests/default/main.cpp Show annotated file Show diff for this revision Revisions of this file
TESTS/unit_tests/default/template_mbed_app.txt Show annotated file Show diff for this revision Revisions of this file
UbloxPPPCellularInterface.h Show annotated file Show diff for this revision Revisions of this file
--- 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);
 }
--- a/TESTS/unit_tests/default/template_mbed_app.txt	Wed Jun 14 09:27:55 2017 +0000
+++ b/TESTS/unit_tests/default/template_mbed_app.txt	Thu Jun 15 14:05:47 2017 +0100
@@ -1,12 +1,5 @@
 {
     "config": {
-        "platform": {
-            "help": "The platform for the cellular feature, e.g. UBLOX or MTS_DRAGONFLY",
-            "value": "UBLOX"
-        },
-        "buffer-size": {
-            "value": 0
-        },
         "debug-on": {
             "help": "Set to true to get AT interface debug",
             "value": false
@@ -74,15 +67,13 @@
     },
     "target_overrides": {
         "*": {
+            "target.features_add": ["LWIP", "COMMON_PAL"],
+            "platform.stdio-convert-newlines": true,
             "lwip.ipv4-enabled": true,
             "lwip.ipv6-enabled": false,
             "lwip.ethernet-enabled": false,
             "lwip.ppp-enabled": true,
             "lwip.tcp-enabled": true,
-            "target.features_add": ["LWIP", "COMMON_PAL"],
-            "platform.stdio-convert-newlines": true,
-            "platform.stdio-baud-rate": 9600,
-            "platform.default-serial-baud-rate": 115200, 
             "lwip.debug-enabled": false,
             "lwip.enable-ppp-trace": false,
             "lwip.use-mbed-trace": false,
--- a/UbloxPPPCellularInterface.h	Wed Jun 14 09:27:55 2017 +0000
+++ b/UbloxPPPCellularInterface.h	Thu Jun 15 14:05:47 2017 +0100
@@ -44,7 +44,7 @@
  *  LWIP running on the mbed MCU, connected to the modem via PPP.
  */
 class UbloxPPPCellularInterface : public CellularBase,
-                                      virtual public UbloxCellularBase {
+                                  virtual public UbloxCellularBase {
 
 public:
     /** Constructor.
@@ -55,9 +55,9 @@
      * @param debug_on true to switch AT interface debug on, otherwise false.
      */
     UbloxPPPCellularInterface(PinName tx = MDMTXD,
-                                  PinName rx = MDMRXD,
-                                  int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE,
-                                  bool debug_on = false);
+                              PinName rx = MDMRXD,
+                              int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE,
+                              bool debug_on = false);
 
     /* Destructor.
      */
@@ -237,6 +237,6 @@
     bool set_atd();
 };
 
-#endif //NSAPI_PPP_AVAILABLE
-#endif //_UBLOX_PPP_CELLULAR_INTERFACE_
+#endif // NSAPI_PPP_AVAILABLE
+#endif // _UBLOX_PPP_CELLULAR_INTERFACE_