Customized
Dependents: MurataTypeYD_RPC_Sample
Fork of SNICInterface_mod by
Diff: Socket/Socket.cpp
- Revision:
- 27:dcc4f34448f0
- Parent:
- 24:987e412ae879
- Child:
- 29:6a0ba999597d
diff -r f2e1030964e4 -r dcc4f34448f0 Socket/Socket.cpp --- a/Socket/Socket.cpp Fri Mar 28 03:03:40 2014 +0000 +++ b/Socket/Socket.cpp Mon Mar 31 02:06:14 2014 +0000 @@ -51,7 +51,50 @@ int Socket::close(bool shutdown) { + 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 = snic_core_p->allocCmdBuf(); + if( payload_buf == NULL ) + { + printf("socket close payload_buf NULL\r\n"); + return -1; + } + + C_SNIC_Core::tagSNIC_CLOSE_SOCKET_REQ_T req; + // Make request + req.cmd_sid = UART_CMD_SID_SNIC_CLOSE_SOCKET_REQ; + req.seq = mUartRequestSeq++; + req.socket_id = mSocketID; + + unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; + 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_CLOSE_SOCKET_REQ_T), payload_buf->buf, command_array ); + + // Send uart command request + snic_core_p->sendUart( command_len, command_array ); + + int ret; + // Wait UART response + ret = uartCmdMgr_p->wait(); + if( ret != 0 ) + { + printf( "socket close failed\r\n" ); + snic_core_p->freeCmdBuf( payload_buf ); + return -1; + } + + if( uartCmdMgr_p->getCommandStatus() != 0 ) + { + printf("socket close status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); + snic_core_p->freeCmdBuf( payload_buf ); + return -1; + } + snic_core_p->freeCmdBuf( payload_buf ); + return 0; } @@ -124,3 +167,44 @@ return 0; } + +int Socket::addrToInteger( const char *addr_p ) +{ + if( addr_p == NULL ) + { + printf("addrToInteger parameter error\r\n"); + return 0; + } + + unsigned char ipadr[4]; + unsigned char temp= 0; + int i,j,k; + + /* convert to char[4] */ + k=0; + for(i=0; i<4; i ++) + { + for(j=0; j<4; j ++) + { + if((addr_p[k] > 0x2F)&&(addr_p[k] < 0x3A)) + { + temp = (temp * 10) + addr_p[k]-0x30; + } + else if((addr_p[k] == 0x20)&&(temp == 0)) + { + } + else + { + ipadr[i]=temp; + temp = 0; + k++; + break; + } + k++; + } + } + + int addr = ( (ipadr[0]<<24) | (ipadr[1]<<16) | (ipadr[2]<<8) | ipadr[3] ); + + return addr; +}