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.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
Diff: tests/blinky_ping_test.h
- Revision:
 - 26:f3e06d63967f
 - Child:
 - 31:31b95ea90f80
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/blinky_ping_test.h	Tue Dec 17 20:52:05 2013 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+#include "include_me.h"
+
+#define MAX_TRIES 5
+
+bool ping_test(const std::string& apn, const std::string& server);
+void blinkLed(DigitalOut led);
+
+void blinkyPingTest() {
+    DigitalOut ledG(LED1);
+    DigitalOut ledR(LED2);
+    std::string apn = "wap.cingular";
+    std::string server = "8.8.8.8";
+    
+    ledG = 1;
+    ledR = 1;
+        
+    if (ping_test(apn, server)) {
+        printf("success!\n\r");
+        blinkLed(ledG);
+    } else {
+        printf("failure!\n\r");
+        blinkLed(ledR);
+    }
+}
+
+bool ping_test(const std::string& apn, const std::string& server) {
+    int i;
+    
+    MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
+    serial->baud(115200);
+    Cellular* cell = Cellular::getInstance(serial);
+    
+    printf("waiting for radio\n\r");
+    wait(30);
+
+    i = 0;
+    printf("setting APN to %s\n\r", apn.c_str());
+    while (i++ < MAX_TRIES) {
+        if (cell->setApn(apn) == Cellular::OK) {
+            printf("successfully set APN\n\r");
+            break;
+        } else if (i > MAX_TRIES) {
+            printf("failed to set APN\n\r");
+            return false;
+        }
+        wait(1);
+    }
+    
+    i = 0;
+    printf("bringing up PPP link\n\r");
+    while (i++ < MAX_TRIES) {
+        if (cell->connect()) {
+            printf("PPP link is up\n\r");
+            break;
+        } else if (i > MAX_TRIES) {
+            printf("failed to bring PPP link up\n\r");
+            return false;
+        }
+        wait(1);
+    }
+    
+    printf("pinging %s\n\r", server.c_str());
+    return cell->ping(server);
+}
+
+void blinkLed(DigitalOut led) {
+    led = 0;
+    
+    while (true) {
+        wait(0.25);
+        led = !led;
+    }
+}
\ No newline at end of file
    
            uIP Socket Modem Shield (Outdated - see below)