|
- #include <assert.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <math.h>
-
- #include <arpa/inet.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
-
- #include "linalg.h"
- #include "licks_message.h"
-
- licks_message message;
- licks_net_message net_message;
-
- int udp_socket_fd;
-
- struct sockaddr_in localaddr;
- struct sockaddr_in remoteaddr;
-
- int
- main(int argc, char **argv) {
- int quit=0;
- udp_socket_fd=socket(PF_INET,SOCK_DGRAM,0);
- if(udp_socket_fd==-1) {
- perror("socket");
- exit(0);
- }
-
- localaddr.sin_family=AF_INET;
- localaddr.sin_port=htons(1337);
- inet_aton("0.0.0.0",&localaddr.sin_addr);;
-
- if(bind(udp_socket_fd,(struct sockaddr *)&localaddr,sizeof(struct sockaddr_in))) {
- perror("bind");
- exit(0);
- }
-
- licks_socket_open("/tmp/udpproxy");
- while(!quit) {
- read(udp_socket_fd,&net_message,sizeof(licks_net_message));
- switch(net_message.type) {
- case MSG_QUIT:
- message.type=MSG_QUIT;
- send_message(&message,ikd_path);
- break;
- case MSG_POWER:
- message.type=MSG_POWER;
- message.i=net_message.i;
- send_message(&message,ikd_path);
- break;
- case MSG_MOVE_BODY:
- message.type=MSG_MOVE_BODY;
- message.move_parameters.v.x=net_message.move_parameters.v.x/1000.0;
- message.move_parameters.v.y=net_message.move_parameters.v.y/1000.0;
- message.move_parameters.v.z=net_message.move_parameters.v.z/1000.0;
- message.move_parameters.duration=net_message.move_parameters.duration;
- send_message(&message,ikd_path);
- break;
- case MSG_WALK:
- message.type=MSG_WALK;
- message.walk_parameters.step_direction.x=net_message.move_parameters.v.x/1000.0;
- message.walk_parameters.step_direction.y=net_message.move_parameters.v.y/1000.0;
- message.walk_parameters.step_rotation=net_message.move_parameters.v.z/1000.0;
- send_message(&message,ikd_path);
- break;
- case MSG_ROTATE_BODY:
- message.type=MSG_ROTATE_BODY;
- message.move_parameters.v.x=net_message.move_parameters.v.x/3276.8;
- message.move_parameters.v.y=net_message.move_parameters.v.y/3276.8;
- message.move_parameters.v.z=net_message.move_parameters.v.z/3276.8;
- message.move_parameters.duration=net_message.move_parameters.duration;
- send_message(&message,ikd_path);
- break;
- }
- }
- licks_socket_close();
-
- close(udp_socket_fd);
- return 0;
- }
|