SNIC UART Interface library for Murata Type-YD module

Dependents:   WebSocketServerTest

Fork of SNICInterface_mod by Toyomasa Watarai

Revision:
43:d80bbb12ffe6
Parent:
41:1c1b5ad4d491
Child:
44:c50e7332afcc
--- a/Socket/TCPSocketConnection.cpp	Fri Sep 19 01:46:17 2014 +0000
+++ b/Socket/TCPSocketConnection.cpp	Fri Nov 14 00:52:31 2014 +0000
@@ -35,11 +35,13 @@
     C_SNIC_Core               *snic_core_p  = C_SNIC_Core::getInstance();
     C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
 
+    FUNC_IN();
     // Socket create
     ret = createSocket();
     if( ret != 0 )
     {
         DEBUG_PRINT("createSocket error : %d\r\n", ret);
+        FUNC_OUT();
         return -1;
     }
 
@@ -47,7 +49,8 @@
     //lcd_printf("connect to [%s](%08x)\r\n", host_p, ip_addr);
     if( ( ip_addr == 0) || (ip_addr == -1) )
     {
-          DEBUG_PRINT("connect resolveHostName failed\r\n");
+        DEBUG_PRINT("connect resolveHostName failed\r\n");
+        FUNC_OUT();
         return -1;
     }
         
@@ -56,6 +59,7 @@
     if( payload_buf_p == NULL )
     {
         DEBUG_PRINT("connect payload_buf_p NULL\r\n");
+        FUNC_OUT();
         return -1;
     }
     
@@ -94,6 +98,7 @@
     {
         DEBUG_PRINT( "connect failed\r\n" );
         snic_core_p->freeCmdBuf( payload_buf_p );
+        FUNC_OUT();
         return -1;
     }
     
@@ -101,6 +106,7 @@
     {
         DEBUG_PRINT("connect status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
         snic_core_p->freeCmdBuf( payload_buf_p );
+        FUNC_OUT();
         return -1;
     }
 
@@ -115,7 +121,7 @@
     }
     con_info_p->is_connected = true;
     con_info_p->is_received  = false;
-
+    FUNC_OUT();
     return 0;
 }
 
@@ -131,11 +137,13 @@
     C_SNIC_Core               *snic_core_p  = C_SNIC_Core::getInstance();
     C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
 
+    FUNC_IN();
     // Get buffer for response payload from MemoryPool
     tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
     if( payload_buf_p == NULL )
     {
         DEBUG_PRINT("connect payload_buf_p NULL\r\n");
+        FUNC_OUT();
         return -1;
     }
     
@@ -168,6 +176,7 @@
     {
         DEBUG_PRINT( "send failed\r\n" );
         snic_core_p->freeCmdBuf( payload_buf_p );
+        FUNC_OUT();
         return -1;
     }
     
@@ -175,11 +184,13 @@
     {
         DEBUG_PRINT("send status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
         snic_core_p->freeCmdBuf( payload_buf_p );
+        FUNC_OUT();
         return -1;
     }
     snic_core_p->freeCmdBuf( payload_buf_p );
 
     // SNIC_SEND_FROM_SOCKET_REQ
+    FUNC_OUT();
     return 0;
 }
 
@@ -192,9 +203,11 @@
 {
     int i = 0;
     
+    FUNC_IN();
     if( (data_p == NULL) || (length < 1) )
     {
         DEBUG_PRINT("TCPSocketConnection::receive parameter error\r\n");
+        FUNC_OUT();
         return -1;
     }
     
@@ -204,6 +217,7 @@
     if( con_info_p->recvbuf_p == NULL )
     {
         DEBUG_PRINT("TCPSocketConnection::receive Conncection info error\r\n");
+        FUNC_OUT();
         return -1;
     }
 
@@ -211,15 +225,14 @@
     if( con_info_p->is_connected == false )
     {
         DEBUG_PRINT(" Socket id \"%d\" is not connected\r\n", mSocketID);
+        FUNC_OUT();
         return -1;
     }
-    
-    if( con_info_p->is_received == false )
+    con_info_p->is_receive_complete = true;
+    while( con_info_p->is_received == false )
     {
-//        DEBUG_PRINT(" Socket id \"%d\" is not received\r\n", mSocketID);
-        return 0;
+        Thread::yield();
     }
-    
     // Get packet data from buffer for receive.
     for (i = 0; i < length; i ++) 
     {
@@ -236,10 +249,12 @@
         con_info_p->mutex.unlock();
     }
 
+    FUNC_OUT();
     return i;
 }
 
 void TCPSocketConnection::setAcceptSocket( int socket_id )
 {
+    FUNC_IN();
     mSocketID = socket_id;
 }