42 static const unsigned char BBOX_RESET = 0x20;
43 static const int VRPN_DIAL_RANGE = 200;
49 char *serialPortName):
59 sprintf(message,
"vrpn_raw_SGIBox: error opening serial port: %s\n",serialPortName);
80 unsigned char inbuf[100];
82 unsigned char lightson[5] = {0x75, 0xff, 0xff, 0xff, 0xff};
83 unsigned char lightsoff[5] = {0x75, 0x00, 0x00, 0x00, 0x00};
85 unsigned char activatebuttons[5] = {0x73, 0xff, 0xff, 0xff, 0xff};
86 unsigned char enablebuttons[5] = {0x71, 0xff, 0xff, 0xff, 0xff};
87 unsigned char enabledials[3] = {0x50, 0xff, 0xff};
96 perror(
"vrpn_raw_SGIBox::reset(): Can't flush incoming buffer");
100 perror(
"vrpn_raw_SGIBox::reset(): Can't write reset command");
104 perror(
"vrpn_raw_SGIBox::reset(): Can't write reset command");
111 perror(
"vrpn_raw_SGIBox::reset(): Can't read or no data from serial port");
115 printf(
"vrpn_raw_SGIBox::reset(): Box's response to reset command: %02x\n", inbuf[0]);
118 for (i = 0; i < ret; i++) {
119 if (inbuf[i] != BBOX_RESET) {
121 fprintf(stderr,
"vrpn_raw_SGIBox::reset(): Bad response to reset command : %02x- please restart sgiBox vrpn server\n",inbuf[i]);
127 if (serialfd != -1) {
128 printf(
"vrpn_raw_SGIBox: flashing the lights on then off...\n");
130 perror(
"vrpn_raw_SGIBox::reset(): Can't turn the lights on");
135 perror(
"vrpn_raw_SGIBox::reset(): Can't turn the lights off");
143 if (serialfd != -1) {
147 perror(
"vrpn_raw_SGIBox::reset(): Can't enable dials");
152 printf(
"vrpn_raw_SGIBOX::reset() : Enabled Dials\n");
157 for (i=0; i < 2; i++) {
160 perror(
"vrpn_raw_SGIBox::reset(): Can't enable buttons");
165 printf(
"vrpn_raw_SGIBOX::reset() : Enabled Buttons\n");
169 perror(
"vrpn_raw_SGIBox::reset(): Can't activate buttons\n");
174 printf(
"vrpn_raw_SGIBOX::reset() : Activated Buttons\n");
206 unsigned char command) {
207 if ( (command >= base_command) && (command < (base_command+8)) ) {
208 buttons[base_button + (command-base_command)] = 1;
216 unsigned char command) {
217 if ( (command >= base_command) && (command < (base_command+8)) ) {
218 buttons[base_button + (command-base_command)] = 0;
231 unsigned char command;
235 printf(
"."); fflush(stdout);
246 perror(
"vrpn_raw_SGIBOX::get_report(): error reading serial port - reseting...");
253 printf(
"vrpn_raw_SGIBox::get_report(): Got %02x\n", command);
257 if (command == 0x20) {
258 perror(
"vrpn_raw_SGIBOX::get_report(): Got reset response when we didn't expect it - reseting...\n");
264 if ( command >= 0xC0 ) {
286 if ( (command >= 0x30) && (command <= 0x37) ) {
288 printf(
"vrpn_raw_SGIBOX::get_report(): Got dial event\n");
290 unsigned char dial_value[2];
291 int i = command - 0x30;
293 struct timeval timeout = {0, 10000};
298 perror(
"vrpn_raw_SGIBOX: starting getting a dial command from box, but message wasn't completed -reseting ...");
303 printf(
"vrpn_raw_SGIBOX::get_report(): Dial event %02x:[ %02x %02x] \n",
304 command,dial_value[0],dial_value[1]);
308 value = static_cast<short>((dial_value[0]<<8) | dial_value[1]);
314 int temp = value - mid_values[i];
315 if (temp > VRPN_DIAL_RANGE) {
317 mid_values[i] = value - VRPN_DIAL_RANGE;
318 }
else if (temp < -VRPN_DIAL_RANGE) {
320 mid_values[i] = value + VRPN_DIAL_RANGE;
327 dials[i] = (value-last_values[i])/(
double)(VRPN_DIAL_RANGE);
328 last_values[i] = value;
335 ( (command >= 0x30) && (command <= 0x37) ) ||
339 perror(
"vrpn_raw_SGIBOX: unrecognized command from sgiBox - reseting...");
352 unsigned char lights[4];
353 unsigned char msg[5];
357 for (bank = 0; bank < 4; bank++) {
359 for (i = 0; i < 8; i++) {
360 int buttonLightNumber = bank*8 + i;
362 lights[bank]=static_cast<unsigned char>(lights[bank]|1<<i);
370 msg[0] = 0x75; memcpy(&msg[1],lights,4);
372 perror(
"Could not write light control message");
395 printf(
"vrpn_raw_SGIBox::Get first new connection, reset the box\n");
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
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...
const char * vrpn_got_first_connection
These are the strings that define the system-generated message types that tell when connections are r...
void vrpn_SleepMsecs(double dMsecs)
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.
virtual void report_changes(void)
#define vrpn_SGI_NUM_BUTTONS
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
void check_release_bank(int base_button, unsigned char base_command, unsigned char command)
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
vrpn_float64 channel[vrpn_CHANNEL_MAX]
void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Generic connection class not specific to the transport mechanism.
int vrpn_write_slowly(int comm, const unsigned char *buffer, size_t bytes, int millisec_delay)
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
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_raw_SGIBox(char *name, vrpn_Connection *c, char *serialDevName)
This structure is what is passed to a vrpn_Connection message callback.
#define vrpn_SGI_NUM_DIALS
void check_press_bank(int base_button, unsigned char base_command, unsigned char command)
virtual vrpn_int32 register_message_type(const char *name)
vrpn_float64 last[vrpn_CHANNEL_MAX]
vrpn_float64 dials[vrpn_DIAL_MAX]