AnsweredAssumed Answered

RTCS_selectall and RTCS_selectset

Question asked by Ferrari Gionatha on Nov 29, 2011
Latest reply on Jan 19, 2012 by Bryan Hunt

Hi all,

 

I'm using K60 (tower board) and MQX 3.7

 

I'd like to use socket to receive UDP packets (800bytes every 32ms) in 2 different ports.

 

I have tried to use RTCS_selectall but I lose some packets.

So I'have tried this simple code:

 

....

_int_install_unexpected_isr();

 

// Inizialize networking

initialize_networking();

 

// local address initialization
laddr.sin_family = AF_INET;
laddr.sin_port = 2500;
laddr.sin_addr.s_addr = INADDR_ANY;

 

// Create a datagram socket:
socklist[ID_SOCKET_SDO] = socket(PF_INET, SOCK_DGRAM, 0);
if (socklist[ID_SOCKET_SDO] == RTCS_SOCKET_ERROR) {
printf("\nFailed to create datagram socket.");
_task_block();
}

 

// Bind the datagram socket to the UDP port:
error = bind(socklist[ID_SOCKET_SDO], &laddr, sizeof(laddr));
if (error != RTCS_OK) {
printf("\nFailed to bind datagram - 0x%lx.", error);
_task_block();
}

 

laddr.sin_port = 2501;

// Create a datagram socket:
socklist[ID_SOCKET_PROFILO_MOTO] = socket(PF_INET, SOCK_DGRAM, 0);
if (socklist[ID_SOCKET_PROFILO_MOTO] == RTCS_SOCKET_ERROR) {
printf("\nFailed to create datagram socket.");
_task_block();
}

 

// Bind the datagram socket to the UDP port:
error = bind(socklist[ID_SOCKET_PROFILO_MOTO], &laddr, sizeof(laddr));
if (error != RTCS_OK) {
printf("\nFailed to bind datagram - 0x%lx.", error);
_task_block();
}

 

// Echo server

// error = ECHOSRV_init("EchoServer", 17, 1000);
// if (error != RTCS_OK) {
// printf("\nFailed to echo server init - 0x%lx.", error);
// _task_block();
// }

 

while (TRUE) {

// prepare recevive structs
GPIOA_PDOR ^= BIT_29; // green led TOGGLE
sock = RTCS_selectset(socklist, NUM_SOCKET_WAITING, 100);

...

}

 

If I stop the sender device, I suppose I have to see every 100ms my led toggle.

This doesn't happen, the timeout is... random. Sometimes is bigger than a second.

Why?

 

Thank you

G

Outcomes