RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Analog_Output.h
1// vrpn_Analog_Output.h
2// David Borland, September 2002
3//
4// These classes are for setting values for an analog output device. The
5// vrpn_Analog was getting overloaded by trying to have functionality for both
6// reading and writing in it. If wanting to read analog values from a device, a
7// vrpn_Analog should be used, if wanting to write analog values to a device, a
8// vrpn_Analog_Output should be used. This is similar to the Tracker/Poser
9// dichotomy.
10
11#ifndef VRPN_ANALOG_OUTPUT_H
12#define VRPN_ANALOG_OUTPUT_H
13
14#include <stddef.h> // for NULL
15
16#include "vrpn_Analog.h" // for vrpn_CHANNEL_MAX
17#include "vrpn_BaseClass.h" // for vrpn_Callback_List, etc
18#include "vrpn_Configure.h" // for VRPN_CALLBACK, VRPN_API
19#include "vrpn_Connection.h" // for vrpn_CONNECTION_RELIABLE, etc
20#include "vrpn_Shared.h" // for timeval
21#include "vrpn_Types.h" // for vrpn_int32, vrpn_float64, etc
22
23// Similar to vrpn_Analog, but messages are different
24// Members beginning with o_ are also found in vrpn_Analog, the o_ is
25// so that you can derive a class from both without getting ambiguities
26class VRPN_API vrpn_Analog_Output : public vrpn_BaseClass {
27public:
28 vrpn_Analog_Output(const char* name, vrpn_Connection* c = NULL);
29
30 // Print the status of the analog output device
31 void o_print(void);
32
33 vrpn_int32 getNumChannels() const { return o_num_channel; }
34
35protected:
36 vrpn_float64 o_channel[vrpn_CHANNEL_MAX];
37 vrpn_int32 o_num_channel;
38 struct timeval o_timestamp;
39 vrpn_int32 request_m_id; //< Request to change message from client
40 vrpn_int32 request_channels_m_id; //< Request to change channels message
41 // from client
42 vrpn_int32 report_num_channels_m_id; //< Report of the number of active
43 // channels, from the server
44 vrpn_int32 got_connection_m_id; //< new-connection notification
45 int o_status;
46
47 virtual int register_types(void);
48};
49
50// A *Sample* Analog output server. Use this, or derive your own server
51// from vrpn_Analog_Output with this as a guide. You can remove the
52// user-level callback code (both the type before this class and the
53// list and the handler register/deregister) if the server is controlling
54// a device directly.
55
57public:
58 vrpn_Analog_Output_Server(const char* name, vrpn_Connection* c,
59 vrpn_int32 numChannels = vrpn_CHANNEL_MAX);
60 virtual ~vrpn_Analog_Output_Server(void);
61
62 virtual void mainloop() { server_mainloop(); }
63
67 vrpn_int32 setNumChannels(vrpn_int32 sizeRequested);
68
70 const vrpn_float64* o_channels(void) const { return o_channel; };
71
72protected:
73 virtual bool report_num_channels(
74 vrpn_uint32 class_of_service = vrpn_CONNECTION_RELIABLE);
75 virtual vrpn_int32 encode_num_channels_to(char* buf, vrpn_int32 num);
76
81 static int VRPN_CALLBACK
83
88 static int VRPN_CALLBACK
90
93 static int VRPN_CALLBACK
95};
96
97// A more complicated analog server that provides a
98// user routine to handle a change in analog values. This is called when
99// the analog callback is called (when a message from its counterpart
100// across the connection arrives). This callback is called whenever
101// EITHER type of change message arrives (either a single-channel change
102// or a multiple-channel change.
103
104typedef struct _vrpn_ANALOGOUTPUTCB {
105 struct timeval msg_time; // Timestamp of analog data
106 vrpn_int32 num_channel; // how many channels
107 const vrpn_float64* channel; // analog values (pointer to channels)
109
110typedef void(VRPN_CALLBACK* vrpn_ANALOGOUTPUTCHANGEHANDLER)(
111 void* userdata, const vrpn_ANALOGOUTPUTCB info);
112
115public:
117 const char* name, vrpn_Connection* c,
118 vrpn_int32 numChannels = vrpn_CHANNEL_MAX);
120
121 // (un)Register a callback handler to handle analog value change.
122 // These will be called whenever EITHER type of change message is
123 // received, either a single channel or multiple channels. This is
124 // useful for applications that "have a" server, rather than derive
125 // from the server.
126 virtual int register_change_handler(void* userdata,
127 vrpn_ANALOGOUTPUTCHANGEHANDLER handler)
128 {
129 return d_callback_list.register_handler(userdata, handler);
130 };
131 virtual int
132 unregister_change_handler(void* userdata,
133 vrpn_ANALOGOUTPUTCHANGEHANDLER handler)
134 {
135 return d_callback_list.unregister_handler(userdata, handler);
136 }
137
138protected:
143 static int VRPN_CALLBACK
145
149};
150
151// Open an analog output device that is on the other end of a connection
152// and send updates to it. This is the type of analog output device
153// that user code will deal with.
155public:
156 // The name of the analog device to connect to
157 // Optional argument to be used when the Remote should listen on
158 // a connection that is already open.
159 vrpn_Analog_Output_Remote(const char* name, vrpn_Connection* c = NULL);
160 virtual ~vrpn_Analog_Output_Remote(void);
161
162 // This routine calls the mainloop of the connection it's on
163 virtual void mainloop();
164
165 // Request the analog to change its value to the one specified.
166 // Returns false on failure.
167 virtual bool request_change_channel_value(
168 unsigned int chan, vrpn_float64 val,
169 vrpn_uint32 class_of_service = vrpn_CONNECTION_RELIABLE);
170
171 // Request the analog to change values all at once. If more values are
172 // given
173 // than we have channels, the extra values are discarded. If less values
174 // are
175 // given than we have channels, the extra channels are set to 0.
176 // Returns false on failure
177 virtual bool request_change_channels(
178 int num, vrpn_float64* vals,
179 vrpn_uint32 class_of_service = vrpn_CONNECTION_RELIABLE);
180
181protected:
182 // How we hear about the number of active channels
183 static int VRPN_CALLBACK
184 handle_report_num_channels(void* userdata, vrpn_HANDLERPARAM p);
185
186 // Routines used to send requests from the client
187 virtual vrpn_int32 encode_change_to(char* buf, vrpn_int32 chan,
188 vrpn_float64 val);
189 virtual vrpn_int32 encode_change_channels_to(char* buf, vrpn_int32 num,
190 vrpn_float64* vals);
191};
192
193#endif
定义 vrpn_Analog_Output.h:114
vrpn_Callback_List< vrpn_ANALOGOUTPUTCB > d_callback_list
定义 vrpn_Analog_Output.h:148
static int VRPN_CALLBACK handle_change_message(void *userdata, vrpn_HANDLERPARAM p)
定义 vrpn_Analog_Output.h:154
定义 vrpn_Analog_Output.h:56
static int VRPN_CALLBACK handle_request_message(void *userdata, vrpn_HANDLERPARAM p)
const vrpn_float64 * o_channels(void) const
Exposes an array of values for the user to read from.
定义 vrpn_Analog_Output.h:70
virtual void mainloop()
定义 vrpn_Analog_Output.h:62
static int VRPN_CALLBACK handle_request_channels_message(void *userdata, vrpn_HANDLERPARAM p)
static int VRPN_CALLBACK handle_got_connection(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 setNumChannels(vrpn_int32 sizeRequested)
定义 vrpn_Analog_Output.h:26
virtual int register_types(void)
void server_mainloop(void)
定义 vrpn_BaseClass.h:310
定义 vrpn_BaseClass.h:361
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Analog_Output.h:104
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41