vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
Loading...
Searching...
No Matches
vrpn_ImmersionBox.h
Go to the documentation of this file.
1
#ifndef VRPN_IMMERSIONBOX_H
2
#define VRPN_IMMERSIONBOX_H
3
#include "
vrpn_Analog.h
"
// for vrpn_Serial_Analog
4
#include "
vrpn_Button.h
"
// for vrpn_Button_Filter
5
#include "
vrpn_Configure.h
"
// for VRPN_API
6
#include "
vrpn_Connection.h
"
// for vrpn_CONNECTION_LOW_LATENCY, etc
7
#include "
vrpn_Dial.h
"
// for vrpn_Dial
8
#include "
vrpn_Shared.h
"
// for timeval
9
#include "
vrpn_Types.h
"
// for vrpn_uint32
10
11
// Written by Rob King at Navy Research Labs. The button code works;
12
// the others are not fully implemented.
13
14
class
VRPN_API
vrpn_ImmersionBox
:
public
vrpn_Serial_Analog
,
15
public
vrpn_Button_Filter
,
16
public
vrpn_Dial
17
{
18
public
:
19
vrpn_ImmersionBox
(
const
char
* name,
20
vrpn_Connection
* c,
21
const
char
* port,
22
int
baud,
23
const
int
numbuttons,
24
const
int
numchannels,
25
const
int
numencoders);
26
27
~vrpn_ImmersionBox
() {};
28
29
// Called once through each main loop iteration to handle
30
// updates.
31
virtual
void
mainloop
(
void
);
32
33
protected
:
34
int
_status
;
35
int
_numbuttons
;
// How many buttons to open
36
int
_numchannels
;
// How many analog channels to open
37
int
_numencoders
;
// How many encoders to open
38
39
unsigned
_expected_chars
;
// How many characters to expect in the report
40
unsigned
char
_buffer
[512];
// Buffer of characters in report
41
unsigned
_bufcount
;
// How many characters we have so far
42
43
struct
timeval
timestamp
;
// Time of the last report from the device
44
45
virtual
void
clear_values
(
void
);
// Set all buttons, analogs and encoders back to 0
46
virtual
int
reset
(
void
);
// Set device back to starting config
47
virtual
int
get_report
(
void
);
// Try to read a report from the device
48
49
// send report iff changed
50
virtual
void
report_changes
(vrpn_uint32 class_of_service =
vrpn_CONNECTION_LOW_LATENCY
);
51
// send report whether or not changed
52
virtual
void
report
(vrpn_uint32 class_of_service =
vrpn_CONNECTION_LOW_LATENCY
);
53
54
// NOTE: class_of_service is only applied to vrpn_Analog
55
// values, not vrpn_Button or vrpn_Dial
56
57
private
:
58
59
#define MAX_IENCODERS 6
60
#define MAX_ICHANNELS 8
61
#define MAX_IBUTTONS 7
62
#define MAX_IBOX_STRING 32
63
64
// utility routine to sync up the baudrate
65
int
syncBaudrate (
double
seconds);
66
67
// utility to read a string from the ibox
68
int
sendIboxCommand (
char
cmd,
char
* returnString,
double
delay);
69
70
// identification strings obtained from the ibox
71
char
iname [
MAX_IBOX_STRING
];
72
char
comment[
MAX_IBOX_STRING
];
73
char
serial [
MAX_IBOX_STRING
];
74
char
id
[
MAX_IBOX_STRING
];
75
char
model [
MAX_IBOX_STRING
];
76
char
vers [
MAX_IBOX_STRING
];
77
char
parmf [
MAX_IBOX_STRING
];
78
79
80
// stores the byte sent to the ibox
81
unsigned
char
commandByte;
82
unsigned
char
dataPacketHeader;
83
int
dataRecordLength;
84
85
// makes a command byte, given the user's choice of time stamping and the number of
86
// reports desired from each type of sensor
87
// also calculates the expected number of bytes in each report that follow the packet header
88
inline
void
setupCommand (
int
useTimeStamp,
89
unsigned
int
numAnalog,
90
unsigned
int
numEncoder) {
91
commandByte = (
unsigned
char) (
92
(useTimeStamp ? 0x20 : 0) |
93
(numAnalog > 4 ? 0x0C : (numAnalog > 2 ? 0x08 : (numAnalog ? 0x04 : 0 ) ) ) |
94
(numEncoder > 3 ? 0x03 : (numEncoder > 2 ? 0x02 : (numEncoder ? 0x01 : 0 ) ) ) );
95
96
dataPacketHeader = (
unsigned
char)(commandByte | 0x80);
97
98
// packet header
99
// button status
100
// (optionally) 2 bytes of timer data
101
// 8,4,2,or 0 analog @1 byte each + byte to hold extra controller bits
102
// 6,4,2,or 0 encoders @2 bytes each
103
dataRecordLength = 1 + (useTimeStamp ? 2 : 0) +
104
(numAnalog > 4 ? 9 :(numAnalog > 2 ? 5: (numAnalog ? 3 : 0 ) ) ) +
105
(numEncoder > 4 ? 12 :(numEncoder > 2 ? 8: (numEncoder ? 4: 0 ) ) );
106
};
107
108
};
109
110
#endif
vrpn_Analog::report
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report whether something has changed or not (for servers) Optionally, tell what time to stamp ...
Definition
vrpn_Analog.C:94
vrpn_Analog::report_changes
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report only if something has changed (for servers) Optionally, tell what time to stamp the val...
Definition
vrpn_Analog.C:71
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Button_Filter::vrpn_Button_Filter
vrpn_Button_Filter(const char *, vrpn_Connection *c=NULL)
Definition
vrpn_Button.C:129
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition
vrpn_Connection.h:561
vrpn_Dial::vrpn_Dial
vrpn_Dial(const char *name, vrpn_Connection *c=NULL)
Definition
vrpn_Dial.C:8
vrpn_ImmersionBox::~vrpn_ImmersionBox
~vrpn_ImmersionBox()
Definition
vrpn_ImmersionBox.h:27
vrpn_ImmersionBox::reset
virtual int reset(void)
Definition
vrpn_ImmersionBox.C:152
vrpn_ImmersionBox::get_report
virtual int get_report(void)
Definition
vrpn_ImmersionBox.C:266
vrpn_ImmersionBox::_bufcount
unsigned _bufcount
Definition
vrpn_ImmersionBox.h:41
vrpn_ImmersionBox::clear_values
virtual void clear_values(void)
Definition
vrpn_ImmersionBox.C:132
vrpn_ImmersionBox::_status
int _status
Definition
vrpn_ImmersionBox.h:34
vrpn_ImmersionBox::_numchannels
int _numchannels
Definition
vrpn_ImmersionBox.h:36
vrpn_ImmersionBox::vrpn_ImmersionBox
vrpn_ImmersionBox(const char *name, vrpn_Connection *c, const char *port, int baud, const int numbuttons, const int numchannels, const int numencoders)
Definition
vrpn_ImmersionBox.C:78
vrpn_ImmersionBox::timestamp
struct timeval timestamp
Definition
vrpn_ImmersionBox.h:43
vrpn_ImmersionBox::_buffer
unsigned char _buffer[512]
Definition
vrpn_ImmersionBox.h:40
vrpn_ImmersionBox::_numencoders
int _numencoders
Definition
vrpn_ImmersionBox.h:37
vrpn_ImmersionBox::_numbuttons
int _numbuttons
Definition
vrpn_ImmersionBox.h:35
vrpn_ImmersionBox::_expected_chars
unsigned _expected_chars
Definition
vrpn_ImmersionBox.h:39
vrpn_Serial_Analog::vrpn_Serial_Analog
vrpn_Serial_Analog(const char *name, vrpn_Connection *connection, const char *port, int baud=9600, int bits=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE, bool rts_flow=false)
Definition
vrpn_Analog.C:124
vrpn_Analog.h
vrpn_Button.h
vrpn_Configure.h
VRPN_API
#define VRPN_API
Definition
vrpn_Configure.h:648
vrpn_Connection.h
vrpn_CONNECTION_LOW_LATENCY
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
Definition
vrpn_Connection.h:120
vrpn_Dial.h
MAX_IBOX_STRING
#define MAX_IBOX_STRING
Definition
vrpn_ImmersionBox.h:62
vrpn_Shared.h
vrpn_Types.h
vrpn_ImmersionBox.h
Generated by
1.17.0