Customized

Dependents:   MurataTypeYD_RPC_Sample

Fork of SNICInterface_mod by Toyomasa Watarai

Revision:
47:62ba69ff80d2
Parent:
43:d80bbb12ffe6
diff -r e1cb45f7a27f -r 62ba69ff80d2 SNIC_WifiInterface.cpp
--- a/SNIC_WifiInterface.cpp	Sat Nov 22 15:32:42 2014 +0000
+++ b/SNIC_WifiInterface.cpp	Fri Jan 23 09:56:01 2015 +0000
@@ -21,6 +21,7 @@
 
 #define UART_CONNECT_BUF_SIZE   512
 unsigned char gCONNECT_BUF[UART_CONNECT_BUF_SIZE];
+static char ip_addr[17] = "\0";
 
 C_SNIC_WifiInterface::C_SNIC_WifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud)
 {
@@ -662,3 +663,57 @@
     snic_core_p->freeCmdBuf( payload_buf_p );
     return ret;
 }
+
+char* C_SNIC_WifiInterface::getIPAddress() {
+    C_SNIC_Core               *snic_core_p  = C_SNIC_Core::getInstance();
+    C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
+    
+    snic_core_p->lockAPI();
+    // Get local ip address.
+    // Get buffer for response payload from MemoryPool
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
+    {
+        DEBUG_PRINT("getIPAddress payload_buf_p NULL\r\n");
+        snic_core_p->unlockAPI();
+        return 0;
+    }
+
+    C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T req;
+    // Make request
+    req.cmd_sid      = UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ;
+    req.seq          = mUartRequestSeq++;
+    req.interface    = 0;
+    
+    unsigned char *command_array_p = snic_core_p->getCommandBuf();
+    unsigned int  command_len;
+    // Preparation of command
+    command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
+                            , sizeof(C_SNIC_Core::tagSNIC_GET_DHCP_INFO_REQ_T), payload_buf_p->buf, command_array_p );
+    // Send uart command request
+    snic_core_p->sendUart( command_len, command_array_p );
+    // Wait UART response
+    int ret = uartCmdMgr_p->wait();
+    if( ret != 0 )
+    {
+        DEBUG_PRINT( "getIPAddress failed\r\n" );
+        snic_core_p->freeCmdBuf( payload_buf_p );
+        snic_core_p->unlockAPI();
+        return 0;
+    }
+    
+    if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS )
+    {
+        snic_core_p->freeCmdBuf( payload_buf_p );
+        snic_core_p->unlockAPI();
+        return 0;
+    }
+    
+    snic_core_p->freeCmdBuf( payload_buf_p );
+    snic_core_p->unlockAPI();
+
+    sprintf(ip_addr, "%d.%d.%d.%d\0", payload_buf_p->buf[9], payload_buf_p->buf[10], payload_buf_p->buf[11], payload_buf_p->buf[12]);
+
+    return ip_addr;
+}
+