RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_YEI_3Space.h
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
9/** @brief Base class with routines for YEI 3Space units.
10*/
11class VRPN_API vrpn_YEI_3Space
12 : public vrpn_Tracker_Server
13 , public vrpn_Analog
14 , public vrpn_Button_Filter
15{
16public:
17 /** @brief Constructor.
18 @param name Name for the device
19 @param c Connection to use.
20 @param reset_commands - Array of pointers to commands, NULL for end.
21 These will be sent after other commands whenever the tracker
22 is reset. This will be copied; the caller is responsible for
23 freeing any storage after calling the constructor.
24 */
25 vrpn_YEI_3Space (const char * name,
27 double frames_per_second = 50,
28 const char *reset_commands[] = NULL);
29
30 /// Destructor.
32
33 /// Called once through each main loop iteration to handle updates.
34 virtual void mainloop ();
35
36protected:
37 /// Initialization that would normally happen in the constructor, but
38 /// we need to wait for the derived classes to open a communications port
39 /// before we can do this. Derived classes should call this at the end
40 /// of their constructors.
41 void init(bool calibrate_gyros_on_setup
42 , bool tare_on_setup
43 , double red_LED_color
44 , double green_LED_color
45 , double blue_LED_color
46 , int LED_mode);
47
48 /// Flush any incoming characters in the communications channel.
49 virtual void flush_input(void) = 0;
50
51 // A list of ASCII commands that are sent to the device after
52 // the other reset commands have been sent, each time the device
53 // is reset. This enables arbitrary configuration.
54 char **d_reset_commands; //< Commands to send on reset
55 int d_reset_command_count; //< How many reset commands
56
57 // Status and handlers for different states
58 int d_status; //< What are we currently up to?
59 virtual int reset(void); //< Set device back to starting config
60 virtual bool get_report(void) = 0; //< Try to read and handle a report from the device
61 virtual void handle_report(unsigned char *report); //< Parse and handle a complete streaming report
62
63 double d_frames_per_second; //< How many frames/second do we want?
64 int d_LED_mode; //< LED mode we read from the device.
65 vrpn_float32 d_LED_color[3]; //< LED color we read from the device.
66
67 /// Compute the CRC for the message, append it, and send message.
68 /// Returns true on success, false on failure.
69 virtual bool send_binary_command(const unsigned char *cmd, int len) = 0;
70
71 /// Put a ':' character at the front and '\n' at the end and then
72 /// send the resulting command as an ASCII command.
73 /// Returns true on success, false on failure.
74 virtual bool send_ascii_command(const char *cmd) = 0;
75
76 /// Read and parse the response to an LED-state request command.
77 /// NULL timeout pointer means wait forever.
78 /// Returns true on success and false on failure.
79 virtual bool receive_LED_mode_response(struct timeval *timeout = NULL) = 0;
80
81 /// Read and parse the response to an LED-values request command.
82 /// NULL timeout pointer means wait forever.
83 /// Returns true on success and false on failure.
84 virtual bool receive_LED_values_response(struct timeval *timeout = NULL) = 0;
85
86 unsigned char d_buffer[128]; //< Buffer to read reports into.
87 unsigned d_expected_characters; //< How many characters we are expecting
88 unsigned d_characters_read; //< How many characters we've read so far
89
90 struct timeval timestamp; //< Time of the last report from the device
91
92 /// send report iff changed
93 virtual void report_changes
94 (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
95 /// send report whether or not changed
96 virtual void report
97 (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
98};
99
100/** @brief Class to support reading data from a wired YEI 3Space unit.
101*/
103 : public vrpn_YEI_3Space
104{
105public:
106 /** @brief Constructor.
107 @param name Name for the device
108 @param c Connection to use.
109 @param port serial port to connect to
110 @param baud Baud rate - 115200 is default.
111 @param calibrate_gyros_on_setup - true to cause this to happen
112 @param tare_on_setup - true to cause this to happen (usually manufacturing-time operation!)
113 @param frames_per_second - How many frames/second to read
114 @param red_LED_color - brightness of LED (0-1)
115 @param green_LED_color - brightness of LED (0-1)
116 @param blue_LED_color - brightness of LED (0-1)
117 @param LED_state - 0 = standard, 1 = static
118 @param reset_commands - Array of pointers to commands, NULL for end.
119 These will be sent after other commands whenever the tracker
120 is reset. This will be copied; the caller is responsible for
121 freeing any storage after calling the constructor.
122 */
123 vrpn_YEI_3Space_Sensor (const char * name,
124 vrpn_Connection * c,
125 const char * port,
126 int baud = 115200,
127 bool calibrate_gyros_on_setup = false,
128 bool tare_on_setup = false,
129 double frames_per_second = 50,
130 double red_LED_color = 0,
131 double green_LED_color = 0,
132 double blue_LED_color = 0,
133 int LED_mode = 1,
134 const char *reset_commands[] = NULL);
135
136 /// Destructor.
138
139protected:
140 int d_serial_fd; //< Serial port to read from.
141
142 /// Flush any incoming characters in the communications channel.
143 virtual void flush_input(void);
144
145 virtual bool get_report(void); //< Try to read and handle a report from the device
146
147 /// Compute the CRC for the message, append it, and send message.
148 /// Returns true on success, false on failure.
149 bool send_binary_command(const unsigned char *cmd, int len);
150
151 /// Put a ':' character at the front and '\n' at the end and then
152 /// send the resulting command as an ASCII command.
153 /// Returns true on success, false on failure.
154 bool send_ascii_command(const char *cmd);
155
156 /// Read and parse the response to an LED-state request command.
157 /// NULL timeout pointer means wait forever.
158 /// Returns true on success and false on failure.
159 bool receive_LED_mode_response(struct timeval *timeout = NULL);
160
161 /// Read and parse the response to an LED-values request command.
162 /// NULL timeout pointer means wait forever.
163 /// Returns true on success and false on failure.
164 bool receive_LED_values_response(struct timeval *timeout = NULL);
165};
166
167/** @brief Class to support reading data from a wireless YEI 3Space unit.
168*/
170 : public vrpn_YEI_3Space
171{
172public:
173 /** @brief Constructor for the first device, which will open the serial
174 port and configure the dongle. The first device on a wireless
175 dongle should call this constructor. The later ones should call
176 the constructor that takes the serial_file_descriptor argument
177 after querying the first for that descriptor.
178 @param name Name for the device
179 @param c Connection to use.
180 @param logical_id Which logical ID to use on the wireless unit.
181 @param port serial port to connect to
182 @param baud Baud rate - 115200 is default.
183 @param calibrate_gyros_on_setup - true to cause this to happen
184 @param tare_on_setup - true to cause this to happen (usually manufacturing-time operation!)
185 @param frames_per_second - How many frames/second to read
186 @param red_LED_color - brightness of LED (0-1)
187 @param green_LED_color - brightness of LED (0-1)
188 @param blue_LED_color - brightness of LED (0-1)
189 @param LED_state - 0 = standard, 1 = static
190 @param reset_commands - Array of pointers to commands, NULL for end.
191 These will be sent after other commands whenever the tracker
192 is reset. This will be copied; the caller is responsible for
193 freeing any storage after calling the constructor.
194 */
196 vrpn_Connection * c,
197 int logical_id,
198 const char * port,
199 int baud = 115200,
200 bool calibrate_gyros_on_setup = false,
201 bool tare_on_setup = false,
202 double frames_per_second = 50,
203 double red_LED_color = 0,
204 double green_LED_color = 0,
205 double blue_LED_color = 0,
206 int LED_mode = 1,
207 const char *reset_commands[] = NULL);
208
209 /** @brief Constructor for a follow-on device, once a wireless unit has already
210 been opened on a given dongle. The serial_file_descriptor argument
211 should be found by querying the first device.
212 @param name Name for the device
213 @param c Connection to use.
214 @param logical_id Which logical ID to use on the wireless unit.
215 @param serial_file_descriptor: Pre-opened serial descriptor to use.
216 @param calibrate_gyros_on_setup - true to cause this to happen
217 @param tare_on_setup - true to cause this to happen (usually manufacturing-time operation!)
218 @param frames_per_second - How many frames/second to read
219 @param red_LED_color - brightness of LED (0-1)
220 @param green_LED_color - brightness of LED (0-1)
221 @param blue_LED_color - brightness of LED (0-1)
222 @param LED_state - 0 = standard, 1 = static
223 @param reset_commands - Array of pointers to commands, NULL for end.
224 These will be sent after other commands whenever the tracker
225 is reset. This will be copied; the caller is responsible for
226 freeing any storage after calling the constructor.
227 */
229 vrpn_Connection * c,
230 int logical_id,
231 int serial_file_descriptor,
232 bool calibrate_gyros_on_setup = false,
233 bool tare_on_setup = false,
234 double frames_per_second = 50,
235 double red_LED_color = 0,
236 double green_LED_color = 0,
237 double blue_LED_color = 0,
238 int LED_mode = 1,
239 const char *reset_commands[] = NULL);
240
241 /// Destructor.
243
244 /// Reports the serial_fd that was opened, so that additional
245 /// sensors that use the same wireless dongle can be opened.
246 int get_serial_file_descriptor(void) const { return d_serial_fd; }
247
248protected:
249 bool d_i_am_first; //< Records whether I'm the first sensor (so close the port)
250 int d_serial_fd; //< Serial port to read from.
251 vrpn_uint8 d_logical_id; //< Which logical ID are we assigned to on the dongle?
252
253 /// Configure the dongle (called if we are the first one)
254 virtual bool configure_dongle(void);
255
256 /// Insert our serial number into the specified slot.
257 virtual bool set_logical_id(vrpn_uint8 logical_id, vrpn_int32 serial_number);
258
259 /// Flush any incoming characters in the communications channel.
260 virtual void flush_input(void);
261
262 /// Get and handle a report from the device if one is available. Return true
263 /// if one was available, false if not.
264 virtual bool get_report(void);
265
266 /// Compute the CRC for the message, append it, and send message
267 /// to the dongle directly (not a wireless command).
268 /// Returns true on success, false on failure.
269 bool send_binary_command_to_dongle(const unsigned char *cmd, int len);
270
271 /// Compute the CRC for the message, append it, and send message.
272 /// Returns true on success, false on failure.
273 bool send_binary_command(const unsigned char *cmd, int len);
274
275 /// Put a ':' character at the front and '\n' at the end and then
276 /// send the resulting command as an ASCII command.
277 /// Returns true on success, false on failure.
278 bool send_ascii_command(const char *cmd);
279
280 /// Read and parse the response to an LED-state request command.
281 /// NULL timeout pointer means wait forever.
282 /// Returns true on success and false on failure.
283 bool receive_LED_mode_response(struct timeval *timeout = NULL);
284
285 /// Read and parse the response to an LED-values request command.
286 /// NULL timeout pointer means wait forever.
287 /// Returns true on success and false on failure.
288 bool receive_LED_values_response(struct timeval *timeout = NULL);
289};
290
291#endif
定义 vrpn_Analog.h:28
定义 vrpn_Button.h:66
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Tracker.h:273
Class to support reading data from a wireless YEI 3Space unit.
定义 vrpn_YEI_3Space.h:171
virtual bool set_logical_id(vrpn_uint8 logical_id, vrpn_int32 serial_number)
Insert our serial number into the specified slot.
int get_serial_file_descriptor(void) const
定义 vrpn_YEI_3Space.h:246
virtual void flush_input(void)
Flush any incoming characters in the communications channel.
virtual ~vrpn_YEI_3Space_Sensor_Wireless()
Destructor.
virtual bool get_report(void)
vrpn_YEI_3Space_Sensor_Wireless(const char *name, vrpn_Connection *c, int logical_id, const char *port, int baud=115200, bool calibrate_gyros_on_setup=false, bool tare_on_setup=false, double frames_per_second=50, double red_LED_color=0, double green_LED_color=0, double blue_LED_color=0, int LED_mode=1, const char *reset_commands[]=NULL)
Constructor for the first device, which will open the serial port and configure the dongle....
bool send_ascii_command(const char *cmd)
vrpn_YEI_3Space_Sensor_Wireless(const char *name, vrpn_Connection *c, int logical_id, int serial_file_descriptor, bool calibrate_gyros_on_setup=false, bool tare_on_setup=false, double frames_per_second=50, double red_LED_color=0, double green_LED_color=0, double blue_LED_color=0, int LED_mode=1, const char *reset_commands[]=NULL)
Constructor for a follow-on device, once a wireless unit has already been opened on a given dongle....
bool send_binary_command(const unsigned char *cmd, int len)
bool send_binary_command_to_dongle(const unsigned char *cmd, int len)
bool receive_LED_values_response(struct timeval *timeout=NULL)
bool receive_LED_mode_response(struct timeval *timeout=NULL)
virtual bool configure_dongle(void)
Configure the dongle (called if we are the first one)
Class to support reading data from a wired YEI 3Space unit.
定义 vrpn_YEI_3Space.h:104
virtual void flush_input(void)
Flush any incoming characters in the communications channel.
bool send_ascii_command(const char *cmd)
bool send_binary_command(const unsigned char *cmd, int len)
bool receive_LED_values_response(struct timeval *timeout=NULL)
virtual ~vrpn_YEI_3Space_Sensor()
Destructor.
bool receive_LED_mode_response(struct timeval *timeout=NULL)
vrpn_YEI_3Space_Sensor(const char *name, vrpn_Connection *c, const char *port, int baud=115200, bool calibrate_gyros_on_setup=false, bool tare_on_setup=false, double frames_per_second=50, double red_LED_color=0, double green_LED_color=0, double blue_LED_color=0, int LED_mode=1, const char *reset_commands[]=NULL)
Constructor.
Base class with routines for YEI 3Space units.
定义 vrpn_YEI_3Space.h:15
virtual bool receive_LED_mode_response(struct timeval *timeout=NULL)=0
virtual bool send_binary_command(const unsigned char *cmd, int len)=0
virtual bool receive_LED_values_response(struct timeval *timeout=NULL)=0
virtual ~vrpn_YEI_3Space()
Destructor.
virtual void mainloop()
Called once through each main loop iteration to handle updates.
virtual bool send_ascii_command(const char *cmd)=0
vrpn_YEI_3Space(const char *name, vrpn_Connection *c, double frames_per_second=50, const char *reset_commands[]=NULL)
Constructor.
virtual void flush_input(void)=0
Flush any incoming characters in the communications channel.
void init(bool calibrate_gyros_on_setup, bool tare_on_setup, double red_LED_color, double green_LED_color, double blue_LED_color, int LED_mode)
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report iff changed