Dependencies:   BLE_API WIFI_API_32kRAM mbed nRF51822

Fork of NNN40_CLI by Delta

Revision:
10:5f1fa331d07c
Parent:
9:ff3ccba5dc16
Child:
12:a91455702763
--- a/CLI_Source/wifi_cli.cpp	Mon Jan 25 11:19:12 2016 +0000
+++ b/CLI_Source/wifi_cli.cpp	Tue Jan 26 09:31:06 2016 +0000
@@ -38,12 +38,14 @@
 static unsigned char *newSSID;
 static scanApInfo saveAP[WIFI_MAX_AP_NUMBER];
 static bool wifiIniState = false;
+static bool wifiDataInt = false; // wifi receive callback flag
 
 typedef struct deviceNetwork_s {
     char ap_ssid[AP_SSID_MAX_LEN+1];
     char ap_pw[AP_PW_MAX_LEN+1];
 } deviceNetwork_t;
 deviceNetwork_t devNetwork[4]; // 0-2 for setNetwork, 3 for set_ap
+DigitalOut wifiWriteInt(p30); 
 
 static uint8_t cyntecIsValidIP(uint8_t *startIdx, uint8_t totalLen)
 {
@@ -445,8 +447,8 @@
     int timeout_ms = 35000;
     uint8_t *argTimeout;
     EthernetInterface ethInterface;
-	if (cyntecGetCommandTokenCnt() != 2 & cyntecGetCommandTokenCnt() != 3)
-		cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
+    if (cyntecGetCommandTokenCnt() != 2 & cyntecGetCommandTokenCnt() != 3)
+        cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
     if (cyntecGetCommandTokenCnt() == 2) {
 #ifdef DELTA_WIFI_DEBUG
         console.printf("\r\n");
@@ -750,7 +752,7 @@
     if (cyntecGetCommandTokenCnt() == 3) {
         /* handle Message arg */
         argLen = atoi((const char *)cyntecGetCommandArgument(0, NULL));
-
+		//console.printf("argLen:%d\r\n",argLen);
         if (argLen > TCP_SEND_MAX_LEN || argLen < 0) {
             cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
             return;
@@ -1086,23 +1088,46 @@
     console.printf("\r\nOK;%d\r\n\r\n",cliEndpoint.get_port());
 }
 
+static void cyn_wifi_enint()
+{
+    wifiDataInt = true;
+    cyntecPrintOk();
+}
+
+static void cyn_wifi_disint()
+{
+    wifiDataInt = false;
+    cyntecPrintOk();
+}
+
+
 int wifi_receive_UDP_callback(uint8_t *data, int size, char* ipaddr, int port)
 {
+    // Do nothing until flag on
+    if(wifiDataInt) {
+    	wifiWriteInt = !wifiWriteInt;
+    	wifiWriteInt = !wifiWriteInt;
 #ifdef DELTA_WIFI_DEBUG
-  console.printf("wifi_receive_UDP_callback:");
+        console.printf("wifi_receive_UDP_callback:");
 #endif
-  console.printf("rTCP;%s,%i,%s,%d;\r\n",data, size, ipaddr, port);
-  // Gill note: port number may different from original
+        console.printf("rUDP;%s,%i,%s,%d;\r\n",data, size, ipaddr, port);
+    }
 }
+// Gill note: port number may different from original
 
 int wifi_receive_TCP_callback(uint8_t *data, int size, char* ipaddr, int port)
 {
+    // Do nothing until flag on
+    if(wifiDataInt) {
+    	wifiWriteInt = !wifiWriteInt;
+    	wifiWriteInt = !wifiWriteInt;
 #ifdef DELTA_WIFI_DEBUG
-  console.printf("wifi_receive_TCP_callback\r\n");
+        console.printf("wifi_receive_TCP_callback\r\n");
 #endif
-  console.printf("rUDP;%s,%i,%s,%d\r\n",data, size, ipaddr, port);
-  // Gill note: port number may different from original
+        console.printf("rTCP;%s,%i,%s,%d;\r\n",data, size, ipaddr, port);
+    } 
 }
+// Gill note: port number may different from original
 
 CyntecCommandEntry wifiCommandSets[] = {
 #if SIMPLE_CMD_NAME
@@ -1117,7 +1142,9 @@
     {"DME4",cyn_wifi_mem_erase4k, NULL, " <MEMADDR> Erase a 4KB sector of embedded flash"},
     {"DMRD",cyn_wifi_mem_read, NULL, " <MEMADDR> <LEN> Read data from embeeded flash"},
     {"DMWT",cyn_wifi_mem_write, NULL, " <MEMADDR> <DATA> Write data into embeeded flash"},
-
+    {"DEDI",cyn_wifi_enint, NULL, " Enable Wifi data interrupt, print data whenever received."},
+    {"DDDI",cyn_wifi_disint, NULL, " Disable Wifi interrupt."},
+    
     /////////**** WIFI Ethernet ****//////////
     {"EINT", cyn_wifi_ethernet_init, NULL, " <STATIC IP> Initialize the interface to use DHCP"},
     {"ECON", cyn_wifi_ethernet_connect, NULL, "<TIMEOUT MS> Bring up the WiFi connection"},
@@ -1155,6 +1182,7 @@
     {"UERS", cyn_wifi_udp_endpoint_reset_address, NULL, "Reset the address of this endpoint"},
     {"UEAD", cyn_wifi_udp_endpoint_address, NULL, " <IPADDR> <PORT> Set/Get the address of this endpoint"},
     {"UEPT", cyn_wifi_udp_endpoint_port, NULL, "Get the port of this endpoint"},
+    
     {NULL, NULL, NULL, NULL},
 #else
     /////////**** WIFI Device ****//////////
@@ -1168,6 +1196,9 @@
     {"device_mem_erase4k",cyn_wifi_mem_erase4k, NULL, " <MEMADDR> Erase a 4KB sector of embedded flash"},
     {"device_mem_read",cyn_wifi_mem_read, NULL, " <MEMADDR> <LEN> Read data from embeeded flash"},
     {"device_mem_write",cyn_wifi_mem_write, NULL, " <MEMADDR> <DATA> Write data into embeeded flash"},
+    {"device_enint",cyn_wifi_enint, NULL, " Enable Wifi data interrupt, print data whenever received."},
+    {"device_disint",cyn_wifi_disint, NULL, " Disable Wifi interrupt."},
+    
 
     /////////**** WIFI Ethernet ****//////////
     {"ethernet_init", cyn_wifi_ethernet_init, NULL, " <STATIC IP> Initialize the interface to use DHCP"},
@@ -1194,7 +1225,7 @@
     {"tcp_connection_send_all", cyn_wifi_tcp_connection_send_all, NULL, " <DATA> Send all the data to the remote host"},
     {"tcp_connection_receive", cyn_wifi_tcp_connection_receive, NULL, " <DATALEN> Receive data from the remote host"},
     {"tcp_connection_receive_all", cyn_wifi_tcp_connection_receive_all, NULL, "<DATALEN> Receive all the data from the remote host"},
-    {"tcp_connection_blocking ", cyn_wifi_tcp_connection_blocking, NULL, "<SETTING> <TIMEOUT MS> Set blocking mode and timeout"},
+    {"tcp_connection_blocking", cyn_wifi_tcp_connection_blocking, NULL, "<SETTING> <TIMEOUT MS> Set blocking mode and timeout"},
     {"tcp_connection_close", cyn_wifi_tcp_connection_close, NULL, "<SHUTDOWN> Close the connection"},
 //	{"tcp_connection_reset_address", cyn_wifi_tcp_connection_reset_address, NULL, "........."},
 //	{"tcp_connection_address", cyn_wifi_tcp_connection_address, NULL, "........."},