optimize w5500 socket test cmd for edu-riscv64 board

This commit is contained in:
wgzAIIT 2023-02-27 16:59:08 +08:00
parent 779444f998
commit 0996e47b88
1 changed files with 53 additions and 36 deletions

View File

@ -437,44 +437,61 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC) |
wiz_server_op, wiz_server_test, wiz_server_op, wiz_server_test,
wiz_sock_recv or wiz_sock_send data as tcp server); wiz_sock_recv or wiz_sock_send data as tcp server);
int32_t loopback_udps(uint8_t sn, uint8_t *buf, uint16_t port) { void loopback_udps(int argc, char *argv[])
int32_t ret; {
uint16_t size, sentsize; /* argv[1]: remote_ip ip address of remote udp
uint8_t destip[4]; * argv[2]: remote_port the port number of the remote udp
uint16_t destport; * argv[2]: local_port the port number of the local udp
// uint8_t packinfo = 0; */
switch (getSn_SR(sn)) { uint32_t tmp_ip[4];
uint8_t remote_ip[4];
uint16_t remote_port, local_port;
uint8_t buffer[g_wiznet_buf_size];
uint16_t len = 0;
if (argc < 4)
{
KPrintf("loopback_udps test error\n");
return;
}
sscanf(argv[1], "%d.%d.%d.%d", &tmp_ip[0], &tmp_ip[1], &tmp_ip[2], &tmp_ip[3]);
for(int i = 0;i < 4; i++)
{
remote_ip[i] = (uint8_t)tmp_ip[i];
}
remote_port = atoi(argv[2]);
local_port = atoi(argv[3]);
while(1)
{
switch (getSn_SR(0))
{
case SOCK_UDP: case SOCK_UDP:
if ((size = getSn_RX_RSR(sn)) > 0) { if(getSn_IR(0) & Sn_IR_RECV)
if (size > g_wiznet_buf_size) size = g_wiznet_buf_size; {
ret = wiz_sock_recvfrom(sn, buf, size, destip, (uint16_t *)&destport); setSn_IR(0, Sn_IR_RECV);
if (ret <= 0) {
printf("%d: wiz_sock_recvfrom error. %ld\r\n", sn, ret);
return ret;
}
size = (uint16_t)ret;
sentsize = 0;
while (sentsize != size) {
ret = wiz_sock_sendto(sn, buf + sentsize, size - sentsize, destip,
destport);
if (ret < 0) {
printf("%d: wiz_sock_sendto error. %ld\r\n", sn, ret);
return ret;
}
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
} }
if((len = getSn_RX_RSR(0))>0)
{
memset(buffer,0,len+1);
wiz_sock_recvfrom(0, buffer, len, remote_ip, (uint16_t *)&remote_port);
printf("received msg: %s\n", buffer);
wiz_sock_sendto(0, buffer, len, remote_ip, remote_port);
} }
break; break;
case SOCK_CLOSED: case SOCK_CLOSED:
printf("%d:LBUStart\r\n", sn); printf("LBUStart\r\n");
if ((ret = wiz_socket(sn, Sn_MR_UDP, port, 0x00)) != sn) return ret; wiz_socket(0, Sn_MR_UDP, local_port, 0);
printf("%d:Opened, port [%d]\r\n", sn, port);
break;
default:
break; break;
} }
return 1;
} }
}
/* wiz_udp remote_ip remote_port local_port */
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
wiz_udp, loopback_udps, w5500 upd test);
void ifconfig() { void ifconfig() {
wiz_NetInfo wiz_netinfo; wiz_NetInfo wiz_netinfo;