drivers/can_serial/can_serial_hub.c
changeset 451 236c2e901e2e
parent 448 732c33c2d8a7
equal deleted inserted replaced
450:dff8cc600cba 451:236c2e901e2e
   188 int read_write(int rd_port, port *p, CAN_HANDLE h, fd_set *wfds, int max_fd)
   188 int read_write(int rd_port, port *p, CAN_HANDLE h, fd_set *wfds, int max_fd)
   189 {
   189 {
   190 	Message m;
   190 	Message m;
   191 	int rv, i;
   191 	int rv, i;
   192 	fd_set wfds_copy;
   192 	fd_set wfds_copy;
   193 	struct timeval tv = {.tv_sec = 0, .tv_usec = 0}; //wait 1 msec
   193 	struct timeval tv = {.tv_sec = 0, .tv_usec = 0}; //wait 0 msec
   194 
   194 
   195 	if (rd_port == MAX_HUB_PORTS) {
   195 	if (rd_port == MAX_HUB_PORTS) {
   196 		rv = DLL_CALL(canReceive)(h, &m);
   196 		rv = DLL_CALL(canReceive)(h, &m);
   197 
   197 
   198 		if (rv == 1) {
   198 		if (rv == 1) {
   219 		if (i == rd_port) {
   219 		if (i == rd_port) {
   220 			fprintf(stderr, "[%d] ", i);
   220 			fprintf(stderr, "[%d] ", i);
   221 			continue;
   221 			continue;
   222 		}
   222 		}
   223 
   223 
   224 		if (rv <= 0 || !FD_ISSET(p[i].fd, &wfds_copy)) {
   224 		if (p[i].fd < 0 || !FD_ISSET(p[i].fd, &wfds_copy)) {
   225 			fprintf(stderr, "{%d} ", i);
   225 			fprintf(stderr, "{%d} ", i);
   226 			continue;
   226 			continue;
   227 		}
   227 		}
   228 
   228 
   229 		fprintf(stderr, "<%d> ", i);
   229 		fprintf(stderr, "<%d> ", i);
   426 			continue;
   426 			continue;
   427 		}
   427 		}
   428 
   428 
   429 		//as timeout is NULL, must be a rfds set.
   429 		//as timeout is NULL, must be a rfds set.
   430 		for (i = 0; i < MAX_HUB_PORTS + 1; i++) {
   430 		for (i = 0; i < MAX_HUB_PORTS + 1; i++) {
   431 			if (FD_ISSET(hub_ports[i].fd, &rfds_copy)) {
   431 			if (hub_ports[i].fd >= 0 && 
       
   432 					FD_ISSET(hub_ports[i].fd, &rfds_copy)) {
   432 
   433 
   433 				rv = read_write(i, hub_ports, can_h, &rfds, max_fd);
   434 				rv = read_write(i, hub_ports, can_h, &rfds, max_fd);
   434 
   435 
   435 				if (rv < 0 && i < MAX_HUB_PORTS) {
   436 				if (rv < 0 && i < MAX_HUB_PORTS) {
   436 
   437 
   437 					FD_CLR(hub_ports[i].fd, &rfds);
   438 					FD_CLR(hub_ports[i].fd, &rfds);
   438 
   439 
   439 					hub_close(&hub_ports[i]);
   440 					hub_close(&hub_ports[i]);
   440 
   441 				}						
   441 					rv = hub_open(&hub_ports[i]);
   442 			}
   442 
   443 
   443 					if (rv < 0) {
   444 			if (hub_ports[i].fd < 0 && i < MAX_HUB_PORTS) {
   444 						ret = 1;
   445 				rv = hub_open(&hub_ports[i]);
   445 						break;
   446 
   446 					}
   447 				if (rv >= 0) {
   447 
       
   448 					FD_SET(rv, &rfds);
   448 					FD_SET(rv, &rfds);
   449 
   449 
   450 					if (rv > max_fd) {
   450 					if (rv > max_fd) {
   451 						max_fd = rv;
   451 						max_fd = rv;
   452 					}					
   452 					}
   453 				}						
   453 				}
   454 			}
   454 			}
   455 		}
   455 		}
   456 	}
   456 	}
   457 
   457 
   458 	for (i = 0; i < MAX_HUB_PORTS; i++) {
   458 	for (i = 0; i < MAX_HUB_PORTS; i++) {