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:
38:f13e4e563d65
Parent:
37:f3a2053627c2
Child:
39:a1233ca02edf
--- a/SNIC_WifiInterface.cpp	Tue Jun 24 06:24:23 2014 +0000
+++ b/SNIC_WifiInterface.cpp	Wed Jun 25 00:04:11 2014 +0000
@@ -44,10 +44,10 @@
     wait(1);
     /* Initialize SNIC API */
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("snic_init payload_buf NULL\r\n");
+        printf("snic_init payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -58,14 +58,14 @@
     req.buf_size[0] = 0x08;
     req.buf_size[1] = 0x00;
 
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    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_INIT_REQ_T), payload_buf->buf, command_array );
+                            , sizeof(C_SNIC_Core::tagSNIC_INIT_REQ_T), payload_buf_p->buf, command_array_p );
 
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
 
     int ret;
     // Wait UART response
@@ -73,7 +73,7 @@
     if( ret != 0 )
     {
         printf( "snic_init failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
@@ -82,7 +82,7 @@
         printf("snic_init status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
         ret = -1;
     }
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
     
     return ret;
 }
@@ -93,10 +93,10 @@
     C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
     
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("getFWVersion payload_buf NULL\r\n");
+        printf("getFWVersion payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -105,32 +105,32 @@
     req.cmd_sid = UART_CMD_SID_GEN_FW_VER_GET_REQ;
     req.seq     = mUartRequestSeq++;
     
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    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_GEN, req.cmd_sid, (unsigned char *)&req
-                        , sizeof(C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T), payload_buf->buf, command_array );
+                        , sizeof(C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T), payload_buf_p->buf, command_array_p );
 
     int ret;
     
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     // Wait UART response
     ret = uartCmdMgr_p->wait();
     if( ret != 0 )
     {
         printf( "getFWversion failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
     if( uartCmdMgr_p->getCommandStatus() == 0 )
     {
-        unsigned char version_len = payload_buf->buf[3];
-        memcpy( version_p, &payload_buf->buf[4], version_len );
+        unsigned char version_len = payload_buf_p->buf[3];
+        memcpy( version_p, &payload_buf_p->buf[4], version_len );
     }
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
     return 0;
 }
 
@@ -155,10 +155,10 @@
     }
     
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("connect payload_buf NULL\r\n");
+        printf("connect payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -193,13 +193,13 @@
         }
     }
 
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    unsigned char *command_array_p = snic_core_p->getCommandBuf();
     // Preparation of command
     command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf
-                        , buf_len, payload_buf->buf, command_array );
+                        , buf_len, payload_buf_p->buf, command_array_p );
 
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     int ret;
     // Wait UART response
@@ -207,7 +207,7 @@
     if( ret != 0 )
     {
         printf( "join failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
@@ -217,7 +217,7 @@
         printf("join status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
         ret = -1;
     }
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
 
     return ret;
 }
@@ -228,10 +228,10 @@
     C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
     
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("disconnect payload_buf NULL\r\n");
+        printf("disconnect payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -240,14 +240,14 @@
     req.cmd_sid = UART_CMD_SID_WIFI_DISCONNECT_REQ;
     req.seq = mUartRequestSeq++;
     
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    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_WIFI, req.cmd_sid, (unsigned char *)&req
-                        , sizeof(C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T), payload_buf->buf, command_array );
+                        , sizeof(C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T), payload_buf_p->buf, command_array_p );
 
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     int ret;
     // Wait UART response
@@ -255,7 +255,7 @@
     if( ret != 0 )
     {
         printf( "disconnect failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
@@ -264,7 +264,7 @@
         printf("disconnect status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
         ret = -1;
     }
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
     return ret;
 }
 
@@ -275,10 +275,10 @@
     C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
 
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("scan payload_buf NULL\r\n");
+        printf("scan payload_buf_p NULL\r\n");
         return -1;
     }
     
@@ -315,17 +315,17 @@
     }
     buf_len++;
 
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    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_WIFI, req.cmd_sid, (unsigned char *)&req
-                        , buf_len, payload_buf->buf, command_array );
+                        , buf_len, payload_buf_p->buf, command_array_p );
 
     // Set scan result callback 
     uartCmdMgr_p->setScanResultHandler( result_handler_p );
     
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
 
     int ret;
     // Wait UART response
@@ -334,7 +334,7 @@
     if( ret != 0 )
     {
         printf( "scan failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
@@ -344,7 +344,7 @@
         ret = -1;
     }
 
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
 
     return ret;
 }
@@ -362,10 +362,10 @@
     }
     
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("wifi_on payload_buf NULL\r\n");
+        printf("wifi_on payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -375,14 +375,14 @@
     req.seq = mUartRequestSeq++;
     memcpy( req.country, country_p, COUNTRYC_CODE_LENTH );
     
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    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_WIFI, req.cmd_sid, (unsigned char *)&req
-                        , sizeof(C_SNIC_Core::tagWIFI_ON_REQ_T), payload_buf->buf, command_array );
+                        , sizeof(C_SNIC_Core::tagWIFI_ON_REQ_T), payload_buf_p->buf, command_array_p );
 
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     int ret;
     // Wait UART response
@@ -390,7 +390,7 @@
     if( ret != 0 )
     {
         printf( "wifi_on failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
@@ -399,7 +399,7 @@
         printf("wifi_on status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
         ret = -1;
     }
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
 
     return ret;
 }
@@ -410,10 +410,10 @@
     C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
 
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("wifi_off payload_buf NULL\r\n");
+        printf("wifi_off payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -422,14 +422,14 @@
     req.cmd_sid = UART_CMD_SID_WIFI_OFF_REQ;
     req.seq = mUartRequestSeq++;
     
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    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_WIFI, req.cmd_sid, (unsigned char *)&req
-                        , sizeof(C_SNIC_Core::tagWIFI_OFF_REQ_T), payload_buf->buf, command_array );
+                        , sizeof(C_SNIC_Core::tagWIFI_OFF_REQ_T), payload_buf_p->buf, command_array_p );
 
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     int ret;
     // Wait UART response
@@ -437,7 +437,7 @@
     if( ret != 0 )
     {
         printf( "wifi_off failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
@@ -446,7 +446,7 @@
         printf("wifi_off status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
         ret = -1;
     }
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
 
     return ret;
 }
@@ -462,10 +462,10 @@
     }
     
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("getRssi payload_buf NULL\r\n");
+        printf("getRssi payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -475,27 +475,27 @@
     req.cmd_sid = UART_CMD_SID_WIFI_GET_STA_RSSI_REQ;
     req.seq     = mUartRequestSeq++;
     
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    unsigned char *command_array_p = snic_core_p->getCommandBuf();
     unsigned int   command_len;
     command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
-                        , sizeof(C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T), payload_buf->buf, command_array );
+                        , sizeof(C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T), payload_buf_p->buf, command_array_p );
 
     int ret;
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     // Wait UART response
     ret = uartCmdMgr_p->wait();
     if( ret != 0 )
     {
         printf( "getRssi failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
-    *rssi_p = (signed char)payload_buf->buf[2];
+    *rssi_p = (signed char)payload_buf_p->buf[2];
 
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
     return 0;
 }
 
@@ -511,10 +511,10 @@
     }
     
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("getWifiStatus payload_buf NULL\r\n");
+        printf("getWifiStatus payload_buf_p NULL\r\n");
         return -1;
     }
 
@@ -524,13 +524,13 @@
     req.seq     = mUartRequestSeq++;
     req.interface = 0;
     
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    unsigned char *command_array_p = snic_core_p->getCommandBuf();
     unsigned int   command_len;
     command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
-                        , sizeof(C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T), payload_buf->buf, command_array );
+                        , sizeof(C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T), payload_buf_p->buf, command_array_p );
 
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     int ret;
     // Wait UART response
@@ -538,26 +538,26 @@
     if( ret != 0 )
     {
         printf( "getWifiStatus failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
     // set status
-    status_p->status = (E_WIFI_STATUS)payload_buf->buf[2];
+    status_p->status = (E_WIFI_STATUS)payload_buf_p->buf[2];
     
     // set Mac address
     if( status_p->status != e_STATUS_OFF )
     {
-        memcpy( status_p->mac_address, &payload_buf->buf[3], BSSID_MAC_LENTH );
+        memcpy( status_p->mac_address, &payload_buf_p->buf[3], BSSID_MAC_LENTH );
     } 
 
     // set SSID
     if( ( status_p->status == e_STA_JOINED ) || ( status_p->status == e_AP_STARTED ) )
     {
-        memcpy( status_p->ssid, &payload_buf->buf[9], strlen( (char *)&payload_buf->buf[9]) );
+        memcpy( status_p->ssid, &payload_buf_p->buf[9], strlen( (char *)&payload_buf_p->buf[9]) );
     } 
 
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
     return 0;
 }
 
@@ -578,14 +578,14 @@
     C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
 
     // Get buffer for response payload from MemoryPool
-    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
-    if( payload_buf == NULL )
+    tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
+    if( payload_buf_p == NULL )
     {
-        printf("setIPConfig payload_buf NULL\r\n");
+        printf("setIPConfig payload_buf_p NULL\r\n");
         return -1;
     }
 
-    unsigned char *command_array = snic_core_p->getCommandBuf();
+    unsigned char *command_array_p = snic_core_p->getCommandBuf();
     unsigned int  command_len;
     if( is_DHCP == true )
     {
@@ -598,7 +598,7 @@
         
         // Preparation of command
         command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
-                            , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf->buf, command_array );
+                            , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf_p->buf, command_array_p );
     }
     else
     {
@@ -620,10 +620,10 @@
 
         // Preparation of command
         command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
-                            , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf->buf, command_array );
+                            , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf_p->buf, command_array_p );
     }
     // Send uart command request
-    snic_core_p->sendUart( command_len, command_array );
+    snic_core_p->sendUart( command_len, command_array_p );
     
     int ret;
     // Wait UART response
@@ -631,7 +631,7 @@
     if( ret != 0 )
     {
         printf( "setIPConfig failed\r\n" );
-        snic_core_p->freeCmdBuf( payload_buf );
+        snic_core_p->freeCmdBuf( payload_buf_p );
         return -1;
     }
     
@@ -641,6 +641,6 @@
         ret = -1;
     }
 
-    snic_core_p->freeCmdBuf( payload_buf );
+    snic_core_p->freeCmdBuf( payload_buf_p );
     return ret;
 }