SNICInterface for ThingPlug Example

Dependents:   ThingPlug_WiFi_Example ThingPlug_WiFi_Example_2

Fork of SNICInterface by muRata

Revision:
24:987e412ae879
Parent:
22:a9ec0cad4f84
Child:
26:f2e1030964e4
--- a/Socket/TCPSocketConnection.cpp	Thu Mar 27 10:11:59 2014 +0000
+++ b/Socket/TCPSocketConnection.cpp	Fri Mar 28 00:45:15 2014 +0000
@@ -39,7 +39,8 @@
 int TCPSocketConnection::connect( unsigned int ip_addr, unsigned short port)
 {
     int ret;
-    C_SNIC_UartCommandManager *uartCmdMgr_p = mSnicWifi_p->getUartCommand();
+    C_SNIC_Core               *snic_core_p  = C_SNIC_Core::getInstance();
+    C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
     
     // Socket create
     ret = createSocket();
@@ -50,7 +51,7 @@
     }
 
     // Get buffer for response payload from MemoryPool
-    C_SNIC_Core::tagMEMPOOL_BLOCK_T *payload_buf = mSnicWifi_p->allocCmdBuf();
+    C_SNIC_Core::tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
     if( payload_buf == NULL )
     {
         printf("connect payload_buf NULL\r\n");
@@ -77,11 +78,11 @@
     unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
     unsigned int  command_len;
     // Preparation of command
-    command_len = mSnicWifi_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
+    command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
                             , sizeof(C_SNIC_Core::tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T), payload_buf->buf, command_array );
 
     // Send uart command request
-    mSnicWifi_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array );
 
     uartCmdMgr_p->setCommandSID( UART_CMD_SID_SNIC_TCP_CONNECTION_STATUS_IND );
 
@@ -90,20 +91,20 @@
     if( ret != 0 )
     {
         printf( "connect failed\r\n" );
-        mSnicWifi_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf );
         return -1;
     }
     
     if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_CONNECTION_UP )
     {
         printf("connect status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
-        mSnicWifi_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf );
         return -1;
     }
-    mSnicWifi_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf );
 
     // Initialize connection information
-    C_SNIC_Core::tagCONNECT_INFO_T *con_info_p = mSnicWifi_p->getConnectInfo( mSocketID );
+    C_SNIC_Core::tagCONNECT_INFO_T *con_info_p = snic_core_p->getConnectInfo( mSocketID );
     if( con_info_p->recvbuf_p == NULL )
     {
         printf( "create recv buffer[socket:%d]\r\n", mSocketID);
@@ -117,17 +118,19 @@
 
 bool TCPSocketConnection::is_connected(void)
 {
-    C_SNIC_Core::tagCONNECT_INFO_T *con_info_p = mSnicWifi_p->getConnectInfo( mSocketID );
+    C_SNIC_Core                    *snic_core_p  = C_SNIC_Core::getInstance();
+    C_SNIC_Core::tagCONNECT_INFO_T *con_info_p = snic_core_p->getConnectInfo( mSocketID );
     return con_info_p->is_connected;
 }
 
 unsigned char gTCP_SEND_BUF[2048];
 int TCPSocketConnection::send(unsigned char* data_p, int length)
 {
-    C_SNIC_UartCommandManager *uartCmdMgr_p = mSnicWifi_p->getUartCommand();
+    C_SNIC_Core               *snic_core_p  = C_SNIC_Core::getInstance();
+    C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
 
     // Get buffer for response payload from MemoryPool
-    C_SNIC_Core::tagMEMPOOL_BLOCK_T *payload_buf = mSnicWifi_p->allocCmdBuf();
+    C_SNIC_Core::tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
     if( payload_buf == NULL )
     {
         printf("connect payload_buf NULL\r\n");
@@ -150,28 +153,28 @@
     unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
     unsigned int  command_len;
     // Preparation of command
-    command_len = mSnicWifi_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, gTCP_SEND_BUF
+    command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, gTCP_SEND_BUF
                             , req_size + length, payload_buf->buf, command_array );
 
     // Send uart command request
-    mSnicWifi_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array );
 
     // Wait UART response
     int ret = uartCmdMgr_p->wait();
     if( ret != 0 )
     {
         printf( "send failed\r\n" );
-        mSnicWifi_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf );
         return -1;
     }
     
     if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS )
     {
         printf("send status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
-        mSnicWifi_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf );
         return -1;
     }
-    mSnicWifi_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf );
 
     // SNIC_SEND_FROM_SOCKET_REQ
     return 0;
@@ -187,8 +190,9 @@
         return -1;
     }
     
+    C_SNIC_Core                    *snic_core_p  = C_SNIC_Core::getInstance();
     // Initialize connection information
-    C_SNIC_Core::tagCONNECT_INFO_T *con_info_p = mSnicWifi_p->getConnectInfo( mSocketID );
+    C_SNIC_Core::tagCONNECT_INFO_T *con_info_p = snic_core_p->getConnectInfo( mSocketID );
     if( con_info_p->recvbuf_p == NULL )
     {
         printf("TCPSocketConnection::receive Conncection info error\r\n");