00001 /** 00002 \file Robots/LoBot/irccm/LoIO.h 00003 \brief Serial I/O API for Robolocust control program running on iRobot 00004 Create Command Module. 00005 00006 This file defines an API for serial port I/O to be used by the various 00007 modules of the Robolocust control program for the iRobot Create 00008 Command Module. 00009 */ 00010 00011 /* 00012 ************************************************************************ 00013 * The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 * 00014 * by the University of Southern California (USC) and the iLab at USC. * 00015 * See http: iLab.usc.edu for information about this project. * 00016 * * 00017 * Major portions of the iLab Neuromorphic Vision Toolkit are protected * 00018 * under the U.S. patent ``Computation of Intrinsic Perceptual Saliency * 00019 * in Visual Environments, and Applications'' by Christof Koch and * 00020 * Laurent Itti, California Institute of Technology, 2001 (patent * 00021 * pending; application number 09/912,225 filed July 23, 2001; see * 00022 * http: pair.uspto.gov/cgi-bin/final/home.pl for current status). * 00023 ************************************************************************ 00024 * This file is part of the iLab Neuromorphic Vision C++ Toolkit. * 00025 * * 00026 * The iLab Neuromorphic Vision C++ Toolkit is free software; you can * 00027 * redistribute it and/or modify it under the terms of the GNU General * 00028 * Public License as published by the Free Software Foundation; either * 00029 * version 2 of the License, or (at your option) any later version. * 00030 * * 00031 * The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope * 00032 * that it will be useful, but WITHOUT ANY WARRANTY; without even the * 00033 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * 00034 * PURPOSE. See the GNU General Public License for more details. * 00035 * * 00036 * You should have received a copy of the GNU General Public License * 00037 * along with the iLab Neuromorphic Vision C++ Toolkit; if not, write * 00038 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * 00039 * Boston, MA 02111-1307 USA. * 00040 ************************************************************************ 00041 */ 00042 00043 /* 00044 Primary maintainer for this file: mviswana usc edu 00045 $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/irccm/LoIO.h $ 00046 $Id: LoIO.h 13744 2010-08-02 02:55:15Z mviswana $ 00047 */ 00048 00049 #ifndef LOBOT_IRCCM_IO_DOT_H 00050 #define LOBOT_IRCCM_IO_DOT_H 00051 00052 /*----------------------------- CONSTANTS -----------------------------*/ 00053 00054 // The different I/O error states/codes 00055 enum { 00056 LOBOT_IO_OK, 00057 LOBOT_IO_TIMEOUT, 00058 } ; 00059 00060 /*-------------------------- INITIALIZATION ---------------------------*/ 00061 00062 /// Set up the serial port 00063 void lo_init_comm(void) ; 00064 00065 /// Reset communication speed on both Create robot and Command Module 00066 void lo_reset_baud(int baud_rate) ; 00067 00068 /// Flush the RX and TX buffers 00069 void lo_clear_buffers(void) ; 00070 00071 /*------------------------- SEND/RECEIVE API --------------------------*/ 00072 00073 /// Transmit a byte over the serial port 00074 void lo_tx(char byte) ; 00075 00076 /// Receive the specified number of bytes over the serial port, waiting a 00077 /// maximum number of milliseconds before giving up. If the timeout is 00078 /// zero, wait forever for the data to come in. 00079 /// 00080 /// The function returns the number of bytes successfully read. 00081 /// 00082 /// Clients should setup a large enough buffer to accommodate the amount 00083 /// of data they require and check the return value before using the data 00084 /// in the buffer. If the number of bytes read is less than the number 00085 /// requested, clients can query the I/O error to see what went wrong. 00086 /// 00087 /// NOTE: Since we're using 8-bit integers, only a maximum of 255 bytes 00088 /// can be retrieved at one time. For the purposes of this control 00089 /// program, that number is more than enough. 00090 unsigned char lo_rx(char* buf, unsigned char n, unsigned int timeout) ; 00091 00092 /// Receive a single byte over the serial port, waiting a maximum number 00093 /// of milliseconds before giving up. If the timeout is zero, wait 00094 /// forever for the data byte to come in. 00095 /// 00096 /// Clients should check the I/O error flag before using the byte 00097 /// returned by this function. 00098 char lo_rx1(unsigned int timeout) ; 00099 00100 /*------------------------- USART REDIRECTION -------------------------*/ 00101 00102 /** 00103 Since the Command Module has only one USART, it needs to be switched 00104 between talking to the USB port and the iRobot Create's serial port. 00105 00106 Usually, the low-level Robolocust control program that runs on the 00107 command module will listen for incoming high-level motor commands over 00108 the USB port. But every time it needs to actually execute one of those 00109 commands, it will have to switch the USART to talk to the Create's 00110 serial port and then back again to continue listening to the higher 00111 layers of the Robolocust controller. 00112 00113 These functions switch the USART between the Command Module's USB port 00114 and the Create's serial port. 00115 */ 00116 //@{ 00117 void lo_io_to_usb(void) ; 00118 void lo_io_to_create(void) ; 00119 //@} 00120 00121 /*-------------------------- ERROR CHECKING ---------------------------*/ 00122 00123 /// Retrieve current I/O status. After each I/O operation, clients should 00124 /// use this function to check for errors. 00125 char lo_io_error(void) ; 00126 00127 /*---------------------------------------------------------------------*/ 00128 00129 #endif