30static const unsigned char CMD_GETNAME =
static_cast<unsigned char>(0xC8);
31static const unsigned char CMD_GETPRID =
static_cast<unsigned char>(0xC9);
32static const unsigned char CMD_GETMODL =
static_cast<unsigned char>(0xCA);
33static const unsigned char CMD_GETSERN =
static_cast<unsigned char>(0xCB);
34static const unsigned char CMD_GETCOMM =
static_cast<unsigned char>(0xCC);
35static const unsigned char CMD_GETPERF =
static_cast<unsigned char>(0xCD);
36static const unsigned char CMD_GETVERS =
static_cast<unsigned char>(0xCE);
48#define STATUS_RESETTING (-1)
49#define STATUS_SYNCING (0)
50#define STATUS_READING (1)
57#define MAX_TIME_INTERVAL (2000000)
59static void pause (
double delay) {
62 unsigned long interval = (long) floor(1000000.0 * delay);
64 struct timeval start, now;
83 const int numchannels,
84 const int numencoders):
88 _numbuttons(numbuttons),
89 _numchannels(numchannels),
90 _numencoders(numencoders)
126 dataRecordLength = 0;
166 if (syncBaudrate (10.0)) {
167 printf(
"vrpn_ImmersionBox found\n");
172 if (0 == sendIboxCommand((
char) CMD_GETNAME, (
char *) &iname, .1)) {
173 fprintf(stderr,
"problems with ibox command CMD_GETNAME\n");
176 if (0 == sendIboxCommand((
char) CMD_GETPRID, (
char *) &
id, .1)) {
177 fprintf(stderr,
"problems with ibox command CMD_GETPRID\n");
180 if (0 == sendIboxCommand((
char) CMD_GETMODL, (
char *) &model, .1)){
181 fprintf(stderr,
"problems with ibox command CMD_GETMODL\n");
184 if (0 == sendIboxCommand((
char) CMD_GETSERN, (
char *) &serial, .1)){
185 fprintf(stderr,
"problems with ibox command CMD_GETSERN\n");
188 if (0 == sendIboxCommand((
char) CMD_GETCOMM, (
char *) &comment, .1)){
189 fprintf(stderr,
"problems with ibox command CMD_GETCOMM\n");
192 if (0 == sendIboxCommand((
char) CMD_GETPERF, (
char *) &parmf, .1)){
193 fprintf(stderr,
"problems with ibox command CMD_GETPERF\n");
196 if (0 == sendIboxCommand((
char) CMD_GETVERS, (
char *) &vers, .1)){
197 fprintf(stderr,
"problems with ibox command CMD_GETVERS\n");
202 printf(
"%s\n%s\n%s\n%s\n%s\n%s\n", iname,
id, serial, comment, parmf, vers);
211 unsigned char command[26] =
"";
214 command[2] = (
unsigned char) 10;
215 command[3] = commandByte;
217 for (
int i = 4; i < 25;i++)
226 fprintf(stderr,
"vrpnImmersionBox::reset: could not write command\n");
235 if (result <= 0 || command[0] != 0xcf) {
236 fprintf(stderr,
"vrpnImmersionBox::reset: no command echo\n");
243 printf(
"ImmersionBox reset complete.\n");
270 unsigned int buttonBits = 0;
272 struct timeval timeout;
274 timeout.tv_usec = 100000;
281 if (
buffer[0] != dataPacketHeader) {
299 (
unsigned char *) responseString,
303 if (result < dataRecordLength) {
309 buttonBits = responseString[0];
318 cerr <<
"left button pressed " << endl;
386 struct timeval current_time;
389 fprintf(stderr,
"Tracker failed to read... current_time=%ld:%ld, timestamp=%ld:%ld\n",
390 current_time.tv_sec,
static_cast<long>(current_time.tv_usec),
399 fprintf(stderr,
"vrpn_ImmersionBox: Unknown mode (internal error)\n");
408int vrpn_ImmersionBox::sendIboxCommand (
char cmd,
char * returnString,
double delay)
410 struct timeval timeout;
412 timeout.tv_usec = 15000;
423 if (NULL == returnString)
436 if (!(responseString[0] & 0x80))
440 if ((responseString[0] & 0x7f) != (cmd & 0x7f))
444 strcpy (returnString, &responseString[1]);
452int vrpn_ImmersionBox::syncBaudrate (
double seconds) {
454 struct timeval miniDelay;
455 miniDelay.tv_sec = 0;
456 miniDelay.tv_usec = 50000;
458 unsigned long maxDelay = 1000000L * (long) seconds;
459 struct timeval start_time;
463 unsigned char responseString[8];
464 const unsigned char * matchString = (
unsigned char *)
S_INITIALIZE ;
474 struct timeval current_time;
478 fprintf(stderr,
"vrpn_ImmersionBox::syncBaudrate timeout expired: %lf secs \n", seconds);
484 fprintf(stderr,
"vrpn_ImmersionBox::syncBaudrate could not write to serial port\n");
497 for (index = 0; index < 4; index++) {
499 if (responseString[index] != matchString[index])
512 matchString = (
const unsigned char *)
"IBOX";
520 for (index = 0; index < 4; index++) {
522 if (responseString[index] != matchString[index])
vrpn_float64 last[vrpn_CHANNEL_MAX]
vrpn_float64 channel[vrpn_CHANNEL_MAX]
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 ...
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...
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
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.
Generic connection class not specific to the transport mechanism.
virtual void report_changes(void)
vrpn_float64 dials[vrpn_DIAL_MAX]
virtual void report(void)
virtual int get_report(void)
virtual void clear_values(void)
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_ImmersionBox(const char *name, vrpn_Connection *c, const char *port, int baud, const int numbuttons, const int numchannels, const int numencoders)
unsigned char buffer[1024]
#define MAX_TIME_INTERVAL
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
int vrpn_write_characters(int comm, const unsigned char *buffer, size_t bytes)
Write the buffer to the serial port.
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
#define vrpn_gettimeofday