00001 /*!@file Psycho/EyeTrackerUDP.H Eye tracker for Doug munoz lab that 00002 uses UDP packets instead of the parallel port */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00006 // by the University of Southern California (USC) and the iLab at USC. // 00007 // See http://iLab.usc.edu for information about this project. // 00008 // //////////////////////////////////////////////////////////////////// // 00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00011 // in Visual Environments, and Applications'' by Christof Koch and // 00012 // Laurent Itti, California Institute of Technology, 2001 (patent // 00013 // pending; application number 09/912,225 filed July 23, 2001; see // 00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00017 // // 00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00019 // redistribute it and/or modify it under the terms of the GNU General // 00020 // Public License as published by the Free Software Foundation; either // 00021 // version 2 of the License, or (at your option) any later version. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00026 // PURPOSE. See the GNU General Public License for more details. // 00027 // // 00028 // You should have received a copy of the GNU General Public License // 00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00031 // Boston, MA 02111-1307 USA. // 00032 // //////////////////////////////////////////////////////////////////// // 00033 // 00034 // Primary maintainer for this file: David J. Berg <dberg@usc.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Psycho/EyeTrackerUDP.H $ 00036 00037 #ifndef PSYCHO_EYETRACKERUDP_H_DEFINED 00038 #define PSYCHO_EYETRACKERUDP_H_DEFINED 00039 00040 #define BUFSIZE 128 00041 00042 #include "Psycho/EyeTracker.H" 00043 #include <sys/socket.h> 00044 #include <netdb.h> 00045 00046 //! Interface to eye-tracker used in Doug Munoz' lab 00047 /*! This is a monkey scleral search coil type, with trigger over 00048 ethernet (UDP packets) from the REX experimental control system. */ 00049 class EyeTrackerUDP : public EyeTracker { 00050 public: 00051 //! Constructor 00052 EyeTrackerUDP(OptionManager& mgr, 00053 const std::string& descrName = "Eye Tracker UDP", 00054 const std::string& tagName = "EyeTrackerUDP"); 00055 //! Destructor 00056 virtual ~EyeTrackerUDP(); 00057 00058 //! Start the tracker 00059 /*! Tracking is started by sending a packet to REX. */ 00060 void startTracking(); 00061 00062 //! Stop the tracker 00063 /*! Tracking is stopped by sending a different packet. */ 00064 void stopTracking(); 00065 00066 //! Is the subject fixating? 00067 bool isFixating(); 00068 00069 //! Did the subject initiate a saccade? 00070 bool isSaccade(); 00071 00072 //! clear all our eye position (isFixating and isSaccade) states? 00073 void clearEyeStatus(); 00074 00075 //! Get current eye position 00076 /*! Not supported by this tracker. */ 00077 Point2D<int> getEyePos() const; 00078 00079 //! Get current fixation position 00080 /*! Not supported by this tracker. */ 00081 Point2D<int> getFixationPos() const; 00082 00083 //!Get the calibration set 00084 /*! Not implemented here */ 00085 CalibrationTransform::Data getCalibrationSet(nub::soft_ref<PsychoDisplay> d) const; 00086 00087 protected: 00088 //! codes for eye states 00089 enum {FIXCODE = 249, SACCODE = 250}; 00090 00091 void start1(); //!< get started 00092 void start2(); //!< get started after subcomponents get started 00093 void stop1(); //!< get things stopped 00094 00095 private: 00096 bool checkForData(); //!< Check for host data and set any internal flags 00097 void sendMessage(const char* msg); //!< send a message 00098 void pushEvent(const std::string& ev); //!< push string to event queue 00099 void setEyeFlags(const unsigned char msg); //!< set internal eye state flags bassed on a byte 00100 void resetEyeFlags(); //!< reset all eye state flags to false 00101 00102 //messages and flags 00103 char *startMsg, *stopMsg; 00104 bool isConnected, isFix, isSac; 00105 00106 //stuff for UDP communicaton 00107 int sockfd; //our socket 00108 struct addrinfo *myInfo, *hostInfo; //address info 00109 struct sockaddr lasthost_addr; //info about the last host 00110 socklen_t lasthost_addrlen; //last host address length 00111 fd_set master, read_fs; // master, and reading file descriptor list 00112 }; 00113 00114 00115 // ###################################################################### 00116 /* So things look consistent in everyone's emacs... */ 00117 /* Local Variables: */ 00118 /* mode: c++ */ 00119 /* indent-tabs-mode: nil */ 00120 /* End: */ 00121 00122 #endif // PSYCHO_EYETRACKERUDP_H_DEFINED