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.
Dependencies: C12832 mbed-rtos mbed websocket_demo
Fork of NNN40_CLI_HOST_WIFI by
Revision 12:b68d0162da48, committed 2015-07-21
- Comitter:
- gordonlu
- Date:
- Tue Jul 21 07:44:13 2015 +0000
- Parent:
- 11:362f6022ffef
- Child:
- 13:c9ecf749d6fd
- Commit message:
- NNN40_CLI_HOST_WIFI : 1.0.2;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jul 17 08:12:29 2015 +0000
+++ b/main.cpp Tue Jul 21 07:44:13 2015 +0000
@@ -39,7 +39,7 @@
//version string
-#define VERSION_STRING ("NNN40_CLI_HOST_WIFI : 1.0.1")
+#define VERSION_STRING ("NNN40_CLI_HOST_WIFI : 1.0.2")
enum WORKINGSTAGE {INITWIFI, TCP_CONNECT_TO_HOST, TCP_LISTEN_FROM_CLIENT, TCP_SEND, TCP_RECEIVE};
@@ -215,7 +215,7 @@
if(!CLI_CMD(cmd))return false;
//init ethernet
- if(!CLI_CMD("cynw ethernet_init\r"))return false;
+ if(!CLI_CMD("cynw ethernet_init\r",10))return false;
//connecting...,
if (!CLI_CMD("cynw ethernet_connect 40000\r",45))return false;
@@ -261,7 +261,7 @@
if(!CLI_CMD("cynw tcp_server_listen\r")) return false;
//accept
- if(!CLI_CMD("cynw tcp_server_accept\r",20)) return false;
+ if(!CLI_CMD("cynw tcp_server_accept\r",10)) return false;
return true;
}
@@ -272,26 +272,26 @@
sprintf(cmd, "cynw tcp_connection_send %s\r",data);
return CLI_CMD(cmd);
}
-bool receive(char * buf, int len, int timeout_ms)
+bool receive(char * buf, int len, int timeout_sec)
{
if(len > 128) len = 128;
char cmd[CLI_COMMAND_MAX_SIZE];
- if(-1 == timeout_ms)//blocking
+ if(-1 == timeout_sec)//blocking
{
sprintf(cmd, "%s" , "cynw tcp_connection_blocking 1\r");
}
else //non-blocking
{
- sprintf(cmd, "cynw tcp_connection_blocking 0 %d\r",timeout_ms);
+ sprintf(cmd, "cynw tcp_connection_blocking 0 %d\r",timeout_sec * 1000);
}
if(!CLI_CMD(cmd)) return false;
- sprintf(cmd, "cynw tcp_connection_receive_all %d" , len);
- if(!CLI_CMD(cmd)) return false;
+ sprintf(cmd, "cynw tcp_connection_receive %d\r" , len);
+ if(!CLI_CMD(cmd,timeout_sec + 2)) return false;
return true;
@@ -379,6 +379,7 @@
if(send(buf))
{
++tx;
+ if(tx % 10 == 0) ws = TCP_RECEIVE; //change to receive
}
else if(!isTCPConnected())
{
@@ -394,7 +395,18 @@
case TCP_RECEIVE:
{
char buf[CLI_RECEIVE_DATA_MAX_SIZE];
- receive(buf, 10, 2000);
+ if(!receive(buf, 5, 5) && !isTCPConnected())
+ {
+ #if(TEST_TCP_CLIENT == 1) //NNN40 as client
+ ws = TCP_CONNECT_TO_HOST;
+ #else //NNN40 as server
+ ws = TCP_LISTEN_FROM_CLIENT;
+ #endif
+ }
+ else
+ {
+ ws = TCP_SEND; //change to send
+ }
break;
}
default:break;
