7 changed files with 151 additions and 3 deletions
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* joystick utility functions |
||||
*/ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
#include <fcntl.h> |
||||
|
||||
#include <linux/joystick.h> |
||||
|
||||
#include "joyutils.h" |
||||
|
||||
/* ----------------------------------------------------------------- */ |
||||
static char *type2txt(unsigned char type) |
||||
{ |
||||
static char temp[100]; |
||||
|
||||
if (!(type & JS_EVENT_INIT)) { |
||||
switch(type) { |
||||
case JS_EVENT_BUTTON: return "button"; |
||||
case JS_EVENT_AXIS: return "axis"; |
||||
} |
||||
} |
||||
else { |
||||
sprintf(temp, "init %d", type & 0x7f); |
||||
return temp; |
||||
} |
||||
return "???"; |
||||
} |
||||
void dump_my_joystick(char *joy_device) |
||||
{ |
||||
int joy_fd, foo; |
||||
struct js_event js; |
||||
int flag = 0; |
||||
unsigned long debut; |
||||
|
||||
if( ( joy_fd = open(joy_device , O_RDONLY)) == -1 ) { |
||||
fprintf(stderr, "%s: couldn't open %s\n", __func__, joy_device); |
||||
exit(1); |
||||
} |
||||
|
||||
for (;;) { |
||||
foo = read(joy_fd, &js, sizeof(struct js_event)); |
||||
if ( ! flag ) { |
||||
debut = js.time; |
||||
flag = 1; |
||||
} |
||||
|
||||
if (8 != foo) { |
||||
fprintf(stderr, "%s: err reading joy\n", __func__); |
||||
exit(1); |
||||
} |
||||
|
||||
printf("%8lu %4d / %-8s %2d %7d\n", |
||||
js.time-debut, |
||||
js.type, type2txt(js.type), |
||||
js.number, js.value); |
||||
|
||||
} |
||||
|
||||
} |
||||
/* ----------------------------------------------------------------- */ |
||||
|
||||
/* ----------------------------------------------------------------- */ |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* joystick utility functions |
||||
*/ |
||||
|
||||
|
||||
void dump_my_joystick(char *joy_device); |
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
localhost:9001 |
||||
localhost:9002 |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/python |
||||
|
||||
import socket, sys, getopt |
||||
|
||||
# --- default values |
||||
|
||||
RX_UDP_IP = "" # pour ecouter sur toutes les interfaces |
||||
RX_UDP_PORT = 5005 # entree du relais |
||||
|
||||
# --- |
||||
|
||||
rx_port = RX_UDP_PORT |
||||
verbose = 0 |
||||
|
||||
# --- parse command line arguments |
||||
|
||||
options = "hvp:c:" |
||||
arguments = sys.argv[1:] |
||||
opts, args = getopt.getopt(arguments, options) |
||||
|
||||
for o, a in opts: |
||||
print ' ', o, ' --> ', a |
||||
if "-v" == o: verbose += 1 |
||||
elif "-p" == o: rx_port = int(a) |
||||
|
||||
print "listening port : ", rx_port |
||||
|
||||
# --- |
||||
|
||||
cibles = [ ]; |
||||
for ligne in open("destinations.liste"): |
||||
a, p = ligne.replace('\n', '').split(":") |
||||
# print a, p |
||||
if p: cibles.append((a, int(p))) |
||||
|
||||
for cible in cibles: |
||||
print " -> ", cible |
||||
|
||||
|
||||
# point d'entree, d'ecoute |
||||
sock_rx = socket.socket(socket.AF_INET, # Internet |
||||
socket.SOCK_DGRAM) # UDP |
||||
sock_rx.bind((RX_UDP_IP, rx_port)) |
||||
|
||||
# point de sortie vers les autres |
||||
sock_tx = socket.socket(socket.AF_INET, # Internet |
||||
socket.SOCK_DGRAM) # UDP |
||||
|
||||
while True: |
||||
data, addr = sock_rx.recvfrom(1024) # buffer size is 1024 bytes |
||||
if verbose: |
||||
print "got:", addr, " ", len(data) |
||||
for cible in cibles: |
||||
# print cible |
||||
sock_tx.sendto(data, cible) |
||||
|
||||
# hop, ce truc doit fonctionner ! |
||||
|
||||
|
||||
|
Loading…
Reference in new issue