31const double VELOCITY= (1/0.06144) * (1/0.00254);
34const unsigned char ESC = 27;
37const unsigned char GS = 29;
38const unsigned char ZERO = 0;
39const unsigned char ZEROES[] =
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
56 const char *port,
int baud,
int bits,
62 d_new_location_requested(false),
63 d_outstanding_requests(0)
67 fprintf(stderr,
"vrpn_Poser_Tek4662: No connection\n");
73 fprintf(stderr,
"vrpn_Poser_Tek4662: NULL port name\n");
80 fprintf(stderr,
"vrpn_Poser_Tek4662: Cannot Open serial port (%s)\n", port);
87 fprintf(stderr,
"vrpn_Poser_Server: can't register position handler\n");
94 fprintf(stderr,
"vrpn_Poser_Server: can't register velocity handler\n");
130static bool interpret_GIN_bytes(
const unsigned char inbuf[],
bool &pen_down,
float &x,
float &y)
133 for (
int i = 0; i < 6; i++) {
134 if ( (inbuf[i] & 0x60) != 0x20) {
return false; }
136 if ( (inbuf[6] & 0x60) != 0x40) {
return false; }
139 pen_down = (inbuf[6] & (1<<2)) != 0;
145 vrpn_uint16 x_int, y_int;
155 if (pen_down) { printf(
"XXX pen down\n"); }
else { printf(
"XXX pen up\n"); }
156 printf(
"XXX At %f, %f\n", x, y);
183 struct timeval wait_time = { 1, 0 };
185 if (bufcount !=
sizeof(inbuf)) {
186 fprintf(stderr,
"vrpn_Poser_Tek4662::reset(): Expected %d characters, got %d\n",
187 static_cast<int>(
sizeof(inbuf)), bufcount);
195 if (!interpret_GIN_bytes(inbuf, pen_down, x, y)) {
211 fprintf(stderr,
"vrpn_Poser_Tek4662: cannot write message: tossing\n");
214 fprintf(stderr,
"vrpn_Poser_Tek4662: No valid connection\n");
233 vrpn_uint16 x_int, y_int;
245 MOVE[1] |= y_int >> 7;
252 MOVE[4] |= x_int >> 7;
261 printf(
"XXX Going to %f,%f (%d, %d)\n",
p_pos[0],
p_pos[1], x_int, y_int);
275 struct timeval timeout = {0, 0};
286 struct timeval timeout = {0, 0};
304 if (!interpret_GIN_bytes(
d_inbuf, pen_down, x, y)) {
318 fprintf(stderr,
"vrpn_Poser_Tek4662: cannot write message: tossing\n");
321 fprintf(stderr,
"vrpn_Poser_Tek4662: No valid connection\n");
378 fprintf(stderr,
"vrpn_Poser_Tek4662: Unknown status (%d)\n",
status);
388 const char* params = (p.
buffer);
391 if (p.
payload_len != (7 *
sizeof(vrpn_float64)) ) {
392 fprintf(stderr,
"vrpn_Poser_Server: change message payload error\n");
393 fprintf(stderr,
" (got %d, expected %d)\n",
394 p.
payload_len,
static_cast<int>(7 *
sizeof(vrpn_float64)) );
399 for (i = 0; i < 3; i++) {
402 for (i = 0; i < 4; i++) {
407 for (i = 0; i < 3; i++) {
426 const char* params = (p.
buffer);
430 if (p.
payload_len != (8 *
sizeof(vrpn_float64)) ) {
431 fprintf(stderr,
"vrpn_Poser_Server: velocity message payload error\n");
432 fprintf(stderr,
" (got %d, expected %d)\n",
433 p.
payload_len,
static_cast<int>(8 *
sizeof(vrpn_float64)) );
438 for (i = 0; i < 3; i++) {
441 for (i = 0; i < 4; i++) {
447 for (i = 0; i < 3; i++) {
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.
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...
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.
Generic connection class not specific to the transport mechanism.
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...
unsigned char d_inbuf[1024]
static int VRPN_CALLBACK handle_change_message(void *userdata, vrpn_HANDLERPARAM p)
bool d_new_location_requested
static int VRPN_CALLBACK handle_vel_change_message(void *userdata, vrpn_HANDLERPARAM p)
int d_outstanding_requests
vrpn_Poser_Tek4662(const char *name, vrpn_Connection *c, const char *port, int baud=1200, int bits=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
virtual ~vrpn_Poser_Tek4662()
vrpn_float64 p_pos_min[3]
vrpn_float64 p_pos_rot_max[3]
vrpn_float64 p_vel_min[3]
vrpn_float64 p_pos_rot_min[3]
vrpn_float64 p_vel_rot_min[3]
vrpn_float64 p_vel_max[3]
vrpn_float64 p_vel_quat[4]
vrpn_float64 p_vel_quat_dt
vrpn_float64 p_vel_rot_max[3]
vrpn_float64 p_pos_max[3]
vrpn_int32 req_position_m_id
struct timeval p_timestamp
vrpn_int32 req_velocity_m_id
virtual int encode_to(char *buf)
This structure is what is passed to a vrpn_Connection message callback.
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
const int vrpn_Poser_Tek4662_SYNCING
const unsigned char DEVICE
const unsigned char PLOTTER_ON[]
const unsigned char ZEROES[]
const int DATA_RECORD_LENGTH
const unsigned char GIN[]
const int vrpn_Poser_Tek4662_RUNNING
const unsigned char MOVE_TEMPLATE[]
const unsigned LOWTWOBITS
const int vrpn_Poser_Tek4662_FAIL
const unsigned char RESET[]
const double COUNTS_PER_METER
const unsigned LOWFIVEBITS
const int vrpn_Poser_Tek4662_RESETTING
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_drain_output_buffer(int comm)
Wait until all of the characters in the output buffer are sent, then return.
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_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.
unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
void vrpn_SleepMsecs(double dMilliSecs)
#define vrpn_gettimeofday
#define DATA_RECORD_LENGTH