Customized
Dependents: MurataTypeYD_RPC_Sample
Fork of SNICInterface_mod by
Diff: Socket/Socket.cpp
- Revision:
- 12:0254eaccfda2
- Parent:
- 4:99cc93fe7d88
- Child:
- 13:53e6471d5753
diff -r c49007d49e52 -r 0254eaccfda2 Socket/Socket.cpp --- a/Socket/Socket.cpp Wed Mar 19 01:48:37 2014 +0000 +++ b/Socket/Socket.cpp Tue Mar 25 01:42:25 2014 +0000 @@ -22,7 +22,8 @@ Socket::Socket() { - + mSnicWifi_p = C_SNIC_Core::getInstance(); + mSocketID = -1; } Socket::~Socket() { @@ -48,4 +49,63 @@ { return 0; } -#endif \ No newline at end of file +#endif + +int Socket::createSocket( unsigned char bind, unsigned int local_addr, unsigned short port ) +{ + // Get buffer for response payload from MemoryPool + tagMEMPOOL_BLOCK_T *payload_buf = mSnicWifi_p->getAlocCmdBuf(); + if( payload_buf == NULL ) + { + printf("createSocket payload_buf NULL\r\n"); + return -1; + } + + tagSNIC_TCP_CREATE_SOCKET_REQ_T req; + int req_len = 0; + + // Make request + req.cmd_sid = UART_CMD_SID_SNIC_TCP_CREATE_SOCKET_REQ; + req_len++; + req.seq = mUartRequestSeq++; + req_len++; + req.bind = bind; + req_len++; + if( bind != 0 ) + { + req.local_addr = local_addr; + req_len++; + req.local_port = port; + req_len++; + } + + 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 + , req_len, payload_buf->buf, command_array ); + + // Send uart command request + mSnicWifi_p->sendUart( command_len, command_array ); + + int ret; + // Wait UART response + ret = mSnicWifi_p->mUartCommand.wait(); + if( ret != 0 ) + { + printf( "createSocket failed\r\n" ); + mSnicWifi_p->freeCmdBuf( payload_buf ); + return -1; + } + + if( mSnicWifi_p->mUartCommand.getCommandStatus() != 0 ) + { + printf("createSocket status:%02x\r\n", mSnicWifi_p->mUartCommand.getCommandStatus()); + mSnicWifi_p->freeCmdBuf( payload_buf ); + return -1; + } + mSocketID = payload_buf->buf[3]; + mSnicWifi_p->freeCmdBuf( payload_buf ); + + return 0; +}