Exemple #1
0
void update_rc(uint16_t left_x, uint16_t left_y, uint16_t right_x, uint16_t right_y, uint8_t button)
{
  
  rcPacket.header.cmd = E_RC_CMD_SEND_RC_DATA;
  
  rcPacket.payLoad.data.axis_left_x = left_x;
  rcPacket.payLoad.data.axis_left_y = left_y;
  rcPacket.payLoad.data.axis_right_x = right_x;
  rcPacket.payLoad.data.axis_right_y = right_y;
  rcPacket.payLoad.data.button = button;

  send_rc(sizeof(rcPacket), (uint8_t*)&rcPacket);
}
Exemple #2
0
void update_rc(uint16_t left_x, uint16_t left_y, uint16_t right_x, uint16_t right_y, uint8_t button, uint8_t led)
{
  printf("(L_x, L_y, R_x, R_y button, led)=(%4d, %4d, %4d, %4d, 0x%2x, 0x%2x)\n", left_x, left_y, right_x, right_y, button, led);
  
  rcPacket.header.cmd = E_RC_CMD_SEND_RC_DATA;
  
  rcPacket.payLoad.data.axis_left_x = left_x;
  rcPacket.payLoad.data.axis_left_y = left_y;
  rcPacket.payLoad.data.axis_right_x = right_x;
  rcPacket.payLoad.data.axis_right_y = right_y;
  rcPacket.payLoad.data.button = button;
  rcPacket.payLoad.data.led = led;

  printf("RendRC!\n");
  send_rc(sizeof(rcPacket), (uint8_t*)&rcPacket);
}
Exemple #3
0
int main(int argc, char *argv[]) {
	int want_dump=0;
	int lport;
	int sock, n, i;
	size_t length, fromlen;
	struct sockaddr_in addr;
	struct sockaddr_in from;
	char buf[BUFSIZ];

	remoteconnection *rc = NULL; 

	if (argc == 2) {
		if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
			printversion(argv[0]);
			return (0);
		}
		if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
				usage (argv[0], 0);
		}
	}

	if (argc < 2)
		usage(argv[0], 1);

	lport = atoi(argv[1]);
	rc=calloc((argc-2), sizeof(remoteconnection));

	if (argc == 2) {
		want_dump = 1;	
		//printf("raw data dump mode!\n");
	}
	for (i=2; i < argc; i++) {
		char *hostname=NULL;
		int port=0;
		if(!splithp(argv[i], &hostname, &port)) {
			open_rc(&(rc[(i-2)]), hostname, port);
			rc[(i-2)].port=port;
			rc[(i-2)].hostname=hostname;
			//printf(" dup to h:%s p:%i\n", hostname, port);
		}
	}

	sock=socket(AF_INET, SOCK_DGRAM, 0);
	if (sock < 0)
		error("Opening socket");

	setnonblock(sock, 1);

	int val=1;
#ifndef HAVE_WINDOWS
	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val,  sizeof(int));
#else
	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &val,  sizeof(int));
#endif

	length = sizeof(addr);
	bzero(&addr, length);
	addr.sin_family=AF_INET;
	addr.sin_addr.s_addr=INADDR_ANY;
	addr.sin_port=htons(lport);
	if (bind(sock, (struct sockaddr *)&addr, length)<0)
		error("binding to port %i failed.", lport);
	fromlen = sizeof(struct sockaddr_in);

	run=1;
#ifndef HAVE_WINDOWS
	signal (SIGHUP, catchsig);
	signal (SIGINT, catchsig);
#endif

	while (run) {
    fd_set rfds;
    struct timeval tv;
    tv.tv_sec = 1; tv.tv_usec = 0;

    FD_ZERO(&rfds);
    FD_SET(sock, &rfds);
    if((select(sock+1, &rfds, NULL, NULL, &tv))<0) {
      if (errno!=EINTR) {
        break;
			}
			continue;
    }
    if(!FD_ISSET(sock, &rfds)) 
			continue;

		n = recvfrom(sock, buf, BUFSIZ, 0, (struct sockaddr *)&from, &fromlen);
		if (n < 0)
			error("recvfrom");
		if (want_dump) {
			//printf("Received a datagram: ");
			write(1, buf, n);
			//printf("\n"); 
			fsync(1);
		}
		for (i=2; i < argc; i++) {
			send_rc(&(rc[i-2]), buf, n);
		}
	}

	for (i=2; i < argc; i++) {
		close_rc(&(rc[i-2]));
		free(rc[(i-2)].hostname);
	}
#ifndef HAVE_WINDOWS
    close(sock); 
#else
    closesocket(sock);
#endif

	return (0);
}