vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_OSVRHackerDevKit.C
Go to the documentation of this file.
1 
12 
14 #include "vrpn_BaseClass.h" // for ::vrpn_TEXT_NORMAL, etc
15 #include "vrpn_FixedPoint.h" // for vrpn::FixedPoint
16 #include <quat.h> // for Q_W, Q_X, etc.
17 
18 #include <cstring> // for memset
19 #include <stdexcept> // for logic_error
20 
22 
23 #if defined(VRPN_USE_HID)
24 
25 // USB vendor and product IDs for the models we support
26 static const vrpn_uint16 vrpn_OSVR_VENDOR = 0x1532;
27 static const vrpn_uint16 vrpn_OSVR_HACKER_DEV_KIT_HMD = 0x0b00;
28 
30 static const vrpn_uint16 vrpn_OSVR_ALT_VENDOR = 0x03EB;
31 static const vrpn_uint16 vrpn_OSVR_ALT_HACKER_DEV_KIT_HMD = 0x2421;
32 
34  vrpn_Connection *c)
35  : vrpn_Tracker(name, c)
37  new vrpn_HidProductAcceptor(vrpn_OSVR_VENDOR,
38  vrpn_OSVR_HACKER_DEV_KIT_HMD),
39  new vrpn_HidProductAcceptor(vrpn_OSVR_ALT_VENDOR,
40  vrpn_OSVR_ALT_HACKER_DEV_KIT_HMD)))
41  , _wasConnected(false)
42 {
43  vrpn_Tracker::num_sensors = 1; // only orientation
44 
45  // Initialize the state
46  std::memset(d_quat, 0, sizeof(d_quat));
47  d_quat[Q_W] = 1.0;
48 
49  // Set the timestamp
51 }
52 
54 {
55  delete _acceptor;
56 }
57 
59  vrpn_uint8 *buffer)
60 {
61  if (bytes != 32) {
63  << "Received a report " << bytes
64  << " in length, but expected it to be 32 bytes. Discarding.";
65  return;
66  }
67 
68  vrpn_uint8 version = vrpn_unbuffer_from_little_endian<vrpn_uint8>(buffer);
70  vrpn_uint8 msg_seq = vrpn_unbuffer_from_little_endian<vrpn_uint8>(buffer);
71 
72  // Signed, 16-bit, fixed-point numbers in Q1.14 format.
73  typedef vrpn::FixedPoint<1, 14> FixedPointValue;
74  d_quat[Q_X] =
75  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
76  .get<vrpn_float64>();
77  d_quat[Q_Y] =
78  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
79  .get<vrpn_float64>();
80  d_quat[Q_Z] =
81  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
82  .get<vrpn_float64>();
83  d_quat[Q_W] =
84  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
85  .get<vrpn_float64>();
86 
88  char msgbuf[512];
89  int len = vrpn_Tracker::encode_to(msgbuf);
91  msgbuf, vrpn_CONNECTION_LOW_LATENCY)) {
92  fprintf(
93  stderr,
94  "vrpn_Tracker_OSVRHackerDevKit: cannot write message: tossing\n");
95  }
96 }
97 
99 {
101 
102  update();
103 
104  if (connected() && !_wasConnected) {
105  send_text_message("Successfully connected to OSVR Hacker Dev Kit HMD.",
107  }
109 
110  server_mainloop();
111 }
112 
113 #endif
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
virtual void mainloop()
Standard VRPN mainloop method.
Accepts any device with the given vendor and product IDs.
header for OSVR Hacker Dev Kit
Generic connection class not specific to the transport mechanism.
#define VRPN_SUPPRESS_EMPTY_OBJECT_WARNING()
vrpn_Tracker_OSVRHackerDevKit(const char *name, vrpn_Connection *c=NULL)
Constructor.
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
Accepts devices meeting at least one of two criteria. NOT SHORT-CIRCUIT. Another demonstration of acc...
vrpn_Connection * d_connection
Connection that this object talks to.
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
vrpn_int32 num_sensors
Definition: vrpn_Tracker.h:114
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
virtual int encode_to(char *buf)
Definition: vrpn_Tracker.C:533
vrpn_HidAcceptor * _acceptor
This is the HidAcceptor we use when reconnecting.
virtual ~vrpn_Tracker_OSVRHackerDevKit()
Destructor.
bool _wasConnected
Flag indicating whether we were connected last time through the mainloop. Used to send a "normal"-sev...
Header allowing use of a output stream-style method of sending text messages from devices...
#define vrpn_gettimeofday
Definition: vrpn_Shared.h:89
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
struct timeval _timestamp
Timestamp updated during mainloop()
A fixed-point value class.
vrpn_int32 d_sender_id
Sender ID registered with the connection.
struct timeval timestamp
Definition: vrpn_Tracker.h:100
vrpn_float64 d_quat[4]
Definition: vrpn_Tracker.h:95
virtual bool connected() const
Returns true iff the last device I/O succeeded.
void on_data_received(std::size_t bytes, vrpn_uint8 *buffer)
Extracts the sensor values from each report.
vrpn_int32 position_m_id
Definition: vrpn_Tracker.h:80