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
Revision 16:6100acfeb1f1, committed 2014-03-27
- Comitter:
- kishino
- Date:
- Thu Mar 27 05:43:54 2014 +0000
- Parent:
- 15:5eb637414df2
- Child:
- 17:d8bc02c455a6
- Commit message:
- The instance of C_SNIC_UartCommandManager in C_SNIC_Core class was changed from public to private.
Changed in this revision
--- a/SNIC/SNIC_Core.cpp Thu Mar 27 05:12:22 2014 +0000
+++ b/SNIC/SNIC_Core.cpp Thu Mar 27 05:43:54 2014 +0000
@@ -33,7 +33,7 @@
{
if( mInstance_p == NULL )
{
- mInstance_p = new C_SNIC_Core();
+ mInstance_p = new C_SNIC_Core();
}
return mInstance_p;
}
@@ -42,6 +42,7 @@
{
int i;
+ mUartCommand_p = new C_SNIC_UartCommandManager();
for( i = 0; i < MAX_SOCKET_ID+1; i++ )
{
mConnectInfo[i].recvbuf_p = NULL;
@@ -92,9 +93,9 @@
command_len = C_SNIC_UartMsgUtil::makeRequest( cmd_id, payload_array, payload_len, command_p );
// Set data for response
- mUartCommand.setCommandID( cmd_id );
- mUartCommand.setCommandSID( cmd_sid | 0x80 );
- mUartCommand.setResponseBuf( response_buf_p );
+ mUartCommand_p->setCommandID( cmd_id );
+ mUartCommand_p->setCommandSID( cmd_sid | 0x80 );
+ mUartCommand_p->setResponseBuf( response_buf_p );
return command_len;
}
@@ -138,6 +139,11 @@
return &mConnectInfo[socket_id];
}
+C_SNIC_UartCommandManager *C_SNIC_Core::getUartCommand()
+{
+ return mUartCommand_p;
+}
+
DigitalOut led1(LED1);
void C_SNIC_Core::uartRecvThread (void const *args_p) {
@@ -146,6 +152,7 @@
{
printf("Socket constructor error: no wifly instance available!\r\n");
}
+ C_SNIC_UartCommandManager *uartCmdMgr_p = instance_p->getUartCommand();
int recvdata = 0;
int i;
@@ -186,29 +193,29 @@
if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_CONNECTION_RECV_IND) )
{
// Packet buffering
- instance_p->mUartCommand.bufferredPacket( gUART_TEMP_BUF, payload_len );
+ uartCmdMgr_p->bufferredPacket( gUART_TEMP_BUF, payload_len );
}
// Check scan results indication
else if( (command_id == UART_CMD_ID_WIFI) && (gUART_TEMP_BUF[0] == UART_CMD_SID_WIFI_SCAN_RESULT_IND) )
{
// Scan result indicate
- instance_p->mUartCommand.scanResultIndicate( gUART_TEMP_BUF, payload_len );
+ uartCmdMgr_p->scanResultIndicate( gUART_TEMP_BUF, payload_len );
}
// Checks in the command which is waiting.
- else if( instance_p->mUartCommand.isWaitingCommand(command_id, gUART_TEMP_BUF) )
+ else if( uartCmdMgr_p->isWaitingCommand(command_id, gUART_TEMP_BUF) )
{
// Get buffer for payload data
- unsigned char *payload_buf_p = instance_p->mUartCommand.getResponseBuf();
+ unsigned char *payload_buf_p = uartCmdMgr_p->getResponseBuf();
if( payload_buf_p != NULL )
{
memcpy( payload_buf_p, gUART_TEMP_BUF, payload_len );
- instance_p->mUartCommand.setResponseBuf( NULL );
+ uartCmdMgr_p->setResponseBuf( NULL );
}
// Set status
- instance_p->mUartCommand.setCommandStatus( gUART_TEMP_BUF[2] );
+ uartCmdMgr_p->setCommandStatus( gUART_TEMP_BUF[2] );
// Set signal for command response wait.
- instance_p->mUartCommand.signal();
+ uartCmdMgr_p->signal();
}
gUART_RCVBUF.size = 0;
--- a/SNIC/SNIC_Core.h Thu Mar 27 05:12:22 2014 +0000
+++ b/SNIC/SNIC_Core.h Thu Mar 27 05:43:54 2014 +0000
@@ -182,7 +182,6 @@
{
public:
- C_SNIC_UartCommandManager mUartCommand;
/** Get buffer for command from memory pool.
@return Pointer of buffer
@@ -225,6 +224,12 @@
*/
tagCONNECT_INFO_T *getConnectInfo( int socket_id );
+ /**
+ Get pointer of the instance of C_SNIC_UartCommandManager.
+ @return The pointer of the instance of C_SNIC_UartCommandManager.
+ */
+ C_SNIC_UartCommandManager *getUartCommand();
+
/** Get an instance of the C_SNIC_Core class.
@return Instance of the C_SNIC_Core class
@note Please do not create an instance in the default constructor this class.
@@ -233,13 +238,15 @@
static C_SNIC_Core *getInstance();
protected:
- static C_SNIC_Core *mInstance_p;
- Thread *mUartRecvThread_p;
- RawSerial *mUart_p;
+ static C_SNIC_Core *mInstance_p;
+ Thread *mUartRecvThread_p;
+ RawSerial *mUart_p;
Mutex mUartMutex;
// DigitalInOut mModuleReset;
private:
+ C_SNIC_UartCommandManager *mUartCommand_p;
+
/** MemoryPool for payload of UART response */
MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload;
--- 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" );
--- a/Socket/Socket.cpp Thu Mar 27 05:12:22 2014 +0000
+++ b/Socket/Socket.cpp Thu Mar 27 05:43:54 2014 +0000
@@ -65,6 +65,7 @@
int Socket::createSocket( unsigned char bind, unsigned int local_addr, unsigned short port )
{
+ 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 )
@@ -104,7 +105,7 @@
int ret;
// Wait UART response
- ret = mSnicWifi_p->mUartCommand.wait();
+ ret = uartCmdMgr_p->wait();
if( ret != 0 )
{
printf( "createSocket failed\r\n" );
@@ -112,9 +113,9 @@
return -1;
}
- if( mSnicWifi_p->mUartCommand.getCommandStatus() != 0 )
+ if( uartCmdMgr_p->getCommandStatus() != 0 )
{
- printf("createSocket status:%02x\r\n", mSnicWifi_p->mUartCommand.getCommandStatus());
+ printf("createSocket status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
mSnicWifi_p->freeCmdBuf( payload_buf );
return -1;
}
--- a/Socket/TCPSocketConnection.cpp Thu Mar 27 05:12:22 2014 +0000
+++ b/Socket/TCPSocketConnection.cpp Thu Mar 27 05:43:54 2014 +0000
@@ -39,7 +39,8 @@
int TCPSocketConnection::connect( unsigned int ip_addr, unsigned short port)
{
int ret;
-
+ C_SNIC_UartCommandManager *uartCmdMgr_p = mSnicWifi_p->getUartCommand();
+
// Socket create
ret = createSocket();
if( ret != 0 )
@@ -82,10 +83,10 @@
// Send uart command request
mSnicWifi_p->sendUart( command_len, command_array );
- mSnicWifi_p->mUartCommand.setCommandSID( UART_CMD_SID_SNIC_TCP_CONNECTION_STATUS_IND );
+ uartCmdMgr_p->setCommandSID( UART_CMD_SID_SNIC_TCP_CONNECTION_STATUS_IND );
// Wait UART response
- ret = mSnicWifi_p->mUartCommand.wait();
+ ret = uartCmdMgr_p->wait();
if( ret != 0 )
{
printf( "connect failed\r\n" );
@@ -93,9 +94,9 @@
return -1;
}
- if( mSnicWifi_p->mUartCommand.getCommandStatus() != UART_CMD_RES_SNIC_CONNECTION_UP )
+ if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_CONNECTION_UP )
{
- printf("connect status:%02x\r\n", mSnicWifi_p->mUartCommand.getCommandStatus());
+ printf("connect status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
mSnicWifi_p->freeCmdBuf( payload_buf );
return -1;
}
@@ -123,6 +124,8 @@
unsigned char gTCP_SEND_BUF[2048];
int TCPSocketConnection::send(unsigned char* data_p, int length)
{
+ 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 )
@@ -156,7 +159,7 @@
// mSnicWifi_p->mUartCommand.setCommandSID( req.cmd_sid );
// Wait UART response
- int ret = mSnicWifi_p->mUartCommand.wait();
+ int ret = uartCmdMgr_p->wait();
if( ret != 0 )
{
printf( "send failed\r\n" );
@@ -164,9 +167,9 @@
return -1;
}
- if( mSnicWifi_p->mUartCommand.getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS )
+ if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS )
{
- printf("send status:%02x\r\n", mSnicWifi_p->mUartCommand.getCommandStatus());
+ printf("send status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
mSnicWifi_p->freeCmdBuf( payload_buf );
return -1;
}
muRata

Murata TypeYD