32 const char *port,
long baud,
int enable_filtering,
int numstations,
33 const char *additional_reset_commands,
int is900_timestamps) :
35 do_filter(enable_filtering),
38 do_is900_timestamps(is900_timestamps)
43 if (additional_reset_commands == NULL) {
76 fprintf(stderr,
"vrpn_Tracker_Fastrak::~vrpn_Tracker_Fastrak(): delete failed\n");
94 const char *timestring;
95 const char *buttonstring;
96 const char *analogstring;
115 sprintf(outstring,
"O%d,2,11%s%s%s,0\015", sensor+1, timestring,
116 buttonstring, analogstring);
118 strlen(outstring)) == (
int)strlen(outstring)) {
175 unsigned char reset[10];
195 reset[resetLen++] = (
unsigned char) (13);
198 reset[resetLen++] =
'Y';
201 reset[resetLen++] =
't';
213 reset[resetLen++] = (
unsigned char) (25);
215 reset[resetLen++] =
'c';
217 sprintf(errmsg,
"Resetting the tracker (attempt %d)",
num_resets);
219 for (i = 0; i < resetLen; i++) {
224 perror(
"Fastrak: Failed writing to tracker");
237 fprintf(stderr,
"\n");
244 unsigned char scrap[80];
246 sprintf(errmsg,
"Got >=%d characters after reset",ret);
248 for (i = 0; i < ret; i++) {
249 if (isprint(scrap[i])) {
250 fprintf(stderr,
"%c",scrap[i]);
252 fprintf(stderr,
"[0x%02X]",scrap[i]);
255 fprintf(stderr,
"\n");
263 perror(
" Fastrak write failed");
269 unsigned char statusmsg[56];
275 if ( (ret != 55) && (ret != 54) ) {
277 " Got %d of 55 characters for status (54 expected for IS900)\n",ret);
279 if ( (statusmsg[0]!=
'2') || (statusmsg[ret-1]!=(
char)(10)) ) {
281 statusmsg[55] =
'\0';
282 fprintf(stderr,
" Fastrak: status is (");
283 for (i = 0; i < ret; i++) {
284 if (isprint(statusmsg[i])) {
285 fprintf(stderr,
"%c",statusmsg[i]);
287 fprintf(stderr,
"[0x%02X]",statusmsg[i]);
290 fprintf(stderr,
"\n)\n");
315 sprintf(outstring,
"e1,0\r");
317 strlen(outstring)) == (
int)strlen(outstring)) {
332 (
const unsigned char *)
"x0.2,0.2,0.8,0.8\015", 17) == 17) {
335 perror(
" Fastrak write position filter failed");
340 (
const unsigned char *)
"v0.2,0.2,0.8,0.8\015", 17) == 17) {
343 perror(
" Fastrak write orientation filter failed");
362 printf(
" Fastrak writing extended reset commands...\n");
366 add_cmd_copy[
sizeof(add_cmd_copy)-1] =
'\0';
374 next_line = strtok(add_cmd_copy,
"\015");
375 while (next_line != NULL) {
376 if (next_line[0] ==
'*') {
377 seconds_to_wait = atoi(&next_line[1]);
378 fprintf(stderr,
" ...sleeping %d seconds\n",seconds_to_wait);
381 sprintf(string_to_send,
"%s\015", next_line);
382 fprintf(stderr,
" ...sending command: %s\n", string_to_send);
384 (
const unsigned char *)string_to_send,strlen(string_to_send));
386 next_line = strtok(next_line+strlen(next_line)+1,
"\015");
399 perror(
" Fastrak write failed");
403 fprintf(stderr,
" Fastrak set to continuous mode\n");
413 char clear_timestamp_cmd[] =
"MT\015MZ\015";
418 strlen(clear_timestamp_cmd)) != (
int)strlen(clear_timestamp_cmd)) {
461 unsigned char *bufptr;
479 sprintf(errmsg,
"While syncing (looking for '0', "
514 sprintf(errmsg,
"Bad sensor # (%d) in record, re-syncing",
d_sensor);
576 VRPN_MSG_INFO(
"No space character at end of report, re-syncing");
605 d_quat[Q_W] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);
606 d_quat[Q_X] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);
607 d_quat[Q_Y] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);
608 d_quat[Q_Z] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);
618 struct timeval delta_time;
621 vrpn_float32 read_time = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);
624 delta_time.tv_sec = (long)(read_time / 1000);
625 read_time -= delta_time.tv_sec * 1000;
626 delta_time.tv_usec = (long)(read_time * 1000);
644 value=*(++bufptr)-
'0';
648 value = ( (*bufptr) >> i) & 1;
668 unsigned char raw_lr = *bufptr;
670 unsigned char raw_tb = *bufptr;
764 double c0Min,
double c0Low,
double c0Hi,
double c0Max,
765 double c1Min,
double c1Low,
double c1Hi,
double c1Max)
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Makes public the protected base class function.
virtual void mainloop()
For this server, the user must normally call report() or report_changes() directly....
vrpn_int32 setNumChannels(vrpn_int32 sizeRequested)
Sets the size of the array; returns the size actually set. (May be clamped to vrpn_CHANNEL_MAX) This ...
vrpn_Connection * d_connection
Connection that this object talks to.
int setChannelValue(int channel, double value)
This method should be used to set the value of a channel. It will be scaled and clipped as described ...
int setClipValues(int channel, double min, double lowzero, double highzero, double max)
Set the clipping values for the specified channel. min maps to -1, values between lowzero and highzer...
Generic connection class not specific to the transport mechanism.
int set_sensor_output_format(int sensor)
Augments the basic Fastrak format to include IS900 features if needed.
struct timeval reset_time
struct timeval is900_zerotime
virtual int get_report(void)
Gets a report if one is available, returns 0 if not, 1 if complete report.
int report_length(int sensor)
Augments the basic Fastrak report length to include IS900 features if needed.
virtual void reset()
Reset the tracker.
int add_fastrak_stylus_button(const char *button_device_name, int sensor, int numbuttons=1)
vrpn_Clipping_Analog_Server * is900_analogs[vrpn_FASTRAK_MAX_STATIONS]
vrpn_Button_Server * is900_buttons[vrpn_FASTRAK_MAX_STATIONS]
int add_is900_analog(const char *analog_device_name, int sensor, double c0Min=-1, double c0Low=0, double c0Hi=0, double c0Max=1, double c1Min=-1, double c1Low=0, double c1Hi=0, double c1Max=1)
Add the analog part of an IS900 joystick device to one of the sensors This allows configuration of an...
vrpn_Tracker_Fastrak(const char *name, vrpn_Connection *c, const char *port="/dev/ttyS1", long baud=19200, int enable_filtering=1, int numstations=vrpn_FASTRAK_MAX_STATIONS, const char *additional_reset_commands=NULL, int is900_timestamps=0)
The constructor is given the name of the tracker (the name of the sender it should use),...
int add_is900_button(const char *button_device_name, int sensor, int numbuttons=5)
Add an IS900 button device to one of the sensors This allows configuration of an InterSense IS-900.
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_INFO(msg)
#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_drain_output_buffer(int comm)
Wait until all of the characters in the output buffer are sent, then return.
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)
timeval vrpn_TimevalSum(const timeval &tv1, const timeval &tv2)
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
#define VRPN_INCHES_TO_METERS
const int vrpn_TRACKER_FAIL
const int vrpn_TRACKER_SYNCING
const int vrpn_TRACKER_PARTIAL
const int vrpn_TRACKER_AWAITING_STATION
class VRPN_API vrpn_Clipping_Analog_Server
const int vrpn_FASTRAK_MAX_STATIONS
class VRPN_API vrpn_Button_Server