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");
290 next_line = strtok(add_cmd_copy,
"\015");
291 while (next_line != NULL) {
292 if (next_line[0] ==
'*') {
293 seconds_to_wait = atoi(&next_line[1]);
294 fprintf(stderr,
" ...sleeping %d seconds\n",seconds_to_wait);
297 sprintf(string_to_send,
"%s\015", next_line);
298 fprintf(stderr,
" ...sending command: %s\n", string_to_send);
300 (
const unsigned char *)string_to_send,strlen(string_to_send));
302 next_line = strtok(next_line+strlen(next_line)+1,
"\015");
313 perror(
" Isotrack write failed");
323 perror(
" Isotrack write failed");
378 sprintf(errmsg,
"While syncing (looking for byte with high order bit set, "
424 sprintf(errmsg,
"Unexpected sync character in record");
443 for(i = 0; i<fullgroups; i++)
445 vrpn_uint8 *group = &
buffer[i * 8];
446 vrpn_uint8 high =
buffer[i * 8 + 7];
448 for(
int j=0; j<7; j++)
450 decoded[d] = *group++;
461 vrpn_uint8 *group = &
buffer[fullgroups * 8];
462 vrpn_uint8 high =
buffer[fullgroups * 8 + left - 1];
464 for(
int j=0; j<left-1; j++)
466 decoded[d] = *group++;
478 sprintf(errmsg,
"Bad sensor # (%d) in record, re-syncing",
d_sensor);
487 vrpn_uint8 *item = &decoded[3];
491 double mul = 1.6632 / 32767.;
492 float div = 1.f / 32767.f;
494 pos[0] = ( (vrpn_int8(item[1]) << 8) + item[0]) * mul; item += 2;
495 pos[1] = ( (vrpn_int8(item[1]) << 8) + item[0]) * mul; item += 2;
496 pos[2] = ( (vrpn_int8(item[1]) << 8) + item[0]) * mul; item += 2;
497 d_quat[3] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div; item += 2;
498 d_quat[0] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div; item += 2;
499 d_quat[1] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div; item += 2;
500 d_quat[2] = ( (vrpn_int8(item[1]) << 8) + item[0]) * div;
510 char button = decoded[2];
511 if(button ==
'@' || button ==
'*')
vrpn_Connection * d_connection
Connection that this object talks to.
Generic connection class not specific to the transport mechanism.
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...
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),...
struct timeval reset_time
virtual int get_report(void)
Gets a report if one is available, returns 0 if not, 1 if complete report.
vrpn_Button_Server * stylus_buttons[vrpn_ISOTRAK_MAX_STATIONS]
virtual void reset()
Reset the tracker.
int add_stylus_button(const char *button_device_name, int sensor)
Add a stylus (with button) to one of the sensors.
unsigned char buffer[VRPN_TRACKER_BUF_SIZE]
void print_latest_report(void)
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
Header containing macros formerly duplicated in a lot of implementation files.
#define VRPN_MSG_ERROR(msg)
#define VRPN_MSG_WARNING(msg)
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...
void vrpn_SleepMsecs(double dMilliSecs)
void vrpn_strcpy(char(&to)[charCount], const char *pSrc)
Null-terminated-string copy function that both guarantees not to overrun the buffer and guarantees th...
#define vrpn_gettimeofday
const int vrpn_TRACKER_FAIL
const int vrpn_TRACKER_SYNCING
const int vrpn_TRACKER_PARTIAL
const int BINARY_RECORD_SIZE
const int vrpn_ISOTRAK_MAX_STATIONS
class VRPN_API vrpn_Button_Server