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

Files at this revision

API Documentation at this revision

Comitter:
MACRUM
Date:
Tue Mar 31 02:59:47 2015 +0000
Parent:
50:cd632a13e4dc
Child:
52:29b4d0adddf3
Commit message:
Added getIPAddress() function

Changed in this revision

SNIC_WifiInterface.cpp Show annotated file Show diff for this revision Revisions of this file
SNIC_WifiInterface.h Show annotated file Show diff for this revision Revisions of this file
--- 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;
+}
--- a/SNIC_WifiInterface.h	Tue Mar 31 02:53:44 2015 +0000
+++ b/SNIC_WifiInterface.h	Tue Mar 31 02:59:47 2015 +0000
@@ -139,6 +139,11 @@
     */
     int setIPConfig( bool is_DHCP, const char *ip_p=NULL, const char *mask_p=NULL, const char *gateway_p=NULL );
 
+    /** Get the IP address of your SNIC interface
+     * \return a pointer to a string containing the IP address
+     */
+    static char* getIPAddress();
+
 private:
     PinName mUART_tx;
     PinName mUART_rx;