RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Analog.h
1#ifndef VRPN_ANALOG_H
2#define VRPN_ANALOG_H
3
4#include <stddef.h> // for NULL
5
6#include "vrpn_BaseClass.h" // for vrpn_Callback_List, etc
7#include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK
8#include "vrpn_Connection.h" // for vrpn_CONNECTION_LOW_LATENCY, etc
9#include "vrpn_Shared.h" // for timeval
10#include "vrpn_Types.h" // for vrpn_int32, vrpn_float64, etc
11
12#ifndef VRPN_CLIENT_ONLY
13#include "vrpn_Serial.h" // for ::vrpn_SER_PARITY_NONE, etc
14#endif
15
16#define vrpn_CHANNEL_MAX 128
17
18// analog status flags
19const int vrpn_ANALOG_SYNCING = (2);
20const int vrpn_ANALOG_REPORT_READY = (1);
21const int vrpn_ANALOG_PARTIAL = (0);
22const int vrpn_ANALOG_RESETTING = (-1);
23const int vrpn_ANALOG_FAIL = (-2);
24
25// Analog time value meaning "go find out what time it is right now"
26const struct timeval vrpn_ANALOG_NOW = {0, 0};
27
28class VRPN_API vrpn_Analog : public vrpn_BaseClass {
29public:
30 vrpn_Analog(const char *name, vrpn_Connection *c = NULL);
31
32 // Print the status of the analog device
33 void print(void);
34
35 vrpn_int32 getNumChannels(void) const;
36
37protected:
38 vrpn_float64 channel[vrpn_CHANNEL_MAX];
39 vrpn_float64 last[vrpn_CHANNEL_MAX];
40 vrpn_int32 num_channel;
41 struct timeval timestamp;
42 vrpn_int32 channel_m_id; //< channel message id (message from server)
43 int status;
44
45 virtual int register_types(void);
46
47 //------------------------------------------------------------------
48 // Routines used to send data from the server
49 virtual vrpn_int32 encode_to(char *buf);
52 virtual void
53 report_changes(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY,
54 const struct timeval time = vrpn_ANALOG_NOW);
57 virtual void
58 report(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY,
59 const struct timeval time = vrpn_ANALOG_NOW);
60};
61
62#ifndef VRPN_CLIENT_ONLY
63class VRPN_API vrpn_Serial_Analog : public vrpn_Analog {
64public:
65 vrpn_Serial_Analog(const char *name, vrpn_Connection *connection,
66 const char *port, int baud = 9600, int bits = 8,
67 vrpn_SER_PARITY parity = vrpn_SER_PARITY_NONE,
68 bool rts_flow = false);
70
71protected:
72 int serial_fd;
73 char portname[1024];
74 int baudrate;
75 unsigned char buffer[1024];
76 int bufcounter;
77
78 int read_available_characters(char *buffer, int bytes);
79};
80#endif
81
82// vrpn_Analog_Server
83// Tom Hudson, March 1999
84//
85// A *Sample* Analog server. Use this or derive your own from vrpn_Analog with
86// this as a guide.
87//
88// Write whatever values you want into channels(), then call report()
89// or report_changes(). (Original spec only called for report_changes(),
90// but vrpn_Analog's assumption that "no new data = same data" doesn't
91// match the BLT stripchart assumption of "no intervening data = ramp".
92//
93// For a sample application, see server_src/sample_analog.C
94
95class VRPN_API vrpn_Analog_Server : public vrpn_Analog {
96
97public:
98 vrpn_Analog_Server(const char *name, vrpn_Connection *c,
99 vrpn_int32 numChannels = vrpn_CHANNEL_MAX);
100
102 virtual void
103 report_changes(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY,
104 const struct timeval time = vrpn_ANALOG_NOW);
105
107 virtual void
108 report(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY,
109 const struct timeval time = vrpn_ANALOG_NOW);
110
114 virtual void mainloop() { server_mainloop(); };
115
117 vrpn_float64 *channels(void) { return channel; }
118
122 vrpn_int32 setNumChannels(vrpn_int32 sizeRequested);
123};
124
126// This is useful for joysticks, to allow them to be centered and
127// scaled to cover the whole range. Rather than writing directly
128// into the channels array, call the setChannel() method.
129
131public:
132 vrpn_Clipping_Analog_Server(const char *name, vrpn_Connection *c,
133 vrpn_int32 numChannels = vrpn_CHANNEL_MAX);
134
142 int setClipValues(int channel, double min, double lowzero, double highzero,
143 double max);
144
148 int setChannelValue(int channel, double value);
149
150protected:
151 typedef struct {
152 double minimum_val; // Value mapped to -1
153 double lower_zero; // Minimum value mapped to 0
154 double upper_zero; // Maximum value mapped to 0
155 double maximum_val; // Value mapped to 1
157
158 clipvals_struct clipvals[vrpn_CHANNEL_MAX];
159};
160
161//----------------------------------------------------------
162//************** Users deal with the following *************
163
164// User routine to handle a change in analog values. This is called when
165// the analog callback is called (when a message from its counterpart
166// across the connection arrives).
167
168typedef struct _vrpn_ANALOGCB {
169 struct timeval msg_time; // Timestamp of analog data
170 vrpn_int32 num_channel; // how many channels
171 vrpn_float64 channel[vrpn_CHANNEL_MAX]; // analog values
173
174typedef void(VRPN_CALLBACK *vrpn_ANALOGCHANGEHANDLER)(void *userdata,
175 const vrpn_ANALOGCB info);
176
177// Open an analog device that is on the other end of a connection
178// and handle updates from it. This is the type of analog device
179// that user code will deal with.
180
181class VRPN_API vrpn_Analog_Remote : public vrpn_Analog {
182public:
183 // The name of the analog device to connect to
184 // Optional argument to be used when the Remote should listen on
185 // a connection that is already open.
186 vrpn_Analog_Remote(const char *name, vrpn_Connection *c = NULL);
187
188 // This routine calls the mainloop of the connection it's on
189 virtual void mainloop();
190
191 // (un)Register a callback handler to handle analog value change
192 virtual int register_change_handler(void *userdata,
193 vrpn_ANALOGCHANGEHANDLER handler)
194 {
195 return d_callback_list.register_handler(userdata, handler);
196 };
197 virtual int unregister_change_handler(void *userdata,
198 vrpn_ANALOGCHANGEHANDLER handler)
199 {
200 return d_callback_list.unregister_handler(userdata, handler);
201 }
202
203protected:
204 vrpn_Callback_List<vrpn_ANALOGCB> d_callback_list;
205
206 static int VRPN_CALLBACK
207 handle_change_message(void *userdata, vrpn_HANDLERPARAM p);
208};
209
210#endif
定义 vrpn_Analog.h:181
virtual void mainloop()
定义 vrpn_Analog.h:95
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Makes public the protected base class function
vrpn_float64 * channels(void)
Exposes an array of values for the user to write into.
定义 vrpn_Analog.h:117
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Makes public the protected base class function
virtual void mainloop()
定义 vrpn_Analog.h:114
vrpn_int32 setNumChannels(vrpn_int32 sizeRequested)
定义 vrpn_Analog.h:28
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
virtual int register_types(void)
void server_mainloop(void)
定义 vrpn_BaseClass.h:310
定义 vrpn_BaseClass.h:361
Analog server that can scale and clip its range to -1..1.
定义 vrpn_Analog.h:130
int setChannelValue(int channel, double value)
int setClipValues(int channel, double min, double lowzero, double highzero, double max)
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Analog.h:63
定义 vrpn_Analog.h:168
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...