24 #include "acquisition_thread.h"
25 #include "act_thread.h"
26 #include "remote_bb_poster.h"
28 #include <core/threading/thread.h>
29 #include <core/threading/wait_condition.h>
30 #include <core/exceptions/system.h>
31 #include <netcomm/fawkes/client.h>
32 #include <blackboard/remote.h>
33 #include <blackboard/interface_listener.h>
34 #include <utils/system/argparser.h>
35 #include <utils/system/signal.h>
36 #include <logging/console.h>
37 #include <netcomm/fawkes/client_handler.h>
38 #include <netcomm/socket/socket.h>
46 #include <interfaces/JoystickInterface.h>
48 using namespace fawkes;
53 print_usage(
const char *program_name)
55 printf(
"Usage: %s [-h] [-r host[:port]] [-d device] [-l]\n"
56 " -h This help message\n"
57 " -r host[:port] Remote host (and optionally port) to connect to\n"
58 " -d device Joystick device to use\n"
59 " -l Start in logging mode - print data read from bb\n",
77 virtual void handle_signal(
int signal)
100 __argp(argp), __logger(logger)
102 char *host = (
char *)
"localhost";
103 unsigned short int port = 1910;
107 if ( free_host ) free(host);
110 __warning_printed =
false;
112 __joystick_if->
read();
113 logger->
log_debug(
"Joystick",
"Number of Axes: %i",
114 __joystick_if->num_axes());
115 logger->
log_debug(
"Joystick",
"Number of Buttons: %i",
116 __joystick_if->num_buttons());
125 bbil_add_data_interface(__joystick_if);
126 __bb->register_listener(
this);
132 __bb->close(__joystick_if);
136 virtual void bb_interface_data_changed(
Interface *interface)
throw()
138 if ( ! __bb->is_alive() ) {
139 if ( __bb->try_aliveness_restore() ) {
140 __logger->log_info(
"Joystick",
"Connection re-established, writing data");
141 __warning_printed =
false;
146 __joystick_if->read();
147 float *axis_value = __joystick_if->axis();
148 __logger->log_info(
"Joystick",
"Axes: 0: %f 1: %f 2: %f 3: %f 4: %f "
149 "5: %f 6: %f 7: %f 8: %f",
150 axis_value[0], axis_value[1],
151 axis_value[2], axis_value[3],
152 axis_value[4], axis_value[5],
153 axis_value[6], axis_value[7]);
154 char button_string[33];
155 button_string[32] = 0;
156 unsigned int pressed_buttons = __joystick_if->pressed_buttons();
157 for (
unsigned int i = 0; i < 32; ++i) {
158 button_string[i] = (pressed_buttons & (1 << i)) ?
'1' :
'0';
160 __logger->log_info(
"Joystick",
"Buttons: %s", button_string);
162 if ( ! __warning_printed ) {
164 __logger->log_warn(
"Joystick",
"Lost connection to BlackBoard, "
165 "will try to re-establish");
166 __warning_printed =
true;
171 void handle_signal(
int signum)
173 __waitcond.wake_all();
183 bool __warning_printed;
210 __bb(blackboard), __joystick_if(joystick_if),
214 __msgproc->process();
215 bbil_add_message_interface(__joystick_if);
216 __bb->register_listener(
this);
222 __bb->unregister_listener(
this);
223 bbil_remove_message_interface(__joystick_if);
227 virtual bool bb_interface_message_received(
Interface *interface,
231 __msgproc->process();
232 __msgproc->process_message(message);
251 main(
int argc,
char **argv)
257 if ( argp.has_arg(
"h") ) {
258 print_usage(argv[0]);
262 const char *joystick_device =
"/dev/input/js0";
263 if ( argp.has_arg(
"d") ) {
264 joystick_device = argp.arg(
"d");
269 if ( argp.has_arg(
"l") ) {
274 char *host = (
char *)
"localhost";
275 unsigned short int port = 1910;
276 bool free_host = argp.parse_hostport(
"r", &host, &port);
281 jbp.joystick_if(), &logger);
286 if (free_host) free(host);
294 printf(
"Error: Unknown Argument\n\n");
295 print_usage(argv[0]);
300 printf(
"\nError: could not connect:\n%s\n", e.
what());
304 printf(
"\nError: could not open joystick device:\n%s\n", e.
what());