Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * visca.h - Class for accessing visca cams 00004 * 00005 * Created: Wed Jun 08 12:06:15 2005 (FireVision) 00006 * Copyright 2005-2009 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 __PLUGINS_PANTILT_SONY_VISCA_H_ 00025 #define __PLUGINS_PANTILT_SONY_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 class ViscaException : public fawkes::Exception 00038 { 00039 public: 00040 ViscaException(const char *msg); 00041 ViscaException(const char *msg, const int _errno); 00042 }; 00043 00044 class ViscaInquiryRunningException : public ViscaException 00045 { 00046 public: 00047 ViscaInquiryRunningException(); 00048 }; 00049 00050 00051 class Visca { 00052 00053 public: 00054 static const unsigned int VISCA_WHITEBLANCE_AUTO; 00055 static const unsigned int VISCA_WHITEBALANCE_INDOOR; 00056 static const unsigned int VISCA_WHITEBALANCE_OUTDOOR; 00057 static const unsigned int VISCA_WHITEBALANCE_ONE_PUSH; 00058 static const unsigned int VISCA_WHITEBALANCE_ATW; 00059 static const unsigned int VISCA_WHITEBALANCE_MANUAL; 00060 00061 static const unsigned int NONBLOCKING_PANTILT; 00062 static const unsigned int NONBLOCKING_ZOOM; 00063 static const unsigned int NONBLOCKING_NUM; 00064 00065 static const unsigned int MAX_PAN_SPEED; 00066 static const unsigned int MAX_TILT_SPEED; 00067 00068 Visca(const char *device_file, unsigned int def_timeout_ms = 10, 00069 bool blocking = true); 00070 virtual ~Visca(); 00071 00072 void open(); 00073 void close(); 00074 00075 // basic communication 00076 void set_address(); 00077 void clear(); 00078 00079 // low level 00080 void send(); 00081 void recv(unsigned int timeout_ms = 0xFFFFFFFF); 00082 void recv_ack(unsigned int *socket = NULL); 00083 void send_with_reply(); 00084 void send_nonblocking(unsigned int *socket = NULL); 00085 void cancel_command(unsigned int socket); 00086 bool data_available(); 00087 void process(); 00088 00089 // pan tilt stuff 00090 void reset_pan_tilt(); 00091 /** Query for pan/tilt but do not wait until finished 00092 * This will send an inquire to the camera that asks for pan/tilt values but 00093 * it does not wait for the data! A later call to getPanTilt will then block and 00094 * wait until the results arrive. 00095 * Not that you can _not_ run another inquire (get*) method until this call has 00096 * finished! You will get VISCA_E_INQRUNNING as error message. 00097 */ 00098 void start_get_pan_tilt(); 00099 void set_pan_tilt(int pan, int tilt); 00100 void get_pan_tilt(int &pan, int &tilt); 00101 void set_pan_tilt_limit(int pan_left, int pan_right, int tilt_up, int tilt_down); 00102 void reset_pan_tilt_limit(); 00103 void set_pan_tilt_speed(unsigned char pan_speed, unsigned char tilt_speed); 00104 void get_pan_tilt_speed(unsigned char &pan_speed, unsigned char &tilt_speed); 00105 00106 bool is_nonblocking_finished(unsigned int item) const; 00107 00108 // zoom 00109 void reset_zoom(); 00110 void set_zoom(unsigned int zoom); 00111 void get_zoom(unsigned int *zoom); 00112 void set_zoom_speed_tele(unsigned int speed); 00113 void set_zoom_speed_wide(unsigned int speed); 00114 void set_zoom_digital_enabled(bool enabled); 00115 00116 // effects, just to play with... 00117 void reset_effect(); 00118 void apply_effect(unsigned char effect); 00119 void apply_effect_pastel(); 00120 void apply_effect_neg_art(); 00121 void apply_effect_sepia(); 00122 void apply_effect_bnw(); 00123 void apply_effect_solarize(); 00124 void apply_effect_mosaic(); 00125 void apply_effect_slim(); 00126 void apply_effect_stretch(); 00127 00128 unsigned int get_white_balance_mode(); 00129 00130 private: 00131 // possible running inquires 00132 static const unsigned int VISCA_RUNINQ_NONE = 0; 00133 static const unsigned int VISCA_RUNINQ_PANTILT = 1; 00134 00135 // Cameras 00136 static const unsigned char VISCA_BUS_0 = 0; 00137 static const unsigned char VISCA_BUS_1 = 1; 00138 static const unsigned char VISCA_BUS_2 = 2; 00139 static const unsigned char VISCA_BUS_3 = 3; 00140 static const unsigned char VISCA_BUS_4 = 4; 00141 static const unsigned char VISCA_BUS_5 = 5; 00142 static const unsigned char VISCA_BUS_6 = 6; 00143 static const unsigned char VISCA_BUS_7 = 7; 00144 static const unsigned char VISCA_BUS_BROADCAST = 8; 00145 00146 // basic formatting 00147 static const unsigned char VISCA_COMMAND = 0x01; 00148 static const unsigned char VISCA_CANCEL = 0x20; 00149 static const unsigned char VISCA_INQUIRY = 0x09; 00150 static const unsigned char VISCA_TERMINATOR = 0xFF; 00151 00152 // response types 00153 static const unsigned char VISCA_RESPONSE_CLEAR = 0x40; 00154 static const unsigned char VISCA_RESPONSE_ADDRESS = 0x30; 00155 static const unsigned char VISCA_RESPONSE_ACK = 0x40; 00156 static const unsigned char VISCA_RESPONSE_COMPLETED = 0x50; 00157 static const unsigned char VISCA_RESPONSE_ERROR = 0x60; 00158 00159 // errors 00160 static const unsigned char VISCA_ERROR_LENGTH = 0x01; 00161 static const unsigned char VISCA_ERROR_SYNTAX = 0x02; 00162 static const unsigned char VISCA_ERROR_BUFFERFULL = 0x03; 00163 static const unsigned char VISCA_ERROR_CANCELLED = 0x04; 00164 static const unsigned char VISCA_ERROR_NOSOCKET = 0x05; 00165 static const unsigned char VISCA_ERROR_NOTEXECABLE = 0x41; 00166 00167 00168 // categories 00169 static const unsigned char VISCA_CATEGORY_INTERFACE = 0x00; 00170 static const unsigned char VISCA_CATEGORY_CAMERA1 = 0x04; 00171 static const unsigned char VISCA_CATEGORY_PAN_TILTER = 0x06; 00172 static const unsigned char VISCA_CATEGORY_CAMERA2 = 0x07; 00173 00174 static const unsigned char VISCA_POWER = 0x00; 00175 static const unsigned char VISCA_DEVICE_INFO = 0x02; 00176 static const unsigned char VISCA_KEYLOCK = 0x17; 00177 static const unsigned char VISCA_ID = 0x22; 00178 static const unsigned char VISCA_ZOOM = 0x07; 00179 static const unsigned char VISCA_ZOOM_STOP = 0x00; 00180 static const unsigned char VISCA_ZOOM_TELE = 0x02; 00181 static const unsigned char VISCA_ZOOM_WIDE = 0x03; 00182 static const unsigned char VISCA_ZOOM_TELE_SPEED = 0x20; 00183 static const unsigned char VISCA_ZOOM_WIDE_SPEED = 0x30; 00184 static const unsigned char VISCA_ZOOM_VALUE = 0x47; 00185 static const unsigned char VISCA_ZOOM_FOCUS_VALUE = 0x47; 00186 static const unsigned char VISCA_DZOOM = 0x06; 00187 static const unsigned char VISCA_DZOOM_ON = 0x02; 00188 static const unsigned char VISCA_DZOOM_OFF = 0x03; 00189 static const unsigned char VISCA_FOCUS = 0x08; 00190 static const unsigned char VISCA_FOCUS_STOP = 0x00; 00191 static const unsigned char VISCA_FOCUS_FAR = 0x02; 00192 static const unsigned char VISCA_FOCUS_NEAR = 0x03; 00193 static const unsigned char VISCA_FOCUS_FAR_SPEED = 0x20; 00194 static const unsigned char VISCA_FOCUS_NEAR_SPEED = 0x30; 00195 static const unsigned char VISCA_FOCUS_VALUE = 0x48; 00196 static const unsigned char VISCA_FOCUS_AUTO = 0x38; 00197 static const unsigned char VISCA_FOCUS_AUTO_MAN = 0x10; 00198 static const unsigned char VISCA_FOCUS_ONE_PUSH = 0x18; 00199 static const unsigned char VISCA_FOCUS_ONE_PUSH_TRIG = 0x01; 00200 static const unsigned char VISCA_FOCUS_ONE_PUSH_INF = 0x02; 00201 static const unsigned char VISCA_FOCUS_AUTO_SENSE = 0x58; 00202 static const unsigned char VISCA_FOCUS_AUTO_SENSE_HIGH = 0x02; 00203 static const unsigned char VISCA_FOCUS_AUTO_SENSE_LOW = 0x03; 00204 static const unsigned char VISCA_FOCUS_NEAR_LIMIT = 0x28; 00205 static const unsigned char VISCA_WB = 0x35; 00206 static const unsigned char VISCA_WB_AUTO = 0x00; 00207 static const unsigned char VISCA_WB_INDOOR = 0x01; 00208 static const unsigned char VISCA_WB_OUTDOOR = 0x02; 00209 static const unsigned char VISCA_WB_ONE_PUSH = 0x03; 00210 static const unsigned char VISCA_WB_ATW = 0x04; 00211 static const unsigned char VISCA_WB_MANUAL = 0x05; 00212 static const unsigned char VISCA_WB_ONE_PUSH_TRIG = 0x05; 00213 static const unsigned char VISCA_RGAIN = 0x03; 00214 static const unsigned char VISCA_RGAIN_VALUE = 0x43; 00215 static const unsigned char VISCA_BGAIN = 0x04; 00216 static const unsigned char VISCA_BGAIN_VALUE = 0x44; 00217 static const unsigned char VISCA_AUTO_EXP = 0x39; 00218 static const unsigned char VISCA_AUTO_EXP_FULL_AUTO = 0x00; 00219 static const unsigned char VISCA_AUTO_EXP_MANUAL = 0x03; 00220 static const unsigned char VISCA_AUTO_EXP_SHUTTER_PRIORITY = 0x0A; 00221 static const unsigned char VISCA_AUTO_EXP_IRIS_PRIORITY = 0x0B; 00222 static const unsigned char VISCA_AUTO_EXP_GAIN_PRIORITY = 0x0C; 00223 static const unsigned char VISCA_AUTO_EXP_BRIGHT = 0x0D; 00224 static const unsigned char VISCA_AUTO_EXP_SHUTTER_AUTO = 0x1A; 00225 static const unsigned char VISCA_AUTO_EXP_IRIS_AUTO = 0x1B; 00226 static const unsigned char VISCA_AUTO_EXP_GAIN_AUTO = 0x1C; 00227 static const unsigned char VISCA_SLOW_SHUTTER = 0x5A; 00228 static const unsigned char VISCA_SLOW_SHUTTER_AUTO = 0x02; 00229 static const unsigned char VISCA_SLOW_SHUTTER_MANUAL = 0x03; 00230 static const unsigned char VISCA_SHUTTER = 0x0A; 00231 static const unsigned char VISCA_SHUTTER_VALUE = 0x4A; 00232 static const unsigned char VISCA_IRIS = 0x0B; 00233 static const unsigned char VISCA_IRIS_VALUE = 0x4B; 00234 static const unsigned char VISCA_GAIN = 0x0C; 00235 static const unsigned char VISCA_GAIN_VALUE = 0x4C; 00236 static const unsigned char VISCA_BRIGHT = 0x0D; 00237 static const unsigned char VISCA_BRIGHT_VALUE = 0x4D; 00238 static const unsigned char VISCA_EXP_COMP = 0x0E; 00239 static const unsigned char VISCA_EXP_COMP_POWER = 0x3E; 00240 static const unsigned char VISCA_EXP_COMP_VALUE = 0x4E; 00241 static const unsigned char VISCA_BACKLIGHT_COMP = 0x33; 00242 static const unsigned char VISCA_APERTURE = 0x02; 00243 static const unsigned char VISCA_APERTURE_VALUE = 0x42; 00244 static const unsigned char VISCA_ZERO_LUX = 0x01; 00245 static const unsigned char VISCA_IR_LED = 0x31; 00246 static const unsigned char VISCA_WIDE_MODE = 0x60; 00247 static const unsigned char VISCA_WIDE_MODE_OFF = 0x00; 00248 static const unsigned char VISCA_WIDE_MODE_CINEMA = 0x01; 00249 static const unsigned char VISCA_WIDE_MODE_16_9 = 0x02; 00250 static const unsigned char VISCA_MIRROR = 0x61; 00251 static const unsigned char VISCA_FREEZE = 0x62; 00252 static const unsigned char VISCA_PICTURE_EFFECT = 0x63; 00253 static const unsigned char VISCA_PICTURE_EFFECT_OFF = 0x00; 00254 static const unsigned char VISCA_PICTURE_EFFECT_PASTEL = 0x01; 00255 static const unsigned char VISCA_PICTURE_EFFECT_NEGATIVE = 0x02; 00256 static const unsigned char VISCA_PICTURE_EFFECT_SEPIA = 0x03; 00257 static const unsigned char VISCA_PICTURE_EFFECT_BW = 0x04; 00258 static const unsigned char VISCA_PICTURE_EFFECT_SOLARIZE = 0x05; 00259 static const unsigned char VISCA_PICTURE_EFFECT_MOSAIC = 0x06; 00260 static const unsigned char VISCA_PICTURE_EFFECT_SLIM = 0x07; 00261 static const unsigned char VISCA_PICTURE_EFFECT_STRETCH = 0x08; 00262 static const unsigned char VISCA_DIGITAL_EFFECT = 0x64; 00263 static const unsigned char VISCA_DIGITAL_EFFECT_OFF = 0x00; 00264 static const unsigned char VISCA_DIGITAL_EFFECT_STILL = 0x01; 00265 static const unsigned char VISCA_DIGITAL_EFFECT_FLASH = 0x02; 00266 static const unsigned char VISCA_DIGITAL_EFFECT_LUMI = 0x03; 00267 static const unsigned char VISCA_DIGITAL_EFFECT_TRAIL = 0x04; 00268 static const unsigned char VISCA_DIGITAL_EFFECT_LEVEL = 0x65; 00269 static const unsigned char VISCA_MEMORY = 0x3F; 00270 static const unsigned char VISCA_MEMORY_RESET = 0x00; 00271 static const unsigned char VISCA_MEMORY_SET = 0x01; 00272 static const unsigned char VISCA_MEMORY_RECALL = 0x02; 00273 static const unsigned char VISCA_DISPLAY = 0x15; 00274 static const unsigned char VISCA_DISPLAY_TOGGLE = 0x10; 00275 static const unsigned char VISCA_DATE_TIME_SET = 0x70; 00276 static const unsigned char VISCA_DATE_DISPLAY = 0x71; 00277 static const unsigned char VISCA_TIME_DISPLAY = 0x72; 00278 static const unsigned char VISCA_TITLE_DISPLAY = 0x74; 00279 static const unsigned char VISCA_TITLE_DISPLAY_CLEAR = 0x00; 00280 static const unsigned char VISCA_TITLE_SET = 0x73; 00281 static const unsigned char VISCA_TITLE_SET_PARAMS = 0x00; 00282 static const unsigned char VISCA_TITLE_SET_PART1 = 0x01; 00283 static const unsigned char VISCA_TITLE_SET_PART2 = 0x02; 00284 static const unsigned char VISCA_IRRECEIVE = 0x08; 00285 static const unsigned char VISCA_IRRECEIVE_ON = 0x02; 00286 static const unsigned char VISCA_IRRECEIVE_OFF = 0x03; 00287 static const unsigned char VISCA_IRRECEIVE_ONOFF = 0x10; 00288 static const unsigned char VISCA_PT_DRIVE = 0x01; 00289 static const unsigned char VISCA_PT_DRIVE_HORIZ_LEFT = 0x01; 00290 static const unsigned char VISCA_PT_DRIVE_HORIZ_RIGHT = 0x02; 00291 static const unsigned char VISCA_PT_DRIVE_HORIZ_STOP = 0x03; 00292 static const unsigned char VISCA_PT_DRIVE_VERT_UP = 0x01; 00293 static const unsigned char VISCA_PT_DRIVE_VERT_DOWN = 0x02; 00294 static const unsigned char VISCA_PT_DRIVE_VERT_STOP = 0x03; 00295 static const unsigned char VISCA_PT_ABSOLUTE_POSITION = 0x02; 00296 static const unsigned char VISCA_PT_RELATIVE_POSITION = 0x03; 00297 static const unsigned char VISCA_PT_HOME = 0x04; 00298 static const unsigned char VISCA_PT_RESET = 0x05; 00299 static const unsigned char VISCA_PT_LIMITSET = 0x07; 00300 static const unsigned char VISCA_PT_LIMITSET_SET = 0x00; 00301 static const unsigned char VISCA_PT_LIMITSET_CLEAR = 0x01; 00302 static const unsigned char VISCA_PT_LIMITSET_SET_UR = 0x01; 00303 static const unsigned char VISCA_PT_LIMITSET_SET_DL = 0x00; 00304 static const unsigned char VISCA_PT_DATASCREEN = 0x06; 00305 static const unsigned char VISCA_PT_DATASCREEN_ON = 0x02; 00306 static const unsigned char VISCA_PT_DATASCREEN_OFF = 0x03; 00307 static const unsigned char VISCA_PT_DATASCREEN_ONOFF = 0x10; 00308 static const unsigned char VISCA_PT_VIDEOSYSTEM_INQ = 0x23; 00309 static const unsigned char VISCA_PT_MODE_INQ = 0x10; 00310 static const unsigned char VISCA_PT_MAXSPEED_INQ = 0x11; 00311 static const unsigned char VISCA_PT_POSITION_INQ = 0x12; 00312 static const unsigned char VISCA_PT_DATASCREEN_INQ = 0x06; 00313 /*****************/ 00314 /* D30/D31 CODES */ 00315 /*****************/ 00316 static const unsigned char VISCA_WIDE_CON_LENS = 0x26; 00317 static const unsigned char VISCA_WIDE_CON_LENS_SET = 0x00; 00318 00319 static const unsigned char VISCA_AT_MODE = 0x01; 00320 static const unsigned char VISCA_AT_ONOFF = 0x10; 00321 static const unsigned char VISCA_AT_AE = 0x02; 00322 static const unsigned char VISCA_AT_AUTOZOOM = 0x03; 00323 static const unsigned char VISCA_ATMD_FRAMEDISPLAY = 0x04; 00324 static const unsigned char VISCA_AT_FRAMEOFFSET = 0x05; 00325 static const unsigned char VISCA_ATMD_STARTSTOP = 0x06; 00326 static const unsigned char VISCA_AT_CHASE = 0x07; 00327 static const unsigned char VISCA_AT_CHASE_NEXT = 0x10; 00328 00329 static const unsigned char VISCA_MD_MODE = 0x08; 00330 static const unsigned char VISCA_MD_ONOFF = 0x10; 00331 static const unsigned char VISCA_MD_FRAME = 0x09; 00332 static const unsigned char VISCA_MD_DETECT = 0x0A; 00333 00334 static const unsigned char VISCA_MD_ADJUST = 0x00; 00335 static const unsigned char VISCA_MD_ADJUST_YLEVEL = 0x0B; 00336 static const unsigned char VISCA_MD_ADJUST_HUELEVEL = 0x0C; 00337 static const unsigned char VISCA_MD_ADJUST_SIZE = 0x0D; 00338 static const unsigned char VISCA_MD_ADJUST_DISPTIME = 0x0F; 00339 static const unsigned char VISCA_MD_ADJUST_REFTIME = 0x0B; 00340 static const unsigned char VISCA_MD_ADJUST_REFMODE = 0x10; 00341 00342 static const unsigned char VISCA_AT_ENTRY = 0x15; 00343 static const unsigned char VISCA_AT_LOSTINFO = 0x20; 00344 static const unsigned char VISCA_MD_LOSTINFO = 0x21; 00345 static const unsigned char VISCA_ATMD_LOSTINFO1 = 0x20; 00346 static const unsigned char VISCA_ATMD_LOSTINFO2 = 0x07; 00347 00348 static const unsigned char VISCA_MD_MEASURE_MODE_1 = 0x27; 00349 static const unsigned char VISCA_MD_MEASURE_MODE_2 = 0x28; 00350 00351 static const unsigned char VISCA_ATMD_MODE = 0x22; 00352 static const unsigned char VISCA_AT_MODE_QUERY = 0x23; 00353 static const unsigned char VISCA_MD_MODE_QUERY = 0x24; 00354 static const unsigned char VISCA_MD_REFTIME_QUERY = 0x11; 00355 static const unsigned char VISCA_AT_POSITION = 0x20; 00356 static const unsigned char VISCA_MD_POSITION = 0x21; 00357 00358 void recv_packet(unsigned int timeout_ms); 00359 void handle_response(); 00360 void finish_nonblocking(unsigned int socket); 00361 00362 char *__device_file; 00363 int __fd; 00364 bool __opened; 00365 unsigned int __default_timeout_ms; 00366 00367 unsigned int __inquire; 00368 00369 unsigned char __recipient; 00370 unsigned char __sender; 00371 00372 unsigned char __obuffer[16]; 00373 unsigned char __ibuffer[1024]; 00374 int __obuffer_length; 00375 int __ibuffer_length; 00376 00377 bool __blocking; 00378 bool __nonblocking_running[2]; 00379 unsigned int __nonblocking_sockets[2]; 00380 00381 unsigned char __pan_speed; 00382 unsigned char __tilt_speed; 00383 00384 #ifdef TIMETRACKER_VISCA 00385 fawkes::TimeTracker *__tt; 00386 unsigned int __ttc_pantilt_get_send; 00387 unsigned int __ttc_pantilt_get_read; 00388 unsigned int __ttc_pantilt_get_handle; 00389 unsigned int __ttc_pantilt_get_interpret; 00390 #endif 00391 00392 }; 00393 00394 00395 00396 #endif