forked from xuos/xiuos
optimize socket demo on nuttx
This commit is contained in:
parent
7052951624
commit
48250b7285
|
@ -50,7 +50,7 @@ uint16_t tcp_socket_port = LWIP_TARGET_PORT;
|
|||
char tcp_ip_str[128] = {0};
|
||||
|
||||
/******************************************************************************/
|
||||
void tcp_set_ip(char *ip_str)
|
||||
void TcpSocketConfigParam(char *ip_str)
|
||||
{
|
||||
int ip1, ip2, ip3, ip4, port = 0;
|
||||
|
||||
|
@ -83,7 +83,7 @@ void tcp_set_ip(char *ip_str)
|
|||
}
|
||||
}
|
||||
|
||||
static void TCPSocketRecvTask(void *arg)
|
||||
static void TcpSocketRecvTask(void *arg)
|
||||
{
|
||||
int fd = -1, clientfd;
|
||||
int recv_len;
|
||||
|
@ -155,24 +155,26 @@ static void TCPSocketRecvTask(void *arg)
|
|||
free(recv_buf);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
void TCPSocketRecvTest(int argc, char *argv[])
|
||||
void TcpSocketRecvTest(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_print("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
tcp_set_ip(argv[1]);
|
||||
TcpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
sys_thread_new("TCPSocketRecvTask", TCPSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(TCPSocketRecvTest, a tcp receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
sys_thread_new("TcpSocketRecvTask", TcpSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
|
||||
static void TCPSocketSendTask(void *arg)
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
TcpSocketRecvTask(NULL);
|
||||
#endif
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(TcpSocketRecvTest, a tcp receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
static void TcpSocketSendTask(void *arg)
|
||||
{
|
||||
int cnt = LWIP_DEMO_TIMES;
|
||||
int fd = -1;
|
||||
|
@ -219,32 +221,21 @@ static void TCPSocketSendTask(void *arg)
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
void TCPSocketSendTest(int argc, char *argv[])
|
||||
void TcpSocketSendTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_print("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
tcp_set_ip(argv[1]);
|
||||
TcpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
sys_thread_new("TCP Socket Send", TCPSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(TCPSocketSendTest, a tcp send sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
sys_thread_new("Tcp Socket Send", TcpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
void tcp_recv_demo(char *ip_str)
|
||||
{
|
||||
tcp_set_ip(ip_str);
|
||||
TCPSocketRecvTask(NULL);
|
||||
}
|
||||
|
||||
void tcp_send_demo(char *ip_str)
|
||||
{
|
||||
tcp_set_ip(ip_str);
|
||||
TCPSocketSendTask(NULL);
|
||||
}
|
||||
TcpSocketSendTask(NULL);
|
||||
#endif
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(TcpSocketSendTest, a tcp send sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ char udp_ip_str[128] = {0};
|
|||
uint16_t udp_socket_port = LWIP_LOCAL_PORT;
|
||||
|
||||
/*****************************************************************************/
|
||||
void udp_set_ip(char *ip_str)
|
||||
void UdpSocketConfigParam(char *ip_str)
|
||||
{
|
||||
int ip1, ip2, ip3, ip4, port = 0;
|
||||
|
||||
|
@ -115,7 +115,7 @@ static void UdpSocketRecvTask(void *arg)
|
|||
continue;
|
||||
}
|
||||
|
||||
lw_notice("UDP bind sucess, start to receive.\n");
|
||||
lw_notice("UDP bind success, start to receive.\n");
|
||||
lw_notice("\n\nLocal Port:%d\n\n", udp_socket_port);
|
||||
|
||||
while(1)
|
||||
|
@ -135,21 +135,24 @@ static void UdpSocketRecvTask(void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
void UdpSocketRecvTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
udp_set_ip(argv[1]);
|
||||
UdpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, NULL,
|
||||
LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
UdpSocketRecvTask(NULL);
|
||||
#endif
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(UdpSocketRecvTest, a udp receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
#endif
|
||||
|
||||
static void UdpSocketSendTask(void *arg)
|
||||
{
|
||||
|
@ -195,32 +198,22 @@ static void UdpSocketSendTask(void *arg)
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
void UdpSocketSendTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
udp_set_ip(argv[1]);
|
||||
UdpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE,
|
||||
sLWIP_DEMO_TASK_PRIO);
|
||||
LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
UdpSocketSendTask(NULL);
|
||||
#endif
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(UdpSocketSendTest, a udp send sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
#endif
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
void udp_recv_demo(char *ip_str)
|
||||
{
|
||||
udp_set_ip(ip_str);
|
||||
UdpSocketRecvTask(NULL);
|
||||
}
|
||||
|
||||
void udp_send_demo(char *ip_str)
|
||||
{
|
||||
udp_set_ip(ip_str);
|
||||
UdpSocketSendTask(NULL);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -73,9 +73,7 @@ CONFIG_READLINE_CMD_HISTORY=y
|
|||
CONFIG_READLINE_CMD_HISTORY_LEN=100
|
||||
CONFIG_READLINE_CMD_HISTORY_LINELEN=120
|
||||
CONFIG_READLINE_TABCOMPLETION=y
|
||||
CONFIG_FS_ROMFS=y
|
||||
CONFIG_NSH_ROMFSETC=y
|
||||
CONFIG_NSH_ARCHROMFS=y
|
||||
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_APPLICATION_CONNECTION=y
|
||||
|
|
|
@ -81,45 +81,35 @@ int cmd_Extsram(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||
* Name: socket test
|
||||
****************************************************************************/
|
||||
#if defined(CONFIG_SOCKET_DEMO) && !defined(CONFIG_NSH_DISABLE_SOCKET_DEMO)
|
||||
extern void udp_set_ip(char *ip_str);
|
||||
extern int udp_recv_demo(void);
|
||||
void UdpSocketRecvTest(int argc, char *argv[]);
|
||||
int cmd_Udprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
nsh_output(vtbl, "Hello, UDP receive!\n");
|
||||
if(argc == 2)
|
||||
udp_set_ip(argv[1]);
|
||||
udp_recv_demo();
|
||||
UdpSocketRecvTest(argc, argv);
|
||||
return OK;
|
||||
}
|
||||
|
||||
extern int udp_send_demo(void);
|
||||
void UdpSocketSendTest(int argc, char *argv[]);
|
||||
int cmd_Udpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
nsh_output(vtbl, "Hello, UDP send!\n");
|
||||
if(argc == 2)
|
||||
udp_set_ip(argv[1]);
|
||||
udp_send_demo();
|
||||
UdpSocketSendTest(argc, argv);
|
||||
return OK;
|
||||
}
|
||||
|
||||
extern void tcp_set_ip(char *ip_str);
|
||||
extern int tcp_recv_demo(void);
|
||||
void TcpSocketRecvTest(int argc, char *argv[]);
|
||||
int cmd_Tcprecv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
nsh_output(vtbl, "Hello, TCP receive!\n");
|
||||
if(argc == 2)
|
||||
tcp_set_ip(argv[1]);
|
||||
tcp_recv_demo();
|
||||
TcpSocketRecvTest(argc, argv);
|
||||
return OK;
|
||||
}
|
||||
|
||||
extern int tcp_send_demo(void);
|
||||
void TcpSocketSendTest(int argc, char *argv[]);
|
||||
int cmd_Tcpsend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
nsh_output(vtbl, "Hello, TCP send!\n");
|
||||
if(argc == 2)
|
||||
tcp_set_ip(argv[1]);
|
||||
tcp_send_demo();
|
||||
TcpSocketSendTest(argc, argv);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue