27 #define STATUS_RESETTING (-1) // Resetting the device 28 #define STATUS_SYNCING (0) // Looking for the first character of report 29 #define STATUS_READING (1) // Looking for the rest of the report 31 #define TIMEOUT_TIME_INTERVAL (2000000L) // max time between reports (usec) 32 #define POLL_INTERVAL (1000000L) // time to poll if no response in a while (usec) 57 fprintf(stderr,
"vrpn_Zaber: can't register handler\n");
62 fprintf(stderr,
"vrpn_Zaber: can't register handler\n");
67 fprintf(stderr,
"vrpn_Zaber: can't register handler\n");
71 fprintf(stderr,
"vrpn_Zaber: Can't get connection!\n");
78 unsigned char command[128];
81 command[0] = devicenum;
85 command[2] =
static_cast<unsigned char>(data & 0x000000FF);
86 command[3] =
static_cast<unsigned char>((data >> 8) & 0x000000FF);
87 command[4] =
static_cast<unsigned char>((data >> 16) & 0x000000FF);
88 command[5] =
static_cast<unsigned char>((data >> 24) & 0x000000FF);
95 unsigned char d1,
unsigned char d2,
unsigned char d3)
97 unsigned char command[128];
118 data = ((buf[0]) & 0x000000FF)
119 + ((buf[1] << 8) & 0x0000FF00)
120 + ((buf[2] << 16) & 0x00FF0000)
121 + ((buf[3] << 24) & 0xFF000000);
136 struct timeval timeout;
137 unsigned char inbuf[128];
151 fprintf(stderr,
"vrpn_Zaber::reset(): Cannot send renumber command, trying again\n");
166 int expected_chars = 4*6;
168 unsigned char channel_id =
static_cast<unsigned char>(
num_channel+1);
175 timeout.tv_usec = 30000;
178 perror(
"vrpn_Zaber::reset(): Error reading position from device");
184 if (ret != expected_chars) {
185 sprintf(errmsg,
"reset: Got %d of %d expected characters for position\n",ret, expected_chars);
192 if ( (inbuf[0] !=
num_channel+1) || (inbuf[1] != 23) ) {
203 #pragma warning ( disable : 4127 ) 207 #pragma warning ( default : 4127 ) 257 printf(
"... Got the 1st char\n");
276 if (ret != 0) printf(
"... got %d characters (%d total)\n",ret,
d_bufcount);
297 sprintf(msg,
"Bad command type (%d) in report (ignoring this report)",
d_buffer[1]);
314 unsigned char chan =
static_cast<unsigned char>(
d_buffer[0] - 1);
318 sprintf(msg,
"Invalid channel (%d of %d), resetting", chan,
num_channel);
337 const char *bufptr = p.
buffer;
352 sprintf(msg,
"vrpn_Zaber::handle_request_message(): Index out of bounds (%d of %d), value %lg\n",
358 me->
send_command(static_cast<unsigned char>(chan_num+1),20,(vrpn_int32)value);
366 const char* bufptr = p.
buffer;
376 sprintf(msg,
"vrpn_Zaber::handle_request_channels_message(): Index out of bounds (%d of %d), clipping\n",
381 for (i = 0; i < num; i++) {
445 struct timeval current_time;
459 sprintf(errmsg,
"Timeout... current_time=%ld:%ld, timestamp=%ld:%ld",
460 current_time.tv_sec, static_cast<long>(current_time.tv_usec),
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
int vrpn_write_characters(int comm, const unsigned char *buffer, size_t bytes)
Write the buffer to the serial port.
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 vrpn_SleepMsecs(double dMsecs)
VRPN_API int vrpn_unbuffer(const char **buffer, timeval *t)
Utility routine for taking a struct timeval from a buffer that was sent as a message.
vrpn_int32 request_channels_m_id
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_RELIABLE)
send report iff changed
#define TIMEOUT_TIME_INTERVAL
Header containing macros formerly duplicated in a lot of implementation files.
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
vrpn_float64 o_channel[vrpn_CHANNEL_MAX]
vrpn_float64 channel[vrpn_CHANNEL_MAX]
vrpn_int32 d_ping_message_id
Ask the server if they are there.
Generic connection class not specific to the transport mechanism.
bool send_command(unsigned char devicenum, unsigned char cmd, vrpn_int32 data)
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report whether something has changed or not (for servers) Optionally, tell what time to stamp ...
#define VRPN_MSG_WARNING(msg)
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
vrpn_Zaber(const char *name, vrpn_Connection *c, const char *port)
virtual void mainloop()
Called once through each main loop iteration to handle updates.
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_RELIABLE)
send report whether or not changed
int register_autodeleted_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
Registers a handler with the connection, and remembers to delete at destruction.
vrpn_Connection * d_connection
Connection that this object talks to.
This structure is what is passed to a vrpn_Connection message callback.
static int VRPN_CALLBACK handle_request_channels_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a request to change multiple channels at once.
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
unsigned char d_buffer[512]
unsigned d_expected_chars
#define vrpn_gettimeofday
struct timeval d_last_poll
vrpn_int32 d_sender_id
Sender ID registered with the connection.
static int VRPN_CALLBACK handle_connect_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a connection request with a report of the values.
static int VRPN_CALLBACK handle_request_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a request to change one of the values by setting the channel to that value.
unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
virtual int get_report(void)
vrpn_int32 convert_bytes_to_reading(const unsigned char *buf)
Convert the four bytes that have been read into a signed integer value.
#define VRPN_MSG_ERROR(msg)