vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
22 #define STATUS_RESETTING (-1) // Resetting the device
23 #define STATUS_SYNCING (0) // Looking for the first character of report
24 #define STATUS_READING (1) // Looking for the rest of the report
26 #define TIMEOUT_TIME_INTERVAL (10000000L) // max time between reports (usec)
27 #define POLL_INTERVAL (1000000L) // time to poll if no response in a while (usec)
47 fprintf(stderr,
"vrpn_Nikon_Controls: can't register handler\n");
52 fprintf(stderr,
"vrpn_Nikon_Controls: can't register handler\n");
57 fprintf(stderr,
"vrpn_Nikon_Controls: can't register handler\n");
61 fprintf(stderr,
"vrpn_Nikon_Controls: Can't get connection!\n");
67 static const char *error_code_to_string(
const int code)
70 case 1:
return "Command error";
71 case 2:
return "Operand error";
72 case 3:
return "Procedding timout error";
73 case 4:
return "Receive buffer overflow error";
74 case 5:
return "Device not mounted";
75 case 6:
return "Drive count overflow error";
76 case 7:
return "Processing prohibited error";
77 default:
return "unknown error";
91 static int parse_focus_position_response(
const char *inbuf,
double &response_pos)
95 size_t len = strlen((
const char *)inbuf);
97 fprintf(stderr,
"parse_focus_position_response(): String too short\n");
98 response_pos = 0;
return 0;
100 if ( (inbuf[len-2] !=
'\r') || (inbuf[len-1] !=
'\n') ) {
101 fprintf(stderr,
"parse_focus_position_response(): (%s) Not [CR][LF] at end\n",inbuf);
102 response_pos = 0;
return 0;
109 printf(
"Nikon control: parsing [%s]\n", inbuf);
112 if (strncmp(inbuf,
"aSPR", strlen(
"aSPR")) == 0) {
113 response_pos = atoi(&inbuf[4]);
117 }
else if (strncmp(inbuf,
"nSPR", strlen(
"nSPR")) == 0) {
118 response_pos = atoi(&inbuf[4]);
122 }
else if (strncmp(inbuf,
"qSMVA", strlen(
"qSMVA")) == 0) {
126 }
else if (strncmp(inbuf,
"oSMV", strlen(
"oSMV")) == 0) {
130 }
else if (strncmp(inbuf,
"nSMV", strlen(
"nSMV")) == 0) {
131 response_pos = atoi(&inbuf[4]);
136 fprintf(stderr,
"parse_focus_position_response(): Unknown response (%s)\n", inbuf);
137 response_pos = 0;
return 0;
152 unsigned char inbuf[256];
166 sprintf(cmd,
"rSPR\r");
168 fprintf(stderr,
"vrpn_Nikon_Controls::reset(): Cannot send focus request\n");
179 perror(
"vrpn_Nikon_Controls::reset(): Error reading position from device");
183 fprintf(stderr,
"vrpn_Nikon_Controls::reset(): No characters when reading position from device\n");
187 ret = parse_focus_position_response((
char *)inbuf, response_pos);
189 fprintf(stderr,
"vrpn_Nikon_Controls::reset(): Error reading focus: %s\n",
190 error_code_to_string((
int)(response_pos)));
194 fprintf(stderr,
"vrpn_Nikon_Controls::reset(): Unexpected response to focus request\n");
199 sprintf(errmsg,
"Focus reported (this is good)");
251 printf(
"... Got the 1st char\n");
271 if (ret != 0) printf(
"... got %d characters (%d total)\n",ret,
_bufcount);
305 ret = parse_focus_position_response((
const char *)
_buffer, response_pos);
307 fprintf(stderr,
"Bad response from nikon [%s], syncing\n",
_buffer);
308 fprintf(stderr,
" (%s)\n", error_code_to_string((
int)response_pos));
350 sprintf(msg,
"vrpn_Nikon_Controls::set_channel(): Index out of bounds (%d of %d), value %lg\n",
357 sprintf(msg,
"fSMV%ld\r", (
long)value);
359 printf(
"Nikon Control: Asking to move to %ld with command %s\n", (
long)value, msg);
362 fprintf(stderr,
"vrpn_Nikon_Controls::set_channel(): Can't write command\n");
366 fprintf(stderr,
"vrpn_Nikon_Controls::set_channel(): Can't drain command\n");
378 const char *bufptr = p.
buffer;
397 const char* bufptr = p.
buffer;
407 sprintf(msg,
"vrpn_Nikon_Controls::handle_request_channels_message(): Index out of bounds (%d of %d), clipping\n",
412 for (i = 0; i < num; i++) {
477 struct timeval current_time;
484 sprintf(msg,
"rSPR\r");
486 fprintf(stderr,
"vrpn_Nikon_Controls::mainloop(): Can't write focus request command\n");
497 sprintf(errmsg,
"Timeout... current_time=%ld:%ld, timestamp=%ld:%ld",
498 current_time.tv_sec, static_cast<long>(current_time.tv_usec),
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.
unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
vrpn_int32 d_ping_message_id
Ask the server if they are there.
vrpn_float64 channel[vrpn_CHANNEL_MAX]
int vrpn_drain_output_buffer(int comm)
Wait until all of the characters in the output buffer are sent, then return.
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 TIMEOUT_TIME_INTERVAL
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
static int VRPN_CALLBACK handle_connect_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a connection request with a report of the values.
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_Connection * d_connection
Connection that this object talks to.
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
void vrpn_SleepMsecs(double dMsecs)
virtual int get_report(void)
This structure is what is passed to a vrpn_Connection message callback.
#define VRPN_MSG_WARNING(msg)
vrpn_int32 d_sender_id
Sender ID registered with the connection.
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.
static int VRPN_CALLBACK handle_request_channels_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a request to change multiple channels at once.
vrpn_Nikon_Controls(const char *device_name, vrpn_Connection *con=NULL, const char *port_name="COM1")
Generic connection class not specific to the transport mechanism.
virtual void mainloop()
This routine is called each time through the server's main loop.
#define vrpn_gettimeofday
unsigned char _buffer[512]
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
const char * VALID_REPORT_CHARS
Characters that can start a report of the type we recognize.
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
Send values whether or not they have changed.
struct timeval o_timestamp
virtual int set_channel(unsigned chan_num, vrpn_float64 value)
Set the channel associated with the index to the specified value.
vrpn_float64 o_channel[vrpn_CHANNEL_MAX]
Header containing macros formerly duplicated in a lot of implementation files.
int vrpn_write_characters(int comm, const unsigned char *buffer, size_t bytes)
Write the buffer to the serial port.
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.
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
Send changes since the last time.
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...
vrpn_int32 request_channels_m_id
#define VRPN_MSG_ERROR(msg)
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...