Customized SNICInterface

Fork of NySNICInterface by Ryo Iizuka

Revision:
33:33f1bc919486
Parent:
32:ae95309643aa
Child:
39:a1233ca02edf
--- a/SNIC/SNIC_UartCommandManager.cpp	Fri May 30 08:30:40 2014 +0000
+++ b/SNIC/SNIC_UartCommandManager.cpp	Tue Jun 03 08:53:07 2014 +0000
@@ -208,7 +208,7 @@
 
     if( con_info_p->recvbuf_p == NULL )
     {
-        printf( "create recv buffer[socket:%d]\r\n", socket_id);
+//        printf( "create recv buffer[socket:%d]\r\n", socket_id);
         con_info_p->recvbuf_p = new CircBuffer<char>(SNIC_UART_RECVBUF_SIZE);
     }
     con_info_p->is_connected  = true;
@@ -216,3 +216,47 @@
     con_info_p->is_accept     = true;
     con_info_p->parent_socket = payload_p[2];
 }
+
+void C_SNIC_UartCommandManager::bufferredUDPPacket( unsigned char *payload_p, int payload_len )
+{
+    if( (payload_p == NULL) || (payload_len == 0) )
+    {
+        return;
+    }
+    
+    C_SNIC_Core *instance_p = C_SNIC_Core::getInstance();
+
+    // Get Connection information
+    C_SNIC_Core::tagUDP_RECVINFO_T *con_info_p = instance_p->getUdpRecvInfo( payload_p[2] );
+    if( con_info_p == NULL )
+    {
+        return;
+    }
+
+    if( con_info_p->recvbuf_p == NULL )
+    {
+//        printf( "create recv buffer[socket:%d]\r\n", payload_p[2]);
+        con_info_p->recvbuf_p = new CircBuffer<char>(SNIC_UART_RECVBUF_SIZE);
+    }
+
+    con_info_p->is_received = true;
+    
+    // Set remote IP address and remote port
+    con_info_p->from_ip   = ((payload_p[3] << 24) | (payload_p[4] << 16) | (payload_p[5] << 8) | payload_p[6]);
+    con_info_p->from_port = ((payload_p[7] << 8)  | payload_p[8]);
+    
+    unsigned short recv_len;
+    // Get receive length from payload
+    recv_len= ((payload_p[9]<<8) & 0xFF00) | payload_p[10];
+    for( int i = 0; i < recv_len; i++ )
+    {
+        if( con_info_p->recvbuf_p->isFull() )
+        {
+            printf("Receive buffer is full.\r\n");
+            break;
+        }
+        
+        // Add to receive buffer
+        con_info_p->recvbuf_p->queue( payload_p[11+i] );
+    }
+}