int dthost_pause (void *host_priv) { int ret = 0; dthost_context_t *hctx = (dthost_context_t *) host_priv; ret = host_pause (hctx); return ret; }
/* hci3_passwd_cmd() handles a cmd that requires a password. * Assumes any nec arguments are in cfg_args[]. * Throws out any chars currently still in input buffer. */ hci3_result hci3_passwd_cmd(hci3_rec *hci, byte cmnd) { int ch, port = hci->port_num, i; host_write_char(port, cmnd); hci3_fast_timeout(hci); host_start_timeout(port); while( (ch=host_read_char(port)) != cmnd) { if (ch != -1) host_start_timeout(port); if (host_timed_out(port)) break; } if (ch == cmnd) { host_write_string(port, hci->serial_number); host_write_char(port, 0x00); /* Write the null to terminate */ host_start_timeout(port); while( (ch=host_read_char(port)) == -1) if (host_timed_out(port)) break; if (ch == -1) return hci3_error(hci, TIMED_OUT); else if (ch == PASSWD_OK) { for(i=0; i<num_cfg_args; i++) host_write_char(hci->port_num, cfg_args[i]); for(i=0; i<num_cfg_args; i++) host_pause(CFG_ARG_PAUSE); return SUCCESS; } else return BAD_PASSWORD; } else return hci3_error(hci, TIMED_OUT); }
/* hci3_disconnect() ends the session and closes the serial port. * The next time the host runs hci3_connect(), the HCI will * respond without having to be turned off & on. */ void hci3_disconnect(hci3_rec *hci) { host_flush_serial(hci->port_num); hci3_end(hci); host_pause(END_PAUSE); host_close_serial(hci->port_num); }
/* hci3_autosynch() leads the Immersion HCI through the baudrate * auto-synch process. This requires that the HCI was either * just powered-on or has just been given an END_SESSION command, * such as by a previous call to hci3_end(). */ hci3_result hci3_autosynch(hci3_rec *hci) { int ch, port = hci->port_num; char *sign_ch = SIGNON_STR; int signed_on = 0; host_start_timeout(port); while ( !signed_on && !host_timed_out(port) ) { hci3_end(hci); /* In case session wasn't ended before */ host_write_string(port, SIGNON_STR); host_pause(SIGNON_PAUSE); while (((ch=host_read_char(port)) != -1) && !signed_on) { if (ch == *sign_ch) { if (!*++sign_ch) { signed_on = 1; } } else { sign_ch = SIGNON_STR; } } } host_flush_serial(port); /* Get rid of excess SIGNON strings in buffer */ if (signed_on) return SUCCESS; else return NO_HCI; }
/* hci3_end_motion() cancels motion-reporting mode and clears all unparsed data. * To cancel motion-reporting without clearing data, use hci3_insert_marker(). */ void hci3_end_motion(hci3_rec *hci) { int port = hci->port_num; host_write_char(port, 0); host_pause(5e-2); host_flush_serial(port); }
/* hci3_factory_settings() restores all factory settings */ hci3_result hci3_factory_settings(hci3_rec *hci) { hci3_result result; num_cfg_args = 0; result = hci3_passwd_cmd(hci, RESTORE_FACTORY); host_pause(RESTORE_PAUSE); return result; }
/* hci3_change_baud() changes the HCI's baud rate and changes the host's * baud rate to match. ANY PENDING SERIAL DATA IS LOST. */ void hci3_change_baud(hci3_rec *hci, long int new_baud) { byte baud_code; host_fix_baud(&new_baud); baud_code = baud_to_code(new_baud); new_baud = code_to_baud(baud_code); host_write_char(hci->port_num, SET_BAUD); host_write_char(hci->port_num, baud_code); host_pause(END_PAUSE); host_close_serial(hci->port_num); host_open_serial(hci->port_num, new_baud); }
/* hci3_reset_com() clears the host serial i/o buffers. * This often helps to recover from a BAD_PACKET error and may be useful * in a user-defined BAD_PACKET_handler. */ void hci3_reset_com(hci3_rec *hci) { host_pause(5e-2); /* Wait 50 ms for HCI to settle */ host_flush_serial(hci->port_num); hci3_clear_packet(hci); }