16 const char** rigidBodyNDIRomFileNames) :
vrpn_Tracker(name,c)
27 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: Can't open serial port: %s\n",port);
30 printf(
"connected to NDI Polaris at default 9600 baud on device:%s.\n",port);
34 printf(
"DEBUG: Reseting com port");
77 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: tool %s didn't init properly!\n",rigidBodyNDIRomFileNames[t]);
119 int TXResponseStrIndex=2;
120 bool gotAtLeastOneReport=
false;
127 gotAtLeastOneReport=
true;
145 TXResponseStrIndex++;
147 TXResponseStrIndex++;
151 return(gotAtLeastOneReport);
163 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: cannot write message: tossing\n");
227 FILE* fptr=fopen(filename,
"rb");
229 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: can't open NDI .rom file %s\n",filename);
234 fseek(fptr , 0 , SEEK_END);
235 long int fileSizeInBytes = ftell(fptr);
239 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: file is %ld bytes long - which is larger than expected NDI ROM file size of %d bytes.\n",
245 unsigned char* rawBytesFromRomFile = (
unsigned char*)
new unsigned char[fileSizeInBytes];
248 size_t result = fread (rawBytesFromRomFile,1,fileSizeInBytes,fptr);
249 if (result != (
unsigned int) fileSizeInBytes) {
250 fprintf(stderr,
"vrpn_Tracker_NDI_Polaris: error while reading .rom file!\n");
259 asciiEncodedHexStr[i]=
'_';
262 for (byteIndex=0; byteIndex<fileSizeInBytes; byteIndex++) {
263 sprintf(&(asciiEncodedHexStr[byteIndex*2]),
"%02x ",rawBytesFromRomFile[byteIndex]);
270 int paddedFileSizeInBytes=fileSizeInBytes+numOfBytesToPadRemaining;
272 while (numOfBytesToPadRemaining>0) {
273 asciiEncodedHexStr[byteIndex*2]=
'0';
274 asciiEncodedHexStr[byteIndex*2+1]=
'0';
276 numOfBytesToPadRemaining--;
279 asciiEncodedHexStr[byteIndex*2]=
'\0';
282 delete (rawBytesFromRomFile);
284 return paddedFileSizeInBytes;
294 if (strIndexPtr==NULL){
296 sscanf((
char*) str,
"%2u",&intVal);
298 sscanf((
char*) &(str[*strIndexPtr]),
"%2u",&intVal);
312 sscanf((
char*) &(str[*strIndexPtr]),
"%6d",&intVal);
314 return (intVal/10000.0f);
325 sscanf((
char*) &(str[*strIndexPtr]),
"%7d",&intVal);
327 return (intVal/100.0f);
363 for (
int chunkIndex=0; chunkIndex<numOfChunks; chunkIndex++) {
370 sprintf(commandStr,
"PVWR %02u%04x%s",portHandleNum, NDIAddress,chunk);
378 sprintf(commandStr,
"PINIT %02u",portHandleNum);
386 sprintf(commandStr,
"PENA %02uD",portHandleNum);
393 return(portHandleNum);
397 printf(
"vrpn_Tracker_NDI_Polaris: Switching NDI to higher baud rate, and then reopening com port at higher rate...");
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
~vrpn_Tracker_NDI_Polaris()
void sendCommand(const char *commandString)
int vrpn_write_characters(int comm, const unsigned char *buffer, size_t bytes)
Write the buffer to the serial port.
int vrpn_close_commport(int comm)
void vrpn_SleepMsecs(double dMsecs)
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.
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
unsigned int parse2CharIntFromNDIResponse(unsigned char *str, int *strIndexPtr=NULL)
virtual void send_report(void)
Generic connection class not specific to the transport mechanism.
int vrpn_set_rts(int comm)
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
vrpn_Connection * d_connection
Connection that this object talks to.
int vrpn_clear_rts(int comm)
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
void switchToHigherBaudRate(const char *port)
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),...
virtual int encode_to(char *buf)
virtual int get_report(void)
int vrpn_flush_output_buffer(int comm)
Throw out any characters (do not send) within the output buffer.
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
#define vrpn_gettimeofday
float parse6CharFloatFromNDIResponse(unsigned char *str, int *strIndexPtr)
int convertBinaryFileToAsciiEncodedHex(const char *filename, char *asciiEncodedHexStr)
int setupOneTool(const char *NDIToolRomFilename)
vrpn_int32 d_sender_id
Sender ID registered with the connection.
float parse7CharFloatFromNDIResponse(unsigned char *str, int *strIndexPtr)
unsigned char * latestResponseStr