23 const char *port,
long baud)
25 ready(1), serial_fd(0), iNumBytes(0), iNumDigBytes(0), iFilterPos(0)
29 fprintf(stderr,
"vrpn_ADBox: Cannot Open serial port\n");
51 struct timeval timeout = {0,200000};
70 case 18: iNumDigBytes = 2;
break;
71 case 19: iNumDigBytes = 3;
break;
72 default: iNumBytes = 0; iNumDigBytes = 0;
break;
81 "vrpn_ADBox: ad-box with %d digital and %d analog ports detected\n",
99 fprintf(stderr,
"vrpn_ADBox: trying to detect ad-box\n");
108 for (
int c = 0; c < iNumBytes; c++)
112 fprintf(stderr,
"vrpn_ADBox: could only read %d chars, %d expected\n",c,iNumBytes+1);
126 for (i = 0; i < iNumDigBytes; i++)
127 for (
int b = 0; b < 8; b++)
130 for (i = 0; i < (iNumBytes - iNumDigBytes) / 2; i++)
132 int iOrg = iFilter[i][iFilterPos] =
133 (int(buffer[iNumDigBytes + i * 2]) << 8) |
int(buffer[iNumDigBytes + 1 + i * 2]);
134 fAnalog = float(iOrg) / 1023.0f;
137 do p = (p + 29) % 30;
while (p != iFilterPos && iFilter[i][p] == iOrg);
140 int iLast(iFilter[i][p]);
141 if (iOrg - iLast == 1 || iLast - iOrg == 1)
143 do p = (p + 29) % 30;
while (p != iFilterPos && iFilter[i][p] == iLast);
144 if (p != iFilterPos && iFilter[i][p] == iOrg)
145 fAnalog = float(iOrg + iLast) / 2046.0f;
152 iFilterPos = (iFilterPos + 1) % 30;
vrpn_ADBox(char *name, vrpn_Connection *c, const char *port="/dev/ttyS1/", long baud=9600)
void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_float64 last[vrpn_CHANNEL_MAX]
vrpn_float64 channel[vrpn_CHANNEL_MAX]
vrpn_Analog(const char *name, vrpn_Connection *c=NULL)
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report only if something has changed (for servers) Optionally, tell what time to stamp the val...
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Generic connection class not specific to the transport mechanism.
class VRPN_API vrpn_Connection
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)
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_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)
#define vrpn_gettimeofday