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>
52print_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();
127 bb_->
close(joystick_if_);
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();
145 "Axes: 0: %f 1: %f 2: %f 3: %f 4: %f "
155 char button_string[33];
156 button_string[32] = 0;
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_) {
166 "Lost connection to BlackBoard, "
167 "will try to re-establish");
168 warning_printed_ =
true;
187 bool warning_printed_;
212 joystick_if_(joystick_if)
251main(
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")) {
270 SignalManager::register_handler(SIGINT, &jbl);
273 char * host = (
char *)
"localhost";
274 unsigned short int port = 1910;
275 bool free_host = argp.parse_hostport(
"r", &host, &port);
282 SignalManager::register_handler(SIGINT, &jqh);
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());
Joystick acqusition thread for Linux joystick API.
Process incoming messages.
void process_message(fawkes::Message *msg)
Process a single message.
void process()
Process message currently in the queue.
Wake actuator thread on incomin messages.
virtual bool bb_interface_message_received(Interface *interface, Message *message) noexcept
BlackBoard message received notification.
JoystickBlackBoardActListener(JoystickAcquisitionThread *aqt, BlackBoard *blackboard, JoystickInterface *joystick_if, Logger *logger)
Constructor.
~JoystickBlackBoardActListener()
Destructor.
Log joystick data gathered via RemoteBlackBoard to console.
JoystickBlackBoardLogger(ArgumentParser &argp, Logger *logger)
Constructor.
~JoystickBlackBoardLogger()
Destructor.
void run()
Wait for quit signal from signal handler.
virtual void bb_interface_data_refreshed(Interface *interface) noexcept
BlackBoard data refreshed notification.
void handle_signal(int signum)
Signal hanlding method.
Simple signal handler for ffjoystick.
virtual void handle_signal(int signal)
Signal hanlding method.
JoystickQuitHandler(JoystickAcquisitionThread &aqt)
Constructor.
Glue to post new data to a RemoteBlackBoard.
Parse command line arguments.
bool parse_hostport(const char *argn, char **host, unsigned short int *port)
Parse host:port string.
BlackBoard interface listener.
void bbil_add_message_interface(Interface *interface)
Add an interface to the message received watch list.
void bbil_remove_message_interface(Interface *interface)
Remove an interface to the message received watch list.
void bbil_add_data_interface(Interface *interface)
Add an interface to the data modification watch list.
The BlackBoard abstract class.
virtual bool is_alive() const noexcept=0
Check if the BlackBoard is still alive.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual bool try_aliveness_restore() noexcept=0
Try to restore the aliveness of the BlackBoard instance.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
virtual void close(Interface *interface)=0
Close interface.
Interface for logging to stderr.
File could not be opened.
Base class for exceptions in Fawkes.
void print_trace() noexcept
Prints trace to stderr.
virtual const char * what() const noexcept
Get primary string.
Base class for all Fawkes BlackBoard interfaces.
void read()
Read from BlackBoard into local copy.
JoystickInterface Fawkes BlackBoard Interface.
uint32_t pressed_buttons() const
Get pressed_buttons value.
uint8_t num_buttons() const
Get num_buttons value.
uint8_t num_axes() const
Get num_axes value.
float * axis() const
Get axis value.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
Interface for signal handling.
void cancel()
Cancel a thread.
Thrown if unknown argument was supplied.
Wait until a given condition holds.
void wait()
Wait for the condition forever.
void wake_all()
Wake up all waiting threads.
Fawkes library namespace.