void *thread_roverdata(void* arg)
{
int i, ret;
// Allocate memory for read buffer, set size according to your needs
unsigned char read_buf [DATA_LEN];
// Normally you wouldn't do this memset() call, but since we will just receive
// ASCII data for this example, we'll set everything to 0 so we can
// call printf() easily.
memset(&read_buf, '\0', sizeof(read_buf));
// Read bytes. The behaviour of read() (e.g. does it block?,
// how long does it block for?) depends on the configuration
// settings above, specifically VMIN and VTIME
int num_bytes = 0;
int len = 0;
int epfd, nfds;
struct epoll_event event;
struct epoll_event* events;
events=calloc(10, sizeof(event));
epfd = epoll_create(10); // 创建epoll实例
event.data.fd = uart5; // 添加标准输入到epoll
event.events = EPOLLIN; // EPOLLET: epoll中的边沿触发的意思是只对新到的数据进行通知,而内核缓冲区中如果是旧数据则不进行通知
epoll_ctl(epfd, EPOLL_CTL_ADD, uart5, &event);
for(;;)
{
ret = epoll_wait(epfd, events, 10, -1);// -1 :wait until it happen
for(i=0; i<ret; i++)
{
if (events[i].data.fd == uart5) {
num_bytes = read(events[i].data.fd, read_buf, DATA_LEN);
if (num_bytes < 0)
{
UARTSendData((char*)"Error reading: %s\r\n", strerror(errno));
//while(1);
}
RTK_LOCATION_HandleRoverData(read_buf, num_bytes);
// WriteFIFO(&save_fifo,read_buf, num_bytes);
num_bytes = 0;
}
}
}
close(uart5);
}