SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html

Dependents:   SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more

Fork of YDwifiInterface by Takao Kishino

Files at this revision

API Documentation at this revision

Comitter:
MACRUM
Date:
Tue Mar 31 03:12:35 2015 +0000
Parent:
51:69a9cf901d54
Child:
53:b53ccb9989c4
Commit message:
TCPSocketServer::accept is now blocking which is same behavior of original EthernetInterface library.

Changed in this revision

SNIC/SNIC_UartCommandManager.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketServer.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SNIC/SNIC_UartCommandManager.cpp	Tue Mar 31 02:59:47 2015 +0000
+++ b/SNIC/SNIC_UartCommandManager.cpp	Tue Mar 31 03:12:35 2015 +0000
@@ -234,6 +234,8 @@
     con_info_p->is_received   = false;
     con_info_p->is_accept     = true;
     con_info_p->parent_socket = payload_p[2];
+    con_info_p->from_ip   = ((payload_p[4] << 24) | (payload_p[5] << 16) | (payload_p[6] << 8) | payload_p[7]);
+    con_info_p->from_port = ((payload_p[8] << 8)  | payload_p[9]);
 }
 
 void C_SNIC_UartCommandManager::bufferredUDPPacket( unsigned char *payload_p, int payload_len )
--- a/Socket/TCPSocketServer.cpp	Tue Mar 31 02:59:47 2015 +0000
+++ b/Socket/TCPSocketServer.cpp	Tue Mar 31 03:12:35 2015 +0000
@@ -161,21 +161,38 @@
     C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
     int          i;
     int          ret = -1;
+    bool         accepted = false;
     
     C_SNIC_Core::tagCONNECT_INFO_T *con_info_p;
-    for( i = 0; i < MAX_SOCKET_ID+1; i++ )
-    {
+    
+    do
+    {    
+        for( i = 0; i < MAX_SOCKET_ID+1; i++ )
+        {
         // Get connection information
-        con_info_p = snic_core_p->getConnectInfo( i );
-        if( (con_info_p->is_connected == true)
-            && (con_info_p->is_accept == true)
-            && (con_info_p->parent_socket == mSocketID) )
-        {
-            // Set socket id
-            connection.setAcceptSocket( i );
-            ret = 0;
-        }   
-    }
+            con_info_p = snic_core_p->getConnectInfo( i );
+            if( (con_info_p->is_connected == true)
+                && (con_info_p->is_accept == true)
+                && (con_info_p->parent_socket == mSocketID) )
+            {
+                // Set socket id
+                connection.setAcceptSocket( i );
+                ret = 0;
+                accepted = true;
+                break;
+            }   
+        }
+    } while( accepted == false );
+    con_info_p->is_accept = false;
+    
+    char remote_addr[ 20 ] = {'\0'};
+    sprintf( remote_addr, "%d.%d.%d.%d"
+            , (con_info_p->from_ip >> 24 ) & 0xff 
+            , (con_info_p->from_ip >> 16 ) & 0xff 
+            , (con_info_p->from_ip >> 8 )  & 0xff 
+            ,  con_info_p->from_ip         & 0xff );
+    
+    connection.set_address( remote_addr, (int)con_info_p->from_port );
     
     return ret;
 }