vrpn 07.35
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_Analog.h
Go to the documentation of this file.
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);
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
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
64public:
65 vrpn_Serial_Analog(const char *name, vrpn_Connection *connection,
66 const char *port, int baud = 9600, int bits = 8,
68 bool rts_flow = false);
70
71protected:
73 char portname[1024];
75 unsigned char buffer[1024];
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
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
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
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,
194 {
195 return d_callback_list.register_handler(userdata, handler);
196 };
197 virtual int unregister_change_handler(void *userdata,
199 {
200 return d_callback_list.unregister_handler(userdata, handler);
201 }
202
203protected:
205
206 static int VRPN_CALLBACK
207 handle_change_message(void *userdata, vrpn_HANDLERPARAM p);
208};
209
210#endif
vrpn_Callback_List< vrpn_ANALOGCB > d_callback_list
Definition: vrpn_Analog.h:204
virtual int unregister_change_handler(void *userdata, vrpn_ANALOGCHANGEHANDLER handler)
Definition: vrpn_Analog.h:197
virtual int register_change_handler(void *userdata, vrpn_ANALOGCHANGEHANDLER handler)
Definition: vrpn_Analog.h:192
vrpn_float64 * channels(void)
Exposes an array of values for the user to write into.
Definition: vrpn_Analog.h:117
virtual void mainloop()
For this server, the user must normally call report() or report_changes() directly....
Definition: vrpn_Analog.h:114
vrpn_int32 num_channel
Definition: vrpn_Analog.h:40
vrpn_int32 channel_m_id
Definition: vrpn_Analog.h:42
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
virtual int register_types(void)=0
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
Analog server that can scale and clip its range to -1..1.
Definition: vrpn_Analog.h:130
Generic connection class not specific to the transport mechanism.
int read_available_characters(char *buffer, int bytes)
vrpn_int32 num_channel
Definition: vrpn_Analog.h:170
This structure is what is passed to a vrpn_Connection message callback.
const int vrpn_ANALOG_FAIL
Definition: vrpn_Analog.h:23
const struct timeval vrpn_ANALOG_NOW
Definition: vrpn_Analog.h:26
const int vrpn_ANALOG_REPORT_READY
Definition: vrpn_Analog.h:20
void(VRPN_CALLBACK * vrpn_ANALOGCHANGEHANDLER)(void *userdata, const vrpn_ANALOGCB info)
Definition: vrpn_Analog.h:174
const int vrpn_ANALOG_RESETTING
Definition: vrpn_Analog.h:22
#define vrpn_CHANNEL_MAX
Definition: vrpn_Analog.h:16
const int vrpn_ANALOG_PARTIAL
Definition: vrpn_Analog.h:21
const int vrpn_ANALOG_SYNCING
Definition: vrpn_Analog.h:19
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
#define VRPN_API
#define VRPN_CALLBACK
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
vrpn_SER_PARITY
Definition: vrpn_Serial.h:15
@ vrpn_SER_PARITY_NONE
Definition: vrpn_Serial.h:16
#define min(x, y)
Definition: vrpn_WiiMote.C:47