16 const char** rigidBodyNDIRomFileNames) :
vrpn_Tracker(name,c)
24 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: Can't open serial port: %s\n",port);
27 printf(
"connected to NDI Polaris at default 9600 baud on device:%s.\n",port);
31 printf(
"DEBUG: Reseting com port");
74 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: tool %s didn't init properly!\n",rigidBodyNDIRomFileNames[t]);
116 int TXResponseStrIndex=2;
117 bool gotAtLeastOneReport=
false;
124 gotAtLeastOneReport=
true;
142 TXResponseStrIndex++;
144 TXResponseStrIndex++;
148 return(gotAtLeastOneReport);
160 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: cannot write message: tossing\n");
223 FILE* fptr=fopen(filename,
"rb");
225 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: can't open NDI .rom file %s\n",filename);
230 fseek(fptr , 0 , SEEK_END);
231 long int fileSizeInBytes = ftell(fptr);
235 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: file is %ld bytes long - which is larger than expected NDI ROM file size of %d bytes.\n",
242 unsigned char* rawBytesFromRomFile;
243 try { rawBytesFromRomFile =
new unsigned char[fileSizeInBytes]; }
245 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: Out of memory!\n");
251 size_t result = fread (rawBytesFromRomFile,1,fileSizeInBytes,fptr);
252 if (result != (
unsigned int) fileSizeInBytes) {
253 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: error while reading .rom file!\n");
255 delete [] rawBytesFromRomFile;
257 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris::convertBinaryFileToAsciiEncodedHex(): delete failed\n");
267 asciiEncodedHexStr[i]=
'_';
270 for (byteIndex=0; byteIndex<fileSizeInBytes; byteIndex++) {
271 sprintf(&(asciiEncodedHexStr[byteIndex*2]),
"%02x ",rawBytesFromRomFile[byteIndex]);
278 int paddedFileSizeInBytes=fileSizeInBytes+numOfBytesToPadRemaining;
280 while (numOfBytesToPadRemaining>0) {
281 asciiEncodedHexStr[byteIndex*2]=
'0';
282 asciiEncodedHexStr[byteIndex*2+1]=
'0';
284 numOfBytesToPadRemaining--;
287 asciiEncodedHexStr[byteIndex*2]=
'\0';
291 delete [] rawBytesFromRomFile;
293 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris::convertBinaryFileToAsciiEncodedHex(): delete failed\n");
297 return paddedFileSizeInBytes;
307 if (strIndexPtr==NULL){
309 sscanf((
char*) str,
"%2u",&intVal);
311 sscanf((
char*) &(str[*strIndexPtr]),
"%2u",&intVal);
325 sscanf((
char*) &(str[*strIndexPtr]),
"%6d",&intVal);
327 return (intVal/10000.0f);
338 sscanf((
char*) &(str[*strIndexPtr]),
"%7d",&intVal);
340 return (intVal/100.0f);
376 for (
int chunkIndex=0; chunkIndex<numOfChunks; chunkIndex++) {
382 sprintf(commandStr,
"PVWR %02u%04x%s",portHandleNum, NDIAddress,chunk);
390 sprintf(commandStr,
"PINIT %02u",portHandleNum);
398 sprintf(commandStr,
"PENA %02uD",portHandleNum);
405 return(portHandleNum);
409 printf(
"vrpn_Tracker_NDI_Polaris: Switching NDI to higher baud rate, and then reopening com port at higher rate...");
vrpn_Connection * d_connection
Connection that this object talks to.
vrpn_int32 d_sender_id
Sender ID registered with the connection.
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
virtual void send_report(void)
void switchToHigherBaudRate(const char *port)
@ MAX_NDI_ROM_FILE_SIZE_IN_BYTES
~vrpn_Tracker_NDI_Polaris()
virtual int get_report(void)
int convertBinaryFileToAsciiEncodedHex(const char *filename, char *asciiEncodedHexStr)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
int setupOneTool(const char *NDIToolRomFilename)
@ MAX_NDI_RESPONSE_LENGTH
unsigned int parse2CharIntFromNDIResponse(unsigned char *str, int *strIndexPtr=NULL)
void sendCommand(const char *commandString)
float parse6CharFloatFromNDIResponse(unsigned char *str, int *strIndexPtr)
unsigned char latestResponseStr[MAX_NDI_RESPONSE_LENGTH]
vrpn_Tracker_NDI_Polaris(const char *name, vrpn_Connection *c, const char *port, int numOfRigidBodies, const char **rigidBodyNDIRomFileNames)
The constructor is given the name of the tracker (the name of the sender it should use),...
float parse7CharFloatFromNDIResponse(unsigned char *str, int *strIndexPtr)
virtual int encode_to(char *buf)
vrpn_Tracker(const char *name, vrpn_Connection *c=NULL, const char *tracker_cfg_file_name=NULL)
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
int vrpn_write_characters(int comm, const unsigned char *buffer, size_t bytes)
Write the buffer to the serial port.
int vrpn_set_rts(int comm)
int vrpn_close_commport(int comm)
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)
int vrpn_flush_output_buffer(int comm)
Throw out any characters (do not send) within the output buffer.
int vrpn_clear_rts(int comm)
int vrpn_open_commport(const char *portname, long baud, int charsize, vrpn_SER_PARITY parity, bool rts_flow)
Open a serial port, given its name and baud rate.
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
class VRPN_API vrpn_Connection