vrpn  07.33
Virtual Reality Peripheral Network
vrpn_YEI_3Space.h
Go to the documentation of this file.
1 #ifndef VRPN_YEI_3SPACE_H
2 #define VRPN_YEI_3SPACE_H
3 
4 #include "quat.h"
5 #include "vrpn_Tracker.h"
6 #include "vrpn_Analog.h"
7 #include "vrpn_Button.h"
8 
12  : public vrpn_Tracker_Server
13  , public vrpn_Analog
14  , public vrpn_Button_Filter
15 {
16 public:
32  vrpn_YEI_3Space (const char * name,
33  vrpn_Connection * c,
34  bool calibrate_gyros_on_setup = false,
35  bool tare_on_setup = false,
36  double frames_per_second = 50,
37  double red_LED_color = 0,
38  double green_LED_color = 0,
39  double blue_LED_color = 0,
40  int LED_mode = 1,
41  const char *reset_commands[] = NULL);
42 
44  virtual ~vrpn_YEI_3Space();
45 
47  virtual void mainloop ();
48 
49 protected:
54  void init(bool calibrate_gyros_on_setup
55  , bool tare_on_setup
56  , double frames_per_second
57  , double red_LED_color
58  , double green_LED_color
59  , double blue_LED_color
60  , int LED_mode);
61 
63  virtual void flush_input(void) = 0;
64 
65  // A list of ASCII commands that are sent to the device after
66  // the other reset commands have been sent, each time the device
67  // is reset. This enables arbitrary configuration.
68  char **d_reset_commands; //< Commands to send on reset
69  int d_reset_command_count; //< How many reset commands
70 
71  // Status and handlers for different states
72  int d_status; //< What are we currently up to?
73  virtual int reset(void); //< Set device back to starting config
74  virtual bool get_report(void) = 0; //< Try to read and handle a report from the device
75  virtual void handle_report(unsigned char *report); //< Parse and handle a complete streaming report
76 
77  double d_frames_per_second; //< How many frames/second do we want?
78  int d_LED_mode; //< LED mode we read from the device.
79  vrpn_float32 d_LED_color[3]; //< LED color we read from the device.
80 
83  virtual bool send_binary_command(const unsigned char *cmd, int len) = 0;
84 
88  virtual bool send_ascii_command(const char *cmd) = 0;
89 
93  virtual bool receive_LED_mode_response(struct timeval *timeout = NULL) = 0;
94 
98  virtual bool receive_LED_values_response(struct timeval *timeout = NULL) = 0;
99 
100  unsigned char d_buffer[128]; //< Buffer to read reports into.
101  unsigned d_expected_characters; //< How many characters we are expecting
102  unsigned d_characters_read; //< How many characters we've read so far
103 
104  struct timeval timestamp; //< Time of the last report from the device
105 
107  virtual void report_changes
108  (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
110  virtual void report
111  (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
112 };
113 
117  : public vrpn_YEI_3Space
118 {
119 public:
137  vrpn_YEI_3Space_Sensor (const char * name,
138  vrpn_Connection * c,
139  const char * port,
140  int baud = 115200,
141  bool calibrate_gyros_on_setup = false,
142  bool tare_on_setup = false,
143  double frames_per_second = 50,
144  double red_LED_color = 0,
145  double green_LED_color = 0,
146  double blue_LED_color = 0,
147  int LED_mode = 1,
148  const char *reset_commands[] = NULL);
149 
151  virtual ~vrpn_YEI_3Space_Sensor();
152 
153 protected:
154  int d_serial_fd; //< Serial port to read from.
155 
157  virtual void flush_input(void);
158 
159  virtual bool get_report(void); //< Try to read and handle a report from the device
160 
163  bool send_binary_command(const unsigned char *cmd, int len);
164 
168  bool send_ascii_command(const char *cmd);
169 
173  bool receive_LED_mode_response(struct timeval *timeout = NULL);
174 
178  bool receive_LED_values_response(struct timeval *timeout = NULL);
179 };
180 
184  : public vrpn_YEI_3Space
185 {
186 public:
210  vrpn_YEI_3Space_Sensor_Wireless (const char * name,
211  vrpn_Connection * c,
212  int logical_id,
213  int serial_number,
214  const char * port,
215  int baud = 115200,
216  bool calibrate_gyros_on_setup = false,
217  bool tare_on_setup = false,
218  double frames_per_second = 50,
219  double red_LED_color = 0,
220  double green_LED_color = 0,
221  double blue_LED_color = 0,
222  int LED_mode = 1,
223  const char *reset_commands[] = NULL);
224 
245  vrpn_YEI_3Space_Sensor_Wireless (const char * name,
246  vrpn_Connection * c,
247  int logical_id,
248  int serial_number,
249  int serial_file_descriptor,
250  bool calibrate_gyros_on_setup = false,
251  bool tare_on_setup = false,
252  double frames_per_second = 50,
253  double red_LED_color = 0,
254  double green_LED_color = 0,
255  double blue_LED_color = 0,
256  int LED_mode = 1,
257  const char *reset_commands[] = NULL);
258 
261 
264  int get_serial_file_descriptor(void) const { return d_serial_fd; }
265 
266 protected:
267  bool d_i_am_first; //< Records whether I'm the first sensor (so close the port)
268  int d_serial_fd; //< Serial port to read from.
269  vrpn_uint8 d_logical_id; //< Which logical ID are we assigned to on the dongle?
270 
272  virtual bool configure_dongle(void);
273 
275  virtual bool set_logical_id(vrpn_uint8 logical_id, vrpn_int32 serial_number);
276 
278  virtual void flush_input(void);
279 
282  virtual bool get_report(void);
283 
287  bool send_binary_command_to_dongle(const unsigned char *cmd, int len);
288 
291  bool send_binary_command(const unsigned char *cmd, int len);
292 
296  bool send_ascii_command(const char *cmd);
297 
301  bool receive_LED_mode_response(struct timeval *timeout = NULL);
302 
306  bool receive_LED_values_response(struct timeval *timeout = NULL);
307 };
308 
309 #endif
double d_frames_per_second
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report only if something has changed (for servers) Optionally, tell what time to stamp the val...
Definition: vrpn_Analog.C:71
char ** d_reset_commands
virtual void flush_input(void)=0
Flush any incoming characters in the communications channel.
unsigned d_expected_characters
virtual bool receive_LED_values_response(struct timeval *timeout=NULL)=0
Read and parse the response to an LED-values request command. NULL timeout pointer means wait forever...
Base class with routines for YEI 3Space units.
virtual bool send_ascii_command(const char *cmd)=0
Put a &#39;:&#39; character at the front and &#39; &#39; at the end and then send the resulting command as an ASCII c...
Generic connection class not specific to the transport mechanism.
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report whether something has changed or not (for servers) Optionally, tell what time to stamp ...
Definition: vrpn_Analog.C:94
Class to support reading data from a wired YEI 3Space unit.
virtual bool get_report(void)=0
#define VRPN_API
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
virtual int init(void)
Initialize things that the constructor can&#39;t. Returns 0 on success, -1 on failure.
unsigned d_characters_read
virtual bool receive_LED_mode_response(struct timeval *timeout=NULL)=0
Read and parse the response to an LED-state request command. NULL timeout pointer means wait forever...
int get_serial_file_descriptor(void) const
Reports the serial_fd that was opened, so that additional sensors that use the same wireless dongle c...
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:65
Class to support reading data from a wireless YEI 3Space unit.
virtual bool send_binary_command(const unsigned char *cmd, int len)=0
Compute the CRC for the message, append it, and send message. Returns true on success, false on failure.