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
Diff: SNIC_WifiInterface.cpp
- Revision:
- 16:6100acfeb1f1
- Parent:
- 15:5eb637414df2
- Child:
- 22:a9ec0cad4f84
diff -r 5eb637414df2 -r 6100acfeb1f1 SNIC_WifiInterface.cpp --- a/SNIC_WifiInterface.cpp Thu Mar 27 05:12:22 2014 +0000 +++ b/SNIC_WifiInterface.cpp Thu Mar 27 05:43:54 2014 +0000 @@ -29,6 +29,8 @@ int C_SNIC_WifiInterface::init() { + C_SNIC_UartCommandManager *uartCmdMgr_p = mSNICWifi_p->getUartCommand(); + /* Initialize UART */ mSNICWifi_p->initUart( mUART_tx, mUART_rx, mUART_baud ); @@ -58,7 +60,7 @@ int ret; // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "snic_init failed\r\n" ); @@ -66,9 +68,9 @@ return -1; } - if( mSNICWifi_p->mUartCommand.getCommandStatus() != 0 ) + if( uartCmdMgr_p->getCommandStatus() != 0 ) { - printf("snic_init status:%02x\r\n", mSNICWifi_p->mUartCommand.getCommandStatus()); + printf("snic_init status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } mSNICWifi_p->freeCmdBuf( payload_buf ); @@ -78,6 +80,8 @@ int C_SNIC_WifiInterface::getFWVersion( unsigned char *version_p ) { + C_SNIC_UartCommandManager *uartCmdMgr_p = mSNICWifi_p->getUartCommand(); + // Get buffer for response payload from MemoryPool tagMEMPOOL_BLOCK_T *payload_buf = mSNICWifi_p->allocCmdBuf(); if( payload_buf == NULL ) @@ -103,7 +107,7 @@ mSNICWifi_p->sendUart( command_len, command_array ); // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "getFWversion failed\r\n" ); @@ -111,7 +115,7 @@ return -1; } - if( mSNICWifi_p->mUartCommand.getCommandStatus() == 0 ) + if( uartCmdMgr_p->getCommandStatus() == 0 ) { unsigned char version_len = payload_buf->buf[3]; memcpy( version_p, &payload_buf->buf[4], version_len ); @@ -123,6 +127,8 @@ 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(); + // Parameter check(SSID) if( (ssid_p == NULL) || (ssid_len == 0) ) { @@ -186,7 +192,7 @@ int ret; // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "join failed\r\n" ); @@ -194,9 +200,9 @@ return -1; } - if( mSNICWifi_p->mUartCommand.getCommandStatus() != 0 ) + if( uartCmdMgr_p->getCommandStatus() != 0 ) { - printf("join status:%02x\r\n", mSNICWifi_p->mUartCommand.getCommandStatus()); + printf("join status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } mSNICWifi_p->freeCmdBuf( payload_buf ); @@ -206,6 +212,8 @@ int C_SNIC_WifiInterface::disconnect() { + C_SNIC_UartCommandManager *uartCmdMgr_p = mSNICWifi_p->getUartCommand(); + // Get buffer for response payload from MemoryPool tagMEMPOOL_BLOCK_T *payload_buf = mSNICWifi_p->allocCmdBuf(); if( payload_buf == NULL ) @@ -230,7 +238,7 @@ int ret; // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "disconnect failed\r\n" ); @@ -238,9 +246,9 @@ return -1; } - if( mSNICWifi_p->mUartCommand.getCommandStatus() != 0 ) + if( uartCmdMgr_p->getCommandStatus() != 0 ) { - printf("disconnect status:%02x\r\n", mSNICWifi_p->mUartCommand.getCommandStatus()); + printf("disconnect status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } mSNICWifi_p->freeCmdBuf( payload_buf ); @@ -250,6 +258,8 @@ 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(); + // Get buffer for response payload from MemoryPool tagMEMPOOL_BLOCK_T *payload_buf = mSNICWifi_p->allocCmdBuf(); if( payload_buf == NULL ) @@ -298,14 +308,14 @@ , buf_len, payload_buf->buf, command_array ); // Set scan result callback - mSNICWifi_p->mUartCommand.setScanResultHandler( result_handler_p ); + uartCmdMgr_p->setScanResultHandler( result_handler_p ); // Send uart command request mSNICWifi_p->sendUart( command_len, command_array ); int ret; // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); printf( "scan wait:%d\r\n", ret ); if( ret != 0 ) { @@ -314,9 +324,9 @@ return -1; } - if( mSNICWifi_p->mUartCommand.getCommandStatus() != 0 ) + if( uartCmdMgr_p->getCommandStatus() != 0 ) { - printf("scan status:%02x\r\n", mSNICWifi_p->mUartCommand.getCommandStatus()); + printf("scan status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } @@ -327,6 +337,8 @@ int C_SNIC_WifiInterface::wifi_on( const char *country_p ) { + C_SNIC_UartCommandManager *uartCmdMgr_p = mSNICWifi_p->getUartCommand(); + // Parameter check if( country_p == NULL ) { @@ -359,7 +371,7 @@ int ret; // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "wifi_on failed\r\n" ); @@ -367,9 +379,9 @@ return -1; } - if( mSNICWifi_p->mUartCommand.getCommandStatus() != 0 ) + if( uartCmdMgr_p->getCommandStatus() != 0 ) { - printf("wifi_on status:%02x\r\n", mSNICWifi_p->mUartCommand.getCommandStatus()); + printf("wifi_on status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } mSNICWifi_p->freeCmdBuf( payload_buf ); @@ -379,6 +391,8 @@ int C_SNIC_WifiInterface::wifi_off() { + C_SNIC_UartCommandManager *uartCmdMgr_p = mSNICWifi_p->getUartCommand(); + // Get buffer for response payload from MemoryPool tagMEMPOOL_BLOCK_T *payload_buf = mSNICWifi_p->allocCmdBuf(); if( payload_buf == NULL ) @@ -403,7 +417,7 @@ int ret; // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "wifi_off failed\r\n" ); @@ -411,9 +425,9 @@ return -1; } - if( mSNICWifi_p->mUartCommand.getCommandStatus() != 0 ) + if( uartCmdMgr_p->getCommandStatus() != 0 ) { - printf("wifi_off status:%02x\r\n", mSNICWifi_p->mUartCommand.getCommandStatus()); + printf("wifi_off status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); ret = -1; } mSNICWifi_p->freeCmdBuf( payload_buf ); @@ -423,6 +437,7 @@ int C_SNIC_WifiInterface::getRssi( signed char *rssi_p ) { + C_SNIC_UartCommandManager *uartCmdMgr_p = mSNICWifi_p->getUartCommand(); if( rssi_p == NULL ) { printf("getRssi parameter error\r\n"); @@ -453,7 +468,7 @@ mSNICWifi_p->sendUart( command_len, command_array ); // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "getRssi failed\r\n" ); @@ -469,6 +484,8 @@ int C_SNIC_WifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p) { + C_SNIC_UartCommandManager *uartCmdMgr_p = mSNICWifi_p->getUartCommand(); + if( status_p == NULL ) { printf("getWifiStatus parameter error\r\n"); @@ -499,7 +516,7 @@ int ret; // Wait UART response - ret = mSNICWifi_p->mUartCommand.wait(); + ret = uartCmdMgr_p->wait(); if( ret != 0 ) { printf( "getWifiStatus failed\r\n" );