12 int vrpn_Wanda::dbug_wanda = getenv(
"DBUG_WANDA") ? 1 : 0;
19 return (
double)(ts.tv_sec + ts.tv_usec/1e6);
25 for(
int i=0;i<num_bytes;i++) {
27 fprintf(stderr,
"%d ", (((1 << b) & ((
int)buf[i])) ? 1 : 0));
39 vrpn_float64 update_rate):
89 fprintf(stderr,
"Tracker: cannot write message: tossing\n");
92 fprintf(stderr,
"Tracker Fastrak: No valid connection\n");
103 if (bytesread < 2)
return;
106 fprintf(stderr,
"wanda huh? expected 2 characters on opening (got %d)\n", bytesread);
109 fprintf(stderr,
"Read init message from wanda\n");
111 fprintf(stderr,
"vrpn_Wanda: ERROR, expected 'M3' from wanda...\n");
119 int new_button_info = 0;
120 int new_valuator_info = 0;
130 bytesread += num_read;
133 while( index == 0 && bytesread > 0 && !(
buffer[0] & (1<<6)) ) {
134 fprintf(stderr,
"synching wanda\n");
135 for(
int i=0;i<bytesread-1;i++)
147 if (curtime - last_val_timestamp > 0.2) {
148 int new_valuator_info = 0;
152 new_valuator_info = 1;
156 new_valuator_info = 1;
159 if (new_valuator_info) {
161 fprintf(stderr,
"timeout: %lf\n", curtime - last_val_timestamp);
172 fprintf(stderr,
"\t(bytesread = %d)\n", bytesread);
175 while( bytesread >= 3 && index < bytesread ) {
177 if (index == 0 && bytesread >= 3) {
180 signed char x =
static_cast<char>((
buffer[1] | ((
buffer[0]&3) << 6)));
181 signed char y =
static_cast<char>((
buffer[2] | ((
buffer[0]&12) << 4)));
182 double xd = -((double)x) / 34.0;
183 double yd = ((double)y) / 34.0;
185 if (xd > 1.0) xd = 1.0;
186 if (xd <-1.0) xd =-1.0;
187 if (yd > 1.0) yd = 1.0;
188 if (yd <-1.0) yd =-1.0;
192 new_valuator_info = 1;
196 new_valuator_info = 1;
201 int blue_val = (
buffer[0] & (1<<4)) ? 1 : 0;
202 int red_val = (
buffer[0] & (1<<5)) ? 1 : 0;
205 buttons[0] =
static_cast<unsigned char>(blue_val);
209 buttons[2] =
static_cast<unsigned char>(red_val);
219 if (index == 3 && bytesread > 3 && !(
buffer[3] & (1<<6))) {
220 int new_val = (
buffer[3]) ? 1 : 0;
223 buttons[1] =
static_cast<unsigned char>(new_val);
233 if (new_valuator_info)
237 if (index == 4 || (index == 3 && bytesread > 3 && (
buffer[3] & (1<<6)))) {
238 for(
int i=index;i<bytesread;i++)
void print_bits(char *buf, int num_bytes)
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...
unsigned char buffer[1024]
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
vrpn_float64 channel[vrpn_CHANNEL_MAX]
Generic connection class not specific to the transport mechanism.
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
void report_new_button_info()
vrpn_Connection * d_connection
Connection that this object talks to.
vrpn_Wanda(char *name, vrpn_Connection *c, char *portname, int baud, double)
#define MAX_TIME_INTERVAL
#define vrpn_gettimeofday
vrpn_int32 d_sender_id
Sender ID registered with the connection.
virtual vrpn_int32 encode_to(char *buf)
const int vrpn_ANALOG_RESETTING
void report_new_valuator_info()