RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_ImmersionBox.h
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
15 public vrpn_Button_Filter,
16 public vrpn_Dial
17{
18 public:
19 vrpn_ImmersionBox (const char * name,
21 const char * port,
22 int baud,
23 const int numbuttons,
24 const int numchannels,
25 const int numencoders);
26
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
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)
定义 vrpn_Button.h:66
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Dial.h:21
定义 vrpn_ImmersionBox.h:17
virtual void mainloop(void)
定义 vrpn_Analog.h:63