RflySimSDK
v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
simulink
vrpn
vrpn_Dial.h
1
// vrpn_Dial.h
2
// This implements a Dial class. A dial is an object that spins,
3
// possibly without bound. It returns the fraction of a revolution that
4
// it has turned as its message type.
5
6
#ifndef VRPN_DIAL_H
7
#define VRPN_DIAL_H
8
9
const
int
vrpn_DIAL_MAX = 128;
10
11
#include <stddef.h>
// for NULL
12
13
#include "
vrpn_BaseClass.h
"
// for vrpn_Callback_List, etc
14
#include "vrpn_Configure.h"
// for VRPN_API, VRPN_CALLBACK
15
#include "vrpn_Shared.h"
// for timeval
16
#include "vrpn_Types.h"
// for vrpn_float64, vrpn_int32
17
18
class
VRPN_API
vrpn_Connection
;
19
struct
vrpn_HANDLERPARAM
;
20
21
class
VRPN_API
vrpn_Dial
:
public
vrpn_BaseClass
{
22
public
:
23
vrpn_Dial
(
const
char
*name,
vrpn_Connection
*c = NULL);
24
25
protected
:
26
vrpn_float64 dials[vrpn_DIAL_MAX];
27
vrpn_int32 num_dials;
28
struct
timeval timestamp;
29
vrpn_int32 change_m_id;
// change message id
30
31
virtual
int
register_types
(
void
);
32
virtual
vrpn_int32 encode_to(
char
*buf, vrpn_int32 buflen, vrpn_int32 dial,
33
vrpn_float64 delta);
34
virtual
void
report_changes(
void
);
// send report iff changed
35
virtual
void
report(
void
);
// send report
36
};
37
38
//----------------------------------------------------------
39
// Example server for an array of dials
40
// This will generate an array of dials that all spin at the same
41
// rate (revolutions/second), and which send reports at a different rate
42
// (updates/second). A real server would send reports whenever it saw
43
// dials changing, and would not have the spin_rate or update_rate parameters.
44
// This server can be used for testing to make sure a client is
45
// working correctly, and to ensure that a connection to a remote server
46
// is working (by running the example server with the name of the device that
47
// the real server would use).
48
49
class
VRPN_API
vrpn_Dial_Example_Server
:
public
vrpn_Dial
{
50
public
:
51
vrpn_Dial_Example_Server
(
const
char
*name,
vrpn_Connection
*c,
52
vrpn_int32 numdials = 1,
53
vrpn_float64 spin_rate = 1.0,
54
vrpn_float64 update_rate = 10.0);
55
virtual
void
mainloop
();
56
57
protected
:
58
vrpn_float64 _spin_rate;
// The rate at which to spin (revolutions/sec)
59
vrpn_float64 _update_rate;
// The rate at which to update (reports/sec)
60
// The dials[] array within the parent is used for the values
61
// The num_dials within the parent is used
62
// The timestamp field within the parent structure is used for timing
63
// The report_changes() or report() functions within the parent are used
64
};
65
66
//----------------------------------------------------------
67
//************** Users deal with the following *************
68
69
// User routine to handle a change in dial values. This is called when
70
// the dial callback is called (when a message from its counterpart
71
// across the connetion arrives).
72
73
typedef
struct
_vrpn_DIALCB
{
74
struct
timeval msg_time;
// Timestamp when change happened
75
vrpn_int32 dial;
// which dial changed
76
vrpn_float64 change;
// Fraction of a revolution it changed
77
}
vrpn_DIALCB
;
78
79
typedef
void(VRPN_CALLBACK *vrpn_DIALCHANGEHANDLER)(
void
*userdata,
80
const
vrpn_DIALCB
info);
81
82
// Open a dial device that is on the other end of a connection
83
// and handle updates from it. This is the type of device
84
// that user code will deal with.
85
86
class
VRPN_API
vrpn_Dial_Remote
:
public
vrpn_Dial
{
87
public
:
88
// The name of the device to connect to.
89
// Optional argument to be used when the Remote MUST listen on
90
// a connection that is already open.
91
vrpn_Dial_Remote
(
const
char
*name,
vrpn_Connection
*c = NULL);
92
~vrpn_Dial_Remote
();
93
94
// This routine calls the mainloop of the connection it's on
95
virtual
void
mainloop
();
96
97
// (un)Register a callback handler to handle dial updates
98
virtual
int
register_change_handler(
void
*userdata,
99
vrpn_DIALCHANGEHANDLER handler)
100
{
101
return
d_callback_list.register_handler(userdata, handler);
102
};
103
virtual
int
unregister_change_handler(
void
*userdata,
104
vrpn_DIALCHANGEHANDLER handler)
105
{
106
return
d_callback_list.unregister_handler(userdata, handler);
107
}
108
109
protected
:
110
vrpn_Callback_List<vrpn_DIALCB>
d_callback_list;
111
112
static
int
VRPN_CALLBACK
113
handle_change_message(
void
*userdata,
vrpn_HANDLERPARAM
p);
114
};
115
116
#endif
vrpn_BaseClass
定义
vrpn_BaseClass.h:310
vrpn_Callback_List
定义
vrpn_BaseClass.h:361
vrpn_Connection
Generic connection class not specific to the transport mechanism.
定义
vrpn_Connection.h:562
vrpn_Dial_Example_Server
定义
vrpn_Dial.h:49
vrpn_Dial_Example_Server::mainloop
virtual void mainloop()
vrpn_Dial_Remote
定义
vrpn_Dial.h:86
vrpn_Dial_Remote::mainloop
virtual void mainloop()
vrpn_Dial
定义
vrpn_Dial.h:21
vrpn_Dial::register_types
virtual int register_types(void)
_vrpn_DIALCB
定义
vrpn_Dial.h:73
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
定义
vrpn_Connection.h:41
vrpn_BaseClass.h
制作者
1.11.0