hello:
#ifdef SUPPORT_ADC
#define OWN_TASK TASK_ADC
#define UDP_BUFFER_SIZE 512
#define MY_UDP_PORT 1999
typedef struct stUDP_MESSAGE
{
unsigned short usLength;
UDP_HEADER tUDP_Header; // reserve header space
unsigned char ucUDP_Message[UDP_BUFFER_SIZE]; // reserve message space
} UDP_MESSAGE;
static unsigned char ucUDP_IP_Address[IPV4_LENGTH] = {192, 168, 0, 37}; // address to send UDP test frames to
static USOCKET MyUDP_Socket;
static UDP_MESSAGE *ptrUDP_Frame;
unsigned char *p,buf[8]={0,1,2,3,4,5,6,7};
int err;
static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
switch (ucEvent) {
case UDP_EVENT_RXDATA:
//if (usPortNr != MY_UDP_PORT) break; // ignore false ports
//if (uMemcmp(ucIP, ucUDP_IP_Address, IPV4_LENGTH)) break; // ignore if not from expected IP address
//if (usLength <= UDP_BUFFER_SIZE) { // ignore frames which are too large
//uMemcpy(&ptrUDP_Frame->ucUDP_Message, data, usLength); // Send the received UDP frame back
// fnSendUDP(MyUDP_Socket, ucUDP_IP_Address, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, usLength, OWN_TASK);
//}
fnSendUDP(MyUDP_Socket, ucIP, usPortNr, (data - sizeof(UDP_HEADER)), usLength, OWN_TASK); // echo back from transmitting IP and port
break;
case UDP_EVENT_PORT_UNREACHABLE: // we have received information that this port is not available at the destination so quit
break;
}
return 0;
}
static void fnConfigUDP(void)
{
if (!((MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS))) < 0)) {
fnBindSocket(MyUDP_Socket, MY_UDP_PORT); // Bind socket
ptrUDP_Frame = uMalloc(sizeof(UDP_MESSAGE)); // get some memory for UDP frame
}
else {
return; // no socket - this must never happen (ensure that enough user UDP sockets have been defined - USER_UDP_SOCKETS in config.h)!!
}
}
void fnADC(TTASKTABLE *ptrTaskTable)
{ //static UDP_MESSAGE *ptrUDP_Frame = uMalloc(sizeof(UDP_MESSAGE)); // get some memory for UDP frame
const unsigned char test_data[] = {1,2,3,4,5,6,7,8};
int i;
//char err[1];
i=1;
RUN_LED(); // hardware dependent
if(i==1) fnConfigUDP();
uMemcpy(&ptrUDP_Frame->ucUDP_Message, test_data, sizeof(test_data)); // Send the received UDP frame back
fnSendUDP(MyUDP_Socket, ucUDP_IP_Address, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, sizeof(test_data), OWN_TASK);
i++;
if(i==100) i=2;
}
#endif
#ifdef SUPPORT_ADC
{ "ecDA", fnADC, NO_QUE, (DELAY_LIMIT)(2.0 * SEC), (DELAY_LIMIT)(2 * SEC), UTASKER_STOP}, //
fnADC(TTASKTABLE *ptrTaskTable) maybe run per (2.0 * SEC)!
but I can get the udp data at pc one time!
I want to get the udp data more ,because per 2 SECOND it will sent ,but only once I can get the data!
and the RUN_LED() is ok! the led can ON or OFF at per (2.0 * SEC)!
WhY???
I want to get
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
after 2.0 * SEC
01 02 03 04 05 06 07 08
......................................
NO like that:
01 02 03 04 05 06 07 08
(over no more )