インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラム。   CQ publishing Interface 2014.10 issue, C027 3G test program.

Dependencies:   C027_Support C027_SupportTest mbed picojson

Fork of C027_SupportTest by u-blox

インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラムです。

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Wed May 14 05:56:27 2014 +0000
Parent:
15:ea10b6cf8c85
Child:
17:c293780a40ac
Commit message:
added tests for large buffers (using our echo server)

Changed in this revision

C027_Support.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/C027_Support.lib	Tue May 13 09:35:14 2014 +0000
+++ b/C027_Support.lib	Wed May 14 05:56:27 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/ublox/code/C027_Support/#869bd35f44cc
+http://mbed.org/teams/ublox/code/C027_Support/#4d6fa520dfca
--- a/main.cpp	Tue May 13 09:35:14 2014 +0000
+++ b/main.cpp	Wed May 14 05:56:27 2014 +0000
@@ -71,7 +71,7 @@
 int main(void)
 {
     int ret;
-    char buf[512] = "";
+    char buf[2048] = "";
 
     // only trace if the serial is different from our modem port
     if (DOTRACE) {
@@ -138,6 +138,7 @@
             if (socket >= 0)
             {
                 TRACE("Socket Connect\r\n");
+                mdm.socketSetBlocking(socket, 10000);
                 if (mdm.socketConnect(socket, "mbed.org", 80))
                 {
                     TRACE("Make a Http Post Request\r\n");
@@ -162,6 +163,74 @@
                 mdm.socketFree(socket);
             }
             
+            int port = 7;
+            const char* host = "echo.u-blox.com";
+            MDMParser::IP ip = mdm.gethostbyname(host);
+            char data[] = "\r\nxxx Socket Hello World\r\n"
+#if 1
+            "00  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "01  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "02  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "03  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "04  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            
+            "05  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "06  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "07  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "08  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "09  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+
+            "10  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "11  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "12  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "13  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "14  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            
+            "15  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "16  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "17  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "18  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "19  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+#endif            
+            "End\r\n";
+                
+            TRACE("Testing TCP sockets with ECHO server\r\n");
+            socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
+            if (socket >= 0)
+            {
+                mdm.socketSetBlocking(socket, 10000);
+                if (mdm.socketConnect(socket, host, port)) {
+                    memcpy(data, "\r\nTCP", 5); 
+                    ret = mdm.socketSend(socket, data, sizeof(data)-1);
+                    if (ret == sizeof(data)-1) {
+                        TRACE("Socket Send %d \"%s\"\r\n", ret, data);
+                    }
+                    ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
+                    if (ret >= 0) {
+                        TRACE("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf);
+                    }
+                    mdm.socketClose(socket);
+                }
+                mdm.socketFree(socket);
+            }
+
+            TRACE("Testing UDP sockets with ECHO server\r\n");
+            socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port);
+            if (socket >= 0)
+            {
+                mdm.socketSetBlocking(socket, 10000);
+                memcpy(data, "\r\nUDP", 5); 
+                ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1);
+                if (ret == sizeof(data)-1) {
+                    TRACE("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data);
+                }
+                ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1);
+                if (ret >= 0) {
+                    TRACE("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf);
+                }
+                mdm.socketFree(socket);
+            }
+            
             // disconnect  
             TRACE("Network Disconnect\r\n");
             mdm.disconnect();