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

Revision:
51:69a9cf901d54
Parent:
43:d80bbb12ffe6
Child:
53:b53ccb9989c4
diff -r cd632a13e4dc -r 69a9cf901d54 SNIC_WifiInterface.cpp
--- a/SNIC_WifiInterface.cpp	Tue Mar 31 02:53:44 2015 +0000
+++ b/SNIC_WifiInterface.cpp	Tue Mar 31 02:59:47 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,56 @@
     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;
+}