Customized
Dependents: MurataTypeYD_RPC_Sample
Fork of SNICInterface_mod by
Diff: SNIC_WifiInterface.cpp
- Revision:
- 24:987e412ae879
- Parent:
- 22:a9ec0cad4f84
- Child:
- 26:f2e1030964e4
--- a/SNIC_WifiInterface.cpp Thu Mar 27 10:11:59 2014 +0000 +++ b/SNIC_WifiInterface.cpp Fri Mar 28 00:45:15 2014 +0000 @@ -17,8 +17,6 @@ C_SNIC_WifiInterface::C_SNIC_WifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud) { - mSNICWifi_p = C_SNIC_Core::getInstance(); - mUART_tx = tx; mUART_rx = rx; mUART_cts = cts; @@ -28,15 +26,16 @@ } int C_SNIC_WifiInterface::init() -{ - 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(); /* Initialize UART */ - mSNICWifi_p->initUart( mUART_tx, mUART_rx, mUART_baud ); + snic_core_p->initUart( mUART_tx, mUART_rx, mUART_baud ); /* Initialize SNIC API */ // 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("snic_init payload_buf NULL\r\n"); @@ -52,11 +51,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_INIT_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 ); int ret; // Wait UART response @@ -64,7 +63,7 @@ if( ret != 0 ) { printf( "snic_init failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -73,17 +72,18 @@ printf("snic_init status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return ret; } int C_SNIC_WifiInterface::getFWVersion( unsigned char *version_p ) { - 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("getFWVersion payload_buf NULL\r\n"); @@ -98,20 +98,20 @@ unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; unsigned int command_len; // Preparation of command - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_GEN, req.cmd_sid, (unsigned char *)&req + 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 ); int ret; // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); // Wait UART response ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "getFWversion failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -120,14 +120,15 @@ unsigned char version_len = payload_buf->buf[3]; memcpy( version_p, &payload_buf->buf[4], version_len ); } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return 0; } int C_SNIC_WifiInterface::connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type , const char *sec_key_p, unsigned char sec_key_len) { - 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(); // Parameter check(SSID) if( (ssid_p == NULL) || (ssid_len == 0) ) @@ -144,7 +145,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"); @@ -184,11 +185,11 @@ } // Preparation of command - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf + command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf , buf_len, payload_buf->buf, command_array ); // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); int ret; // Wait UART response @@ -196,7 +197,7 @@ if( ret != 0 ) { printf( "join failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -205,17 +206,18 @@ printf("join status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return ret; } int C_SNIC_WifiInterface::disconnect() { - 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("disconnect payload_buf NULL\r\n"); @@ -230,11 +232,11 @@ unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; unsigned int command_len; // Preparation of command - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req + 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 ); // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); int ret; // Wait UART response @@ -242,7 +244,7 @@ if( ret != 0 ) { printf( "disconnect failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -251,17 +253,18 @@ printf("disconnect status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return ret; } int C_SNIC_WifiInterface::scan( const char *ssid_p, unsigned char *bssid_p , void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) ) { - 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("scan payload_buf NULL\r\n"); @@ -304,14 +307,14 @@ unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; unsigned int command_len; // Preparation of command - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req + command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req , buf_len, payload_buf->buf, command_array ); // Set scan result callback uartCmdMgr_p->setScanResultHandler( result_handler_p ); // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); int ret; // Wait UART response @@ -320,7 +323,7 @@ if( ret != 0 ) { printf( "scan failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -330,14 +333,15 @@ ret = -1; } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return ret; } int C_SNIC_WifiInterface::wifi_on( const char *country_p ) { - 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(); // Parameter check if( country_p == NULL ) @@ -347,7 +351,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("wifi_on payload_buf NULL\r\n"); @@ -363,11 +367,11 @@ unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; unsigned int command_len; // Preparation of command - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req + 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 ); // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); int ret; // Wait UART response @@ -375,7 +379,7 @@ if( ret != 0 ) { printf( "wifi_on failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -384,17 +388,18 @@ printf("wifi_on status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return ret; } int C_SNIC_WifiInterface::wifi_off() { - 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("wifi_off payload_buf NULL\r\n"); @@ -409,11 +414,11 @@ unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; unsigned int command_len; // Preparation of command - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req + 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 ); // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); int ret; // Wait UART response @@ -421,7 +426,7 @@ if( ret != 0 ) { printf( "wifi_off failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -430,14 +435,15 @@ printf("wifi_off status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return ret; } int C_SNIC_WifiInterface::getRssi( signed char *rssi_p ) { - 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(); if( rssi_p == NULL ) { printf("getRssi parameter error\r\n"); @@ -445,7 +451,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("getRssi payload_buf NULL\r\n"); @@ -460,31 +466,32 @@ unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; unsigned int command_len; - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req + 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 ); int ret; // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); // Wait UART response ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "getRssi failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } *rssi_p = (signed char)payload_buf->buf[2]; - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return 0; } int C_SNIC_WifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p) { - 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(); if( status_p == NULL ) { @@ -493,7 +500,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("getWifiStatus payload_buf NULL\r\n"); @@ -508,11 +515,11 @@ unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; unsigned int command_len; - command_len = mSNICWifi_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req + 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 ); // Send uart command request - mSNICWifi_p->sendUart( command_len, command_array ); + snic_core_p->sendUart( command_len, command_array ); int ret; // Wait UART response @@ -520,7 +527,7 @@ if( ret != 0 ) { printf( "getWifiStatus failed\r\n" ); - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return -1; } @@ -539,6 +546,6 @@ memcpy( status_p->ssid, &payload_buf->buf[9], strlen( (char *)&payload_buf->buf[9]) ); } - mSNICWifi_p->freeCmdBuf( payload_buf ); + snic_core_p->freeCmdBuf( payload_buf ); return 0; }