Fawkes API
Fawkes Development Version
|
24 #include "acquisition_thread.h"
25 #include "act_thread.h"
26 #include "remote_bb_poster.h"
28 #include <blackboard/interface_listener.h>
29 #include <blackboard/remote.h>
30 #include <core/exceptions/system.h>
31 #include <core/threading/thread.h>
32 #include <core/threading/wait_condition.h>
33 #include <interfaces/JoystickInterface.h>
34 #include <logging/console.h>
35 #include <netcomm/fawkes/client.h>
36 #include <netcomm/fawkes/client_handler.h>
37 #include <netcomm/socket/socket.h>
38 #include <utils/system/argparser.h>
39 #include <utils/system/signal.h>
52 print_usage(
const char *program_name)
54 printf(
"Usage: %s [-h] [-r host[:port]] [-d device] [-l]\n"
55 " -h This help message\n"
56 " -r host[:port] Remote host (and optionally port) to connect to\n"
57 " -d device Joystick device to use\n"
58 " -l Start in logging mode - print data read from bb\n",
98 char * host = (
char *)
"localhost";
99 unsigned short int port = 1910;
107 warning_printed_ =
false;
109 joystick_if_->
read();
110 logger->
log_debug(
"Joystick",
"Number of Axes: %i", joystick_if_->num_axes());
111 logger->
log_debug(
"Joystick",
"Number of Buttons: %i", joystick_if_->num_buttons());
120 bbil_add_data_interface(joystick_if_);
121 bb_->register_listener(
this);
127 bb_->close(joystick_if_);
134 if (!bb_->is_alive()) {
135 if (bb_->try_aliveness_restore()) {
136 logger_->log_info(
"Joystick",
"Connection re-established, writing data");
137 warning_printed_ =
false;
142 joystick_if_->read();
143 float *axis_value = joystick_if_->axis();
144 logger_->log_info(
"Joystick",
145 "Axes: 0: %f 1: %f 2: %f 3: %f 4: %f "
155 char button_string[33];
156 button_string[32] = 0;
157 unsigned int pressed_buttons = joystick_if_->pressed_buttons();
158 for (
unsigned int i = 0; i < 32; ++i) {
159 button_string[i] = (pressed_buttons & (1 << i)) ?
'1' :
'0';
161 logger_->log_info(
"Joystick",
"Buttons: %s", button_string);
163 if (!warning_printed_) {
165 logger_->log_warn(
"Joystick",
166 "Lost connection to BlackBoard, "
167 "will try to re-establish");
168 warning_printed_ =
true;
176 waitcond_.wake_all();
187 bool warning_printed_;
212 joystick_if_(joystick_if)
216 bbil_add_message_interface(joystick_if_);
217 bb_->register_listener(
this);
223 bb_->unregister_listener(
this);
224 bbil_remove_message_interface(joystick_if_);
233 msgproc_->process_message(message);
251 main(
int argc,
char **argv)
256 if (argp.has_arg(
"h")) {
257 print_usage(argv[0]);
261 const char *joystick_device =
"/dev/input/js0";
262 if (argp.has_arg(
"d")) {
263 joystick_device = argp.arg(
"d");
268 if (argp.has_arg(
"l")) {
273 char * host = (
char *)
"localhost";
274 unsigned short int port = 1910;
275 bool free_host = argp.parse_hostport(
"r", &host, &port);
291 printf(
"Error: Unknown Argument\n\n");
292 print_usage(argv[0]);
295 printf(
"\nError: could not connect:\n%s\n", e.
what());
297 printf(
"\nError: could not open joystick device:\n%s\n", e.
what());
bool parse_hostport(const char *argn, char **host, unsigned short int *port)
Parse host:port string.
virtual void bb_interface_data_changed(Interface *interface)
BlackBoard data changed notification.
Interface for logging to stderr.
virtual bool bb_interface_message_received(Interface *interface, Message *message)
BlackBoard message received notification.
Wait until a given condition holds.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Interface for signal handling.
void read()
Read from BlackBoard into local copy.
BlackBoard interface listener.
The BlackBoard abstract class.
Thrown if unknown argument was supplied.
Joystick acqusition thread for Linux joystick API.
Log joystick data gathered via RemoteBlackBoard to console.
void handle_signal(int signum)
Signal hanlding method.
JoystickBlackBoardLogger(ArgumentParser &argp, Logger *logger)
Constructor.
static SignalHandler * register_handler(int signum, SignalHandler *handler)
Register a SignalHandler for a signal.
JoystickQuitHandler(JoystickAcquisitionThread &aqt)
Constructor.
File could not be opened.
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
JoystickBlackBoardActListener(JoystickAcquisitionThread *aqt, BlackBoard *blackboard, JoystickInterface *joystick_if, Logger *logger)
Constructor.
Wake actuator thread on incomin messages.
Fawkes library namespace.
Parse command line arguments.
Base class for all Fawkes BlackBoard interfaces.
void print_trace()
Prints trace to stderr.
virtual void handle_signal(int signal)
Signal hanlding method.
Process incoming messages.
Glue to post new data to a RemoteBlackBoard.
Simple signal handler for ffjoystick.
virtual const char * what() const
Get primary string.
~JoystickBlackBoardLogger()
Destructor.
void run()
Wait for quit signal from signal handler.
JoystickInterface Fawkes BlackBoard Interface.
~JoystickBlackBoardActListener()
Destructor.
Base class for exceptions in Fawkes.