35 const char *port,
long baud,
int enable_filtering,
int numstations,
36 const char *additional_reset_commands) :
38 do_filter(enable_filtering),
43 if (additional_reset_commands == NULL) {
74 sprintf(outstring,
"O2,11\r");
77 strlen(outstring)) == (
int)strlen(outstring)) {
94 unsigned char reset[10];
113 reset[resetLen++] = (
unsigned char) (13);
117 reset[resetLen++] = (
unsigned char) (25);
120 reset[resetLen++] =
'c';
123 sprintf(errmsg,
"Resetting the tracker (attempt %d)",
num_resets);
126 for (i = 0; i < resetLen; i++) {
131 perror(
"Isotrack: Failed writing to tracker");
141 fprintf(stderr,
"\n");
148 unsigned char scrap[80];
150 sprintf(errmsg,
"Got >=%d characters after reset",ret);
152 for (i = 0; i < ret; i++) {
153 if (isprint(scrap[i])) {
154 fprintf(stderr,
"%c",scrap[i]);
156 fprintf(stderr,
"[0x%02X]",scrap[i]);
159 fprintf(stderr,
"\n");
167 perror(
" Isotrack write failed");
173 unsigned char statusmsg[22];
180 " Got %d of 21 characters for status\n",ret);
181 VRPN_MSG_ERROR(
"Bad status report from Isotrack, retrying reset");
184 else if ( (statusmsg[0]!=
'2') ) {
186 statusmsg[
sizeof(statusmsg) - 1] =
'\0';
187 fprintf(stderr,
" Isotrack: bad status (");
188 for (i = 0; i < ret; i++) {
189 if (isprint(statusmsg[i])) {
190 fprintf(stderr,
"%c",statusmsg[i]);
192 fprintf(stderr,
"[0x%02X]",statusmsg[i]);
195 fprintf(stderr,
")\n");
196 VRPN_MSG_ERROR(
"Bad status report from Isotrack, retrying reset");
224 perror(
" Isotrack write position filter failed");
231 perror(
" Isotrack write orientation filter failed");
239 perror(
" Isotrack write failed");
243 VRPN_MSG_WARNING(
"Isotrack reset ALIGNMENT reference frame (this is good)");
248 perror(
" Isotrack write failed");
257 perror(
" Isotrack write failed");
279 printf(
" Isotrack writing extended reset commands...\n");
283 add_cmd_copy[
sizeof(add_cmd_copy)-1] =
'\0';
291 next_line = strtok(add_cmd_copy,
"\015");
292 while (next_line != NULL) {
293 if (next_line[0] ==
'*') {
294 seconds_to_wait = atoi(&next_line[1]);
295 fprintf(stderr,
" ...sleeping %d seconds\n",seconds_to_wait);
298 sprintf(string_to_send,
"%s\015", next_line);
299 fprintf(stderr,
" ...sending command: %s\n", string_to_send);
301 (
const unsigned char *)string_to_send,strlen(string_to_send));
303 next_line = strtok(next_line+strlen(next_line)+1,
"\015");
314 perror(
" Isotrack write failed");
324 perror(
" Isotrack write failed");
379 sprintf(errmsg,
"While syncing (looking for byte with high order bit set, " 425 sprintf(errmsg,
"Unexpected sync character in record");
444 for(i = 0; i<fullgroups; i++)
446 vrpn_uint8 *group = &
buffer[i * 8];
447 vrpn_uint8 high =
buffer[i * 8 + 7];
449 for(
int j=0; j<7; j++)
451 decoded[d] = *group++;
462 vrpn_uint8 *group = &
buffer[fullgroups * 8];
463 vrpn_uint8 high =
buffer[fullgroups * 8 + left - 1];
465 for(
int j=0; j<left-1; j++)
467 decoded[d] = *group++;
479 sprintf(errmsg,
"Bad sensor # (%d) in record, re-syncing",
d_sensor);
488 vrpn_uint8 *item = &decoded[3];
492 double mul = 1.6632 / 32767.;
493 float div = 1.f / 32767.f;
495 pos[0] = ( (vrpn_int8(item[1]) << 8) + item[0]) * mul; item += 2;
496 pos[1] = ( (vrpn_int8(item[1]) << 8) + item[0]) * mul; item += 2;
497 pos[2] = ( (vrpn_int8(item[1]) << 8) + item[0]) * mul; item += 2;
498 d_quat[3] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div; item += 2;
499 d_quat[0] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div; item += 2;
500 d_quat[1] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div; item += 2;
501 d_quat[2] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div;
511 char button = decoded[2];
512 if(button ==
'@' || button ==
'*')
int add_stylus_button(const char *button_device_name, int sensor)
Add a stylus (with button) to one of the sensors.
int vrpn_write_characters(int comm, const unsigned char *buffer, size_t bytes)
Write the buffer to the serial port.
void vrpn_SleepMsecs(double dMsecs)
class VRPN_API vrpn_Button_Server
const int BINARY_RECORD_SIZE
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
virtual int get_report(void)
Gets a report if one is available, returns 0 if not, 1 if complete report.
Header containing macros formerly duplicated in a lot of implementation files.
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
vrpn_Tracker_Isotrak(const char *name, vrpn_Connection *c, const char *port="/dev/ttyS1", long baud=19200, int enable_filtering=1, int numstations=vrpn_ISOTRAK_MAX_STATIONS, const char *additional_reset_commands=NULL)
The constructor is given the name of the tracker (the name of the sender it should use)...
int set_sensor_output_format(int sensor)
This routine sets the device for position + quaternion It puts a space at the end so that we can chec...
unsigned char buffer[VRPN_TRACKER_BUF_SIZE]
Generic connection class not specific to the transport mechanism.
#define VRPN_MSG_WARNING(msg)
const int vrpn_TRACKER_FAIL
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
const int vrpn_TRACKER_PARTIAL
vrpn_Connection * d_connection
Connection that this object talks to.
vrpn_Button_Server * stylus_buttons[vrpn_ISOTRAK_MAX_STATIONS]
const int vrpn_TRACKER_SYNCING
#define vrpn_gettimeofday
struct timeval reset_time
void print_latest_report(void)
virtual void reset()
Reset the tracker.
const int vrpn_ISOTRAK_MAX_STATIONS
#define VRPN_MSG_ERROR(msg)