LoSerial.H

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/io/LoSerial.H
00003    \brief Interface for talking to the robot's motor driver.
00004 
00005    lobot's computer sends motor commands to a Sabertooth motor driver via
00006    a Propeller board that is connected to the computer over a USB serial
00007    port. This file defines a class that encapsulates the serial
00008    communications interface using either libserial (if available) or
00009    INVT's serial communications support (if libserial is not available).
00010 */
00011 
00012 // //////////////////////////////////////////////////////////////////// //
00013 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00014 // 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 // Primary maintainer for this file: Manu Viswanathan <mviswana@usc.edu>
00043 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/io/LoSerial.H $
00044 // $Id: LoSerial.H 12645 2010-01-25 03:28:29Z mviswana $
00045 //
00046 
00047 #ifndef LOBOT_SERIAL_DOT_H
00048 #define LOBOT_SERIAL_DOT_H
00049 
00050 //------------------------------ HEADERS --------------------------------
00051 
00052 // Headers for serial port communications
00053 #ifdef HAVE_LIBSERIAL
00054 
00055 #include <SerialPort.h>
00056 
00057 #else // fallback to using INVT serial port support
00058 
00059 #include "Devices/Serial.H"
00060 #include "nub/ref.h"
00061 
00062 #endif
00063 
00064 // INVT model manager stuff
00065 #include "Component/ModelManager.H"
00066 
00067 //----------------------------- NAMESPACE -------------------------------
00068 
00069 namespace lobot {
00070 
00071 //------------------------- CLASS DEFINITION ----------------------------
00072 
00073 /**
00074    \class lobot::Serial
00075    \brief Serial communications API.
00076 
00077    The robot's motors are controlled by a motor driver that is in turn
00078    controlled by a Propeller-based I/O board. This board connects to the
00079    Robolocust computer (the mini-ITX Debian box) over a USB port. The
00080    lobot::Serial class provides an API for interfacing with the Propeller
00081    using a serial port. It uses libserial for the serial communications
00082    if that library is available. Otherwise, it falls back to using INVT's
00083    support for serial communications.
00084 */
00085 class Serial {
00086    /// The low-level serial device interface.
00087 #ifdef HAVE_LIBSERIAL
00088    SerialPort m_serial ;
00089 #else
00090    nub::ref< ::Serial> m_serial ;
00091    bool m_peek_flag ;
00092    char m_peek_char ;
00093 #endif
00094 
00095 public:
00096    /// Initialization.
00097    Serial(const ModelManager&, const std::string& device, int baud_rate) ;
00098 
00099    /// Check if the serial port has data available for reading.
00100    bool ready() ;
00101 
00102    /// Receive data from the serial port. Returns the number of bytes
00103    /// successfully read. Client should check that this is equal to the
00104    /// expected number.
00105    int read(char buf[], int n) ;
00106 
00107    /// Send data to the serial port.
00108    void write(char buf[], int n) ;
00109 
00110    /// Read the specified number of bytes and don't return until they're
00111    /// all read in.
00112    void read_full(char buf[], int n) ;
00113 
00114    /// Read and discard the specified number of bytes.
00115    void eat(int n) ;
00116 
00117    /// Clean-up.
00118   ~Serial() ;
00119 } ;
00120 
00121 //-----------------------------------------------------------------------
00122 
00123 } // end of namespace encapsulating this file's definitions
00124 
00125 #endif
00126 
00127 /* So things look consistent in everyone's emacs... */
00128 /* Local Variables: */
00129 /* indent-tabs-mode: nil */
00130 /* End: */
Generated on Sun May 8 08:41:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3