visca.h

00001 
00002 /***************************************************************************
00003  *  visca.h - Class for accessing visca cams
00004  *
00005  *  Generated: Wed Jun 08 12:06:15 2005
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __FIREVISION_CONTROL_VISCA_H_
00025 #define __FIREVISION_CONTROL_VISCA_H_
00026 
00027 #include <core/exception.h>
00028 
00029 #ifdef TIMETRACKER_VISCA
00030 #  warning Visca time tracker enabled
00031 #  include <utils/timetracker.h>
00032 #  include <fstream>
00033 #endif
00034 
00035 #include <cstddef>
00036 
00037 namespace firevision {
00038 #if 0 /* just to make Emacs auto-indent happy */
00039 }
00040 #endif
00041 
00042 class ViscaControlException : public fawkes::Exception
00043 {
00044  public:
00045   ViscaControlException(const char *msg);
00046   ViscaControlException(const char *msg, const int _errno);
00047 };
00048 
00049 class ViscaControlInquiryRunningException : public ViscaControlException
00050 {
00051  public:
00052   ViscaControlInquiryRunningException();
00053 };
00054 
00055 
00056 class ViscaControl {
00057 
00058  public:
00059   static const unsigned int VISCA_WHITEBLANCE_AUTO;
00060   static const unsigned int VISCA_WHITEBALANCE_INDOOR;
00061   static const unsigned int VISCA_WHITEBALANCE_OUTDOOR;
00062   static const unsigned int VISCA_WHITEBALANCE_ONE_PUSH;
00063   static const unsigned int VISCA_WHITEBALANCE_ATW;
00064   static const unsigned int VISCA_WHITEBALANCE_MANUAL;
00065 
00066   ViscaControl(bool blocking = true);
00067 
00068   void         open(const char *port);
00069   void         close();
00070 
00071   // basic communication
00072   void         set_address(unsigned int num_cameras);
00073   void         clear();
00074 
00075   // low level
00076   void         send();
00077   void         recv(unsigned int max_wait_ms = 10);
00078   void         recv_ack(unsigned int *socket = NULL);
00079   void         send_with_reply();
00080   void         send_nonblocking(unsigned int *socket = NULL);
00081   void         cancel_command(unsigned int socket);
00082   bool         data_available();
00083   void         process();
00084 
00085   // pan tilt stuff
00086   void         resetPanTilt();
00087   /** Query for pan/tilt but do not wait until finished
00088    * This will send an inquire to the camera that asks for pan/tilt values but
00089    * it does not wait for the data! A later call to getPanTilt will then block and
00090    * wait until the results arrive.
00091    * Not that you can _not_ run another inquire (get*) method until this call has
00092    * finished! You will get VISCA_E_INQRUNNING as error message.
00093    */
00094   void         startGetPanTilt();
00095   void         setPanTilt(int pan, int tilt);
00096   void         getPanTilt(int *pan, int *tilt);
00097   void         setPanTiltLimit(int pan_left, int pan_right, int tilt_up, int tilt_down);
00098   void         resetPanTiltLimit();
00099 
00100   // zoom
00101   void         resetZoom();
00102   void         setZoom(unsigned int zoom);
00103   void         getZoom(unsigned int *zoom);
00104   void         setZoomSpeedTele(unsigned int speed);
00105   void         setZoomSpeedWide(unsigned int speed);
00106   void         setZoomDigitalEnabled(bool enabled);
00107 
00108   // effects, just to play with...
00109   void         resetEffect();
00110   void         applyEffect(unsigned char effect);
00111   void         applyEffectPastel();
00112   void         applyEffectNegArt();
00113   void         applyEffectSepia();
00114   void         applyEffectBnW();
00115   void         applyEffectSolarize();
00116   void         applyEffectMosaic();
00117   void         applyEffectSlim();
00118   void         applyEffectStretch();
00119 
00120   unsigned int getWhiteBalanceMode();
00121 
00122  private:
00123 
00124   // possible running inquires
00125   static const unsigned int VISCA_RUNINQ_NONE                   = 0;
00126   static const unsigned int VISCA_RUNINQ_PANTILT                = 1;
00127 
00128   // Cameras
00129   static const unsigned char VISCA_BUS_0                        = 0;
00130   static const unsigned char VISCA_BUS_1                        = 1;
00131   static const unsigned char VISCA_BUS_2                        = 2;
00132   static const unsigned char VISCA_BUS_3                        = 3;
00133   static const unsigned char VISCA_BUS_4                        = 4;
00134   static const unsigned char VISCA_BUS_5                        = 5;
00135   static const unsigned char VISCA_BUS_6                        = 6;
00136   static const unsigned char VISCA_BUS_7                        = 7;
00137   static const unsigned char VISCA_BUS_BROADCAST                = 8;
00138 
00139   // basic formatting
00140   static const unsigned char VISCA_COMMAND                      = 0x01;
00141   static const unsigned char VISCA_CANCEL                       = 0x20;
00142   static const unsigned char VISCA_INQUIRY                      = 0x09;
00143   static const unsigned char VISCA_TERMINATOR                   = 0xFF;
00144 
00145   // response types
00146   static const unsigned char VISCA_RESPONSE_CLEAR               = 0x40;
00147   static const unsigned char VISCA_RESPONSE_ADDRESS             = 0x30;
00148   static const unsigned char VISCA_RESPONSE_ACK                 = 0x40;
00149   static const unsigned char VISCA_RESPONSE_COMPLETED           = 0x50;
00150   static const unsigned char VISCA_RESPONSE_ERROR               = 0x60;
00151 
00152   // errors
00153   static const unsigned char VISCA_ERROR_LENGTH                 = 0x01;
00154   static const unsigned char VISCA_ERROR_SYNTAX                 = 0x02;
00155   static const unsigned char VISCA_ERROR_BUFFERFULL             = 0x03;
00156   static const unsigned char VISCA_ERROR_CANCELLED              = 0x04;
00157   static const unsigned char VISCA_ERROR_NOSOCKET               = 0x05;
00158   static const unsigned char VISCA_ERROR_NOTEXECABLE            = 0x41;
00159 
00160 
00161   // categories
00162   static const unsigned char VISCA_CATEGORY_INTERFACE           = 0x00;
00163   static const unsigned char VISCA_CATEGORY_CAMERA1             = 0x04;
00164   static const unsigned char VISCA_CATEGORY_PAN_TILTER          = 0x06;
00165   static const unsigned char VISCA_CATEGORY_CAMERA2             = 0x07;
00166 
00167   static const unsigned char VISCA_POWER                        = 0x00;
00168   static const unsigned char VISCA_DEVICE_INFO                  = 0x02;
00169   static const unsigned char VISCA_KEYLOCK                      = 0x17;
00170   static const unsigned char VISCA_ID                           = 0x22;
00171   static const unsigned char VISCA_ZOOM                         = 0x07;
00172   static const unsigned char   VISCA_ZOOM_STOP                  = 0x00;
00173   static const unsigned char   VISCA_ZOOM_TELE                  = 0x02;
00174   static const unsigned char   VISCA_ZOOM_WIDE                  = 0x03;
00175   static const unsigned char   VISCA_ZOOM_TELE_SPEED            = 0x20;
00176   static const unsigned char   VISCA_ZOOM_WIDE_SPEED            = 0x30;
00177   static const unsigned char VISCA_ZOOM_VALUE                   = 0x47;
00178   static const unsigned char VISCA_ZOOM_FOCUS_VALUE             = 0x47;
00179   static const unsigned char VISCA_DZOOM                        = 0x06;
00180   static const unsigned char   VISCA_DZOOM_ON                   = 0x02;
00181   static const unsigned char   VISCA_DZOOM_OFF                  = 0x03;
00182   static const unsigned char VISCA_FOCUS                        = 0x08;
00183   static const unsigned char   VISCA_FOCUS_STOP                 = 0x00;
00184   static const unsigned char   VISCA_FOCUS_FAR                  = 0x02;
00185   static const unsigned char   VISCA_FOCUS_NEAR                 = 0x03;
00186   static const unsigned char   VISCA_FOCUS_FAR_SPEED            = 0x20;
00187   static const unsigned char   VISCA_FOCUS_NEAR_SPEED           = 0x30;
00188   static const unsigned char VISCA_FOCUS_VALUE                  = 0x48;
00189   static const unsigned char VISCA_FOCUS_AUTO                   = 0x38;
00190   static const unsigned char   VISCA_FOCUS_AUTO_MAN             = 0x10;
00191   static const unsigned char VISCA_FOCUS_ONE_PUSH               = 0x18;
00192   static const unsigned char   VISCA_FOCUS_ONE_PUSH_TRIG        = 0x01;
00193   static const unsigned char   VISCA_FOCUS_ONE_PUSH_INF         = 0x02;
00194   static const unsigned char VISCA_FOCUS_AUTO_SENSE             = 0x58;
00195   static const unsigned char   VISCA_FOCUS_AUTO_SENSE_HIGH      = 0x02;
00196   static const unsigned char   VISCA_FOCUS_AUTO_SENSE_LOW       = 0x03;
00197   static const unsigned char VISCA_FOCUS_NEAR_LIMIT             = 0x28;
00198   static const unsigned char VISCA_WB                           = 0x35;
00199   static const unsigned char   VISCA_WB_AUTO                    = 0x00;
00200   static const unsigned char   VISCA_WB_INDOOR                  = 0x01;
00201   static const unsigned char   VISCA_WB_OUTDOOR                 = 0x02;
00202   static const unsigned char   VISCA_WB_ONE_PUSH                = 0x03;
00203   static const unsigned char   VISCA_WB_ATW                     = 0x04;
00204   static const unsigned char   VISCA_WB_MANUAL                  = 0x05;
00205   static const unsigned char   VISCA_WB_ONE_PUSH_TRIG           = 0x05;
00206   static const unsigned char VISCA_RGAIN                        = 0x03;
00207   static const unsigned char VISCA_RGAIN_VALUE                  = 0x43;
00208   static const unsigned char VISCA_BGAIN                        = 0x04;
00209   static const unsigned char VISCA_BGAIN_VALUE                  = 0x44;
00210   static const unsigned char VISCA_AUTO_EXP                     = 0x39;
00211   static const unsigned char   VISCA_AUTO_EXP_FULL_AUTO         = 0x00;
00212   static const unsigned char   VISCA_AUTO_EXP_MANUAL            = 0x03;
00213   static const unsigned char   VISCA_AUTO_EXP_SHUTTER_PRIORITY  = 0x0A;
00214   static const unsigned char   VISCA_AUTO_EXP_IRIS_PRIORITY     = 0x0B;
00215   static const unsigned char   VISCA_AUTO_EXP_GAIN_PRIORITY     = 0x0C;
00216   static const unsigned char   VISCA_AUTO_EXP_BRIGHT            = 0x0D;
00217   static const unsigned char   VISCA_AUTO_EXP_SHUTTER_AUTO      = 0x1A;
00218   static const unsigned char   VISCA_AUTO_EXP_IRIS_AUTO         = 0x1B;
00219   static const unsigned char   VISCA_AUTO_EXP_GAIN_AUTO         = 0x1C;
00220   static const unsigned char VISCA_SLOW_SHUTTER                 = 0x5A;
00221   static const unsigned char   VISCA_SLOW_SHUTTER_AUTO          = 0x02;
00222   static const unsigned char   VISCA_SLOW_SHUTTER_MANUAL        = 0x03;
00223   static const unsigned char VISCA_SHUTTER                      = 0x0A;
00224   static const unsigned char VISCA_SHUTTER_VALUE                = 0x4A;
00225   static const unsigned char VISCA_IRIS                         = 0x0B;
00226   static const unsigned char VISCA_IRIS_VALUE                   = 0x4B;
00227   static const unsigned char VISCA_GAIN                         = 0x0C;
00228   static const unsigned char VISCA_GAIN_VALUE                   = 0x4C;
00229   static const unsigned char VISCA_BRIGHT                       = 0x0D;
00230   static const unsigned char VISCA_BRIGHT_VALUE                 = 0x4D;
00231   static const unsigned char VISCA_EXP_COMP                     = 0x0E;
00232   static const unsigned char VISCA_EXP_COMP_POWER               = 0x3E;
00233   static const unsigned char VISCA_EXP_COMP_VALUE               = 0x4E;
00234   static const unsigned char VISCA_BACKLIGHT_COMP               = 0x33;
00235   static const unsigned char VISCA_APERTURE                     = 0x02;
00236   static const unsigned char VISCA_APERTURE_VALUE               = 0x42;
00237   static const unsigned char VISCA_ZERO_LUX                     = 0x01;
00238   static const unsigned char VISCA_IR_LED                       = 0x31;
00239   static const unsigned char VISCA_WIDE_MODE                    = 0x60;
00240   static const unsigned char   VISCA_WIDE_MODE_OFF              = 0x00;
00241   static const unsigned char   VISCA_WIDE_MODE_CINEMA           = 0x01;
00242   static const unsigned char   VISCA_WIDE_MODE_16_9             = 0x02;
00243   static const unsigned char VISCA_MIRROR                       = 0x61;
00244   static const unsigned char VISCA_FREEZE                       = 0x62;
00245   static const unsigned char VISCA_PICTURE_EFFECT               = 0x63;
00246   static const unsigned char   VISCA_PICTURE_EFFECT_OFF         = 0x00;
00247   static const unsigned char   VISCA_PICTURE_EFFECT_PASTEL      = 0x01;
00248   static const unsigned char   VISCA_PICTURE_EFFECT_NEGATIVE    = 0x02;
00249   static const unsigned char   VISCA_PICTURE_EFFECT_SEPIA       = 0x03;
00250   static const unsigned char   VISCA_PICTURE_EFFECT_BW          = 0x04;
00251   static const unsigned char   VISCA_PICTURE_EFFECT_SOLARIZE    = 0x05;
00252   static const unsigned char   VISCA_PICTURE_EFFECT_MOSAIC      = 0x06;
00253   static const unsigned char   VISCA_PICTURE_EFFECT_SLIM        = 0x07;
00254   static const unsigned char   VISCA_PICTURE_EFFECT_STRETCH     = 0x08;
00255   static const unsigned char VISCA_DIGITAL_EFFECT               = 0x64;
00256   static const unsigned char   VISCA_DIGITAL_EFFECT_OFF         = 0x00;
00257   static const unsigned char   VISCA_DIGITAL_EFFECT_STILL       = 0x01;
00258   static const unsigned char   VISCA_DIGITAL_EFFECT_FLASH       = 0x02;
00259   static const unsigned char   VISCA_DIGITAL_EFFECT_LUMI        = 0x03;
00260   static const unsigned char   VISCA_DIGITAL_EFFECT_TRAIL       = 0x04;
00261   static const unsigned char VISCA_DIGITAL_EFFECT_LEVEL         = 0x65;
00262   static const unsigned char VISCA_MEMORY                       = 0x3F;
00263   static const unsigned char   VISCA_MEMORY_RESET               = 0x00;
00264   static const unsigned char   VISCA_MEMORY_SET                 = 0x01;
00265   static const unsigned char   VISCA_MEMORY_RECALL              = 0x02;
00266   static const unsigned char VISCA_DISPLAY                      = 0x15;
00267   static const unsigned char   VISCA_DISPLAY_TOGGLE             = 0x10;
00268   static const unsigned char VISCA_DATE_TIME_SET                = 0x70;
00269   static const unsigned char VISCA_DATE_DISPLAY                 = 0x71;
00270   static const unsigned char VISCA_TIME_DISPLAY                 = 0x72;
00271   static const unsigned char VISCA_TITLE_DISPLAY                = 0x74;
00272   static const unsigned char   VISCA_TITLE_DISPLAY_CLEAR        = 0x00;
00273   static const unsigned char VISCA_TITLE_SET                    = 0x73;
00274   static const unsigned char   VISCA_TITLE_SET_PARAMS           = 0x00;
00275   static const unsigned char   VISCA_TITLE_SET_PART1            = 0x01;
00276   static const unsigned char   VISCA_TITLE_SET_PART2            = 0x02;
00277   static const unsigned char VISCA_IRRECEIVE                    = 0x08;
00278   static const unsigned char   VISCA_IRRECEIVE_ON               = 0x02;
00279   static const unsigned char   VISCA_IRRECEIVE_OFF              = 0x03;
00280   static const unsigned char   VISCA_IRRECEIVE_ONOFF            = 0x10;
00281   static const unsigned char VISCA_PT_DRIVE                     = 0x01;
00282   static const unsigned char   VISCA_PT_DRIVE_HORIZ_LEFT        = 0x01;
00283   static const unsigned char   VISCA_PT_DRIVE_HORIZ_RIGHT       = 0x02;
00284   static const unsigned char   VISCA_PT_DRIVE_HORIZ_STOP        = 0x03;
00285   static const unsigned char   VISCA_PT_DRIVE_VERT_UP           = 0x01;
00286   static const unsigned char   VISCA_PT_DRIVE_VERT_DOWN         = 0x02;
00287   static const unsigned char   VISCA_PT_DRIVE_VERT_STOP         = 0x03;
00288   static const unsigned char VISCA_PT_ABSOLUTE_POSITION         = 0x02;
00289   static const unsigned char VISCA_PT_RELATIVE_POSITION         = 0x03;
00290   static const unsigned char VISCA_PT_HOME                      = 0x04;
00291   static const unsigned char VISCA_PT_RESET                     = 0x05;
00292   static const unsigned char VISCA_PT_LIMITSET                  = 0x07;
00293   static const unsigned char   VISCA_PT_LIMITSET_SET            = 0x00;
00294   static const unsigned char   VISCA_PT_LIMITSET_CLEAR          = 0x01;
00295   static const unsigned char     VISCA_PT_LIMITSET_SET_UR       = 0x01;
00296   static const unsigned char     VISCA_PT_LIMITSET_SET_DL       = 0x00;
00297   static const unsigned char VISCA_PT_DATASCREEN                = 0x06;
00298   static const unsigned char   VISCA_PT_DATASCREEN_ON           = 0x02;
00299   static const unsigned char   VISCA_PT_DATASCREEN_OFF          = 0x03;
00300   static const unsigned char   VISCA_PT_DATASCREEN_ONOFF        = 0x10;
00301   static const unsigned char VISCA_PT_VIDEOSYSTEM_INQ           = 0x23;
00302   static const unsigned char VISCA_PT_MODE_INQ                  = 0x10;
00303   static const unsigned char VISCA_PT_MAXSPEED_INQ              = 0x11;
00304   static const unsigned char VISCA_PT_POSITION_INQ              = 0x12;
00305   static const unsigned char VISCA_PT_DATASCREEN_INQ            = 0x06;
00306   /*****************/
00307   /* D30/D31 CODES */
00308   /*****************/
00309   static const unsigned char VISCA_WIDE_CON_LENS                = 0x26;
00310   static const unsigned char   VISCA_WIDE_CON_LENS_SET          = 0x00;
00311 
00312   static const unsigned char VISCA_AT_MODE                      = 0x01;
00313   static const unsigned char   VISCA_AT_ONOFF                   = 0x10;
00314   static const unsigned char VISCA_AT_AE                        = 0x02;
00315   static const unsigned char VISCA_AT_AUTOZOOM                  = 0x03;
00316   static const unsigned char VISCA_ATMD_FRAMEDISPLAY            = 0x04;
00317   static const unsigned char VISCA_AT_FRAMEOFFSET               = 0x05;
00318   static const unsigned char VISCA_ATMD_STARTSTOP               = 0x06;
00319   static const unsigned char VISCA_AT_CHASE                     = 0x07;
00320   static const unsigned char   VISCA_AT_CHASE_NEXT              = 0x10;
00321 
00322   static const unsigned char VISCA_MD_MODE                      = 0x08;
00323   static const unsigned char   VISCA_MD_ONOFF                   = 0x10;
00324   static const unsigned char VISCA_MD_FRAME                     = 0x09;
00325   static const unsigned char VISCA_MD_DETECT                    = 0x0A;
00326 
00327   static const unsigned char VISCA_MD_ADJUST                    = 0x00;
00328   static const unsigned char   VISCA_MD_ADJUST_YLEVEL           = 0x0B;
00329   static const unsigned char   VISCA_MD_ADJUST_HUELEVEL         = 0x0C;
00330   static const unsigned char   VISCA_MD_ADJUST_SIZE             = 0x0D;
00331   static const unsigned char   VISCA_MD_ADJUST_DISPTIME         = 0x0F;
00332   static const unsigned char   VISCA_MD_ADJUST_REFTIME          = 0x0B;
00333   static const unsigned char   VISCA_MD_ADJUST_REFMODE          = 0x10;
00334 
00335   static const unsigned char VISCA_AT_ENTRY                     = 0x15;
00336   static const unsigned char VISCA_AT_LOSTINFO                  = 0x20;
00337   static const unsigned char VISCA_MD_LOSTINFO                  = 0x21;
00338   static const unsigned char VISCA_ATMD_LOSTINFO1               = 0x20;
00339   static const unsigned char VISCA_ATMD_LOSTINFO2               = 0x07;
00340 
00341   static const unsigned char VISCA_MD_MEASURE_MODE_1            = 0x27;
00342   static const unsigned char VISCA_MD_MEASURE_MODE_2            = 0x28;
00343 
00344   static const unsigned char VISCA_ATMD_MODE                    = 0x22;
00345   static const unsigned char VISCA_AT_MODE_QUERY                = 0x23;
00346   static const unsigned char VISCA_MD_MODE_QUERY                = 0x24;
00347   static const unsigned char VISCA_MD_REFTIME_QUERY             = 0x11;
00348   static const unsigned char VISCA_AT_POSITION                  = 0x20;
00349   static const unsigned char VISCA_MD_POSITION                  = 0x21;
00350 
00351   static const unsigned int  VISCA_NONBLOCKING_PANTILT          = 0;
00352   static const unsigned int  VISCA_NONBLOCKING_ZOOM             = 1;
00353   static const unsigned int  VISCA_NONBLOCKING_NUM              = 2;
00354 
00355   void         recv_packet(unsigned int max_wait_ms = 10);
00356   void         handle_response();
00357   void         finish_nonblocking(unsigned int socket);
00358 
00359   int  dev;
00360   bool opened;
00361 
00362   unsigned int inquire;
00363 
00364   // Visca specific
00365   unsigned char recipient;
00366   unsigned char sender;
00367 
00368   unsigned char obuffer[16];
00369   unsigned char ibuffer[1024];
00370   int  obuffer_length;
00371   int  ibuffer_length;
00372 
00373   unsigned int num_commands_running;
00374   bool         blocking;
00375   bool         nonblocking_running[2];
00376   unsigned int nonblocking_sockets[2];
00377 #ifdef TIMETRACKER_VISCA
00378   fawkes::TimeTracker    *tracker;
00379   std::ofstream   track_file;
00380   unsigned int    ttcls_pantilt_get_send;
00381   unsigned int    ttcls_pantilt_get_read;
00382   unsigned int    ttcls_pantilt_get_handle;
00383   unsigned int    ttcls_pantilt_get_interpret;
00384 #endif
00385 
00386 };
00387 
00388 } // end namespace firevision
00389 
00390 #endif

Generated on Tue Feb 22 13:32:14 2011 for Fawkes API by  doxygen 1.4.7