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> 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",
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);
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;
173 __waitcond.wake_all();
183 bool __warning_printed;
209 __bb(blackboard), __joystick_if(joystick_if)
212 __msgproc->process();
213 bbil_add_message_interface(__joystick_if);
214 __bb->register_listener(
this);
220 __bb->unregister_listener(
this);
221 bbil_remove_message_interface(__joystick_if);
229 __msgproc->process();
230 __msgproc->process_message(message);
248 main(
int argc,
char **argv)
255 print_usage(argv[0]);
259 const char *joystick_device =
"/dev/input/js0";
261 joystick_device = argp.
arg(
"d");
271 char *host = (
char *)
"localhost";
272 unsigned short int port = 1910;
283 if (free_host) free(host);
291 printf(
"Error: Unknown Argument\n\n");
292 print_usage(argv[0]);
297 printf(
"\nError: could not connect:\n%s\n", e.
what());
301 printf(
"\nError: could not open joystick device:\n%s\n", e.
what());
File could not be opened.
Wait until a given condition holds.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
const char * arg(const char *argn)
Get argument value.
bool parse_hostport(const char *argn, char **host, unsigned short int *port)
Parse host:port string.
Wake actuator thread on incomin messages.
JoystickQuitHandler(JoystickAcquisitionThread &aqt)
Constructor.
JoystickInterface Fawkes BlackBoard Interface.
Interface for logging to stderr.
Process incoming messages.
Fawkes library namespace.
void handle_signal(int signum)
Signal hanlding method.
Interface for signal handling.
~JoystickBlackBoardActListener()
Destructor.
Parse command line arguments.
virtual const char * what() const
Get primary string.
virtual void handle_signal(int signal)
Signal hanlding method.
Joystick acqusition thread for Linux joystick API.
Base class for all Fawkes BlackBoard interfaces.
virtual bool bb_interface_message_received(Interface *interface, Message *message)
BlackBoard message received notification.
~JoystickBlackBoardLogger()
Destructor.
Base class for exceptions in Fawkes.
void read()
Read from BlackBoard into local copy.
void run()
Wait for quit signal from signal handler.
Simple signal handler for ffjoystick.
Glue to post new data to a RemoteBlackBoard.
static SignalHandler * register_handler(int signum, SignalHandler *handler)
Register a SignalHandler for a signal.
Log joystick data gathered via RemoteBlackBoard to console.
fawkes::BlackBoard * blackboard()
Get blackboard.
JoystickBlackBoardActListener(JoystickAcquisitionThread *aqt, BlackBoard *blackboard, JoystickInterface *joystick_if, Logger *logger)
Constructor.
void print_trace()
Prints trace to stderr.
JoystickBlackBoardLogger(ArgumentParser &argp, Logger *logger)
Constructor.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
void join()
Join the thread.
bool has_arg(const char *argn)
Check if argument has been supplied.
The BlackBoard abstract class.
Thrown if unknown argument was supplied.
virtual void bb_interface_data_changed(Interface *interface)
BlackBoard data changed notification.
BlackBoard interface listener.
fawkes::JoystickInterface * joystick_if()
Get joystick interface.
void start(bool wait=true)
Call this method to start the thread.