Fawkes API  Fawkes Development Version
visca.h
1 
2 /***************************************************************************
3  * visca.h - Class for accessing visca cams
4  *
5  * Generated: Wed Jun 08 12:06:15 2005
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FIREVISION_CONTROL_VISCA_H_
25 #define __FIREVISION_CONTROL_VISCA_H_
26 
27 #include <core/exception.h>
28 
29 #ifdef TIMETRACKER_VISCA
30 # warning Visca time tracker enabled
31 # include <utils/timetracker.h>
32 # include <fstream>
33 #endif
34 
35 #include <cstddef>
36 
37 namespace firevision {
38 #if 0 /* just to make Emacs auto-indent happy */
39 }
40 #endif
41 
43 {
44  public:
45  ViscaControlException(const char *msg);
46  ViscaControlException(const char *msg, const int _errno);
47 };
48 
50 {
51  public:
53 };
54 
55 
56 class ViscaControl {
57 
58  public:
59  static const unsigned int VISCA_WHITEBLANCE_AUTO;
60  static const unsigned int VISCA_WHITEBALANCE_INDOOR;
61  static const unsigned int VISCA_WHITEBALANCE_OUTDOOR;
62  static const unsigned int VISCA_WHITEBALANCE_ONE_PUSH;
63  static const unsigned int VISCA_WHITEBALANCE_ATW;
64  static const unsigned int VISCA_WHITEBALANCE_MANUAL;
65 
66  ViscaControl(bool blocking = true);
67 
68  void open(const char *port);
69  void close();
70 
71  // basic communication
72  void set_address(unsigned int num_cameras);
73  void clear();
74 
75  // low level
76  void send();
77  void recv(unsigned int max_wait_ms = 10);
78  void recv_ack(unsigned int *socket = NULL);
79  void send_with_reply();
80  void send_nonblocking(unsigned int *socket = NULL);
81  void cancel_command(unsigned int socket);
82  bool data_available();
83  void process();
84 
85  // pan tilt stuff
86  void resetPanTilt();
87  /** Query for pan/tilt but do not wait until finished
88  * This will send an inquire to the camera that asks for pan/tilt values but
89  * it does not wait for the data! A later call to getPanTilt will then block and
90  * wait until the results arrive.
91  * Not that you can _not_ run another inquire (get*) method until this call has
92  * finished! You will get VISCA_E_INQRUNNING as error message.
93  */
94  void startGetPanTilt();
95  void setPanTilt(int pan, int tilt);
96  void getPanTilt(int *pan, int *tilt);
97  void setPanTiltLimit(int pan_left, int pan_right, int tilt_up, int tilt_down);
98  void resetPanTiltLimit();
99 
100  // zoom
101  void resetZoom();
102  void setZoom(unsigned int zoom);
103  void getZoom(unsigned int *zoom);
104  void setZoomSpeedTele(unsigned int speed);
105  void setZoomSpeedWide(unsigned int speed);
106  void setZoomDigitalEnabled(bool enabled);
107 
108  // effects, just to play with...
109  void resetEffect();
110  void applyEffect(unsigned char effect);
111  void applyEffectPastel();
112  void applyEffectNegArt();
113  void applyEffectSepia();
114  void applyEffectBnW();
115  void applyEffectSolarize();
116  void applyEffectMosaic();
117  void applyEffectSlim();
118  void applyEffectStretch();
119 
120  unsigned int getWhiteBalanceMode();
121 
122  private:
123 
124  // possible running inquires
125  static const unsigned int VISCA_RUNINQ_NONE = 0;
126  static const unsigned int VISCA_RUNINQ_PANTILT = 1;
127 
128  // Cameras
129  static const unsigned char VISCA_BUS_0 = 0;
130  static const unsigned char VISCA_BUS_1 = 1;
131  static const unsigned char VISCA_BUS_2 = 2;
132  static const unsigned char VISCA_BUS_3 = 3;
133  static const unsigned char VISCA_BUS_4 = 4;
134  static const unsigned char VISCA_BUS_5 = 5;
135  static const unsigned char VISCA_BUS_6 = 6;
136  static const unsigned char VISCA_BUS_7 = 7;
137  static const unsigned char VISCA_BUS_BROADCAST = 8;
138 
139  // basic formatting
140  static const unsigned char VISCA_COMMAND = 0x01;
141  static const unsigned char VISCA_CANCEL = 0x20;
142  static const unsigned char VISCA_INQUIRY = 0x09;
143  static const unsigned char VISCA_TERMINATOR = 0xFF;
144 
145  // response types
146  static const unsigned char VISCA_RESPONSE_CLEAR = 0x40;
147  static const unsigned char VISCA_RESPONSE_ADDRESS = 0x30;
148  static const unsigned char VISCA_RESPONSE_ACK = 0x40;
149  static const unsigned char VISCA_RESPONSE_COMPLETED = 0x50;
150  static const unsigned char VISCA_RESPONSE_ERROR = 0x60;
151 
152  // errors
153  static const unsigned char VISCA_ERROR_LENGTH = 0x01;
154  static const unsigned char VISCA_ERROR_SYNTAX = 0x02;
155  static const unsigned char VISCA_ERROR_BUFFERFULL = 0x03;
156  static const unsigned char VISCA_ERROR_CANCELLED = 0x04;
157  static const unsigned char VISCA_ERROR_NOSOCKET = 0x05;
158  static const unsigned char VISCA_ERROR_NOTEXECABLE = 0x41;
159 
160 
161  // categories
162  static const unsigned char VISCA_CATEGORY_INTERFACE = 0x00;
163  static const unsigned char VISCA_CATEGORY_CAMERA1 = 0x04;
164  static const unsigned char VISCA_CATEGORY_PAN_TILTER = 0x06;
165  static const unsigned char VISCA_CATEGORY_CAMERA2 = 0x07;
166 
167  static const unsigned char VISCA_POWER = 0x00;
168  static const unsigned char VISCA_DEVICE_INFO = 0x02;
169  static const unsigned char VISCA_KEYLOCK = 0x17;
170  static const unsigned char VISCA_ID = 0x22;
171  static const unsigned char VISCA_ZOOM = 0x07;
172  static const unsigned char VISCA_ZOOM_STOP = 0x00;
173  static const unsigned char VISCA_ZOOM_TELE = 0x02;
174  static const unsigned char VISCA_ZOOM_WIDE = 0x03;
175  static const unsigned char VISCA_ZOOM_TELE_SPEED = 0x20;
176  static const unsigned char VISCA_ZOOM_WIDE_SPEED = 0x30;
177  static const unsigned char VISCA_ZOOM_VALUE = 0x47;
178  static const unsigned char VISCA_ZOOM_FOCUS_VALUE = 0x47;
179  static const unsigned char VISCA_DZOOM = 0x06;
180  static const unsigned char VISCA_DZOOM_ON = 0x02;
181  static const unsigned char VISCA_DZOOM_OFF = 0x03;
182  static const unsigned char VISCA_FOCUS = 0x08;
183  static const unsigned char VISCA_FOCUS_STOP = 0x00;
184  static const unsigned char VISCA_FOCUS_FAR = 0x02;
185  static const unsigned char VISCA_FOCUS_NEAR = 0x03;
186  static const unsigned char VISCA_FOCUS_FAR_SPEED = 0x20;
187  static const unsigned char VISCA_FOCUS_NEAR_SPEED = 0x30;
188  static const unsigned char VISCA_FOCUS_VALUE = 0x48;
189  static const unsigned char VISCA_FOCUS_AUTO = 0x38;
190  static const unsigned char VISCA_FOCUS_AUTO_MAN = 0x10;
191  static const unsigned char VISCA_FOCUS_ONE_PUSH = 0x18;
192  static const unsigned char VISCA_FOCUS_ONE_PUSH_TRIG = 0x01;
193  static const unsigned char VISCA_FOCUS_ONE_PUSH_INF = 0x02;
194  static const unsigned char VISCA_FOCUS_AUTO_SENSE = 0x58;
195  static const unsigned char VISCA_FOCUS_AUTO_SENSE_HIGH = 0x02;
196  static const unsigned char VISCA_FOCUS_AUTO_SENSE_LOW = 0x03;
197  static const unsigned char VISCA_FOCUS_NEAR_LIMIT = 0x28;
198  static const unsigned char VISCA_WB = 0x35;
199  static const unsigned char VISCA_WB_AUTO = 0x00;
200  static const unsigned char VISCA_WB_INDOOR = 0x01;
201  static const unsigned char VISCA_WB_OUTDOOR = 0x02;
202  static const unsigned char VISCA_WB_ONE_PUSH = 0x03;
203  static const unsigned char VISCA_WB_ATW = 0x04;
204  static const unsigned char VISCA_WB_MANUAL = 0x05;
205  static const unsigned char VISCA_WB_ONE_PUSH_TRIG = 0x05;
206  static const unsigned char VISCA_RGAIN = 0x03;
207  static const unsigned char VISCA_RGAIN_VALUE = 0x43;
208  static const unsigned char VISCA_BGAIN = 0x04;
209  static const unsigned char VISCA_BGAIN_VALUE = 0x44;
210  static const unsigned char VISCA_AUTO_EXP = 0x39;
211  static const unsigned char VISCA_AUTO_EXP_FULL_AUTO = 0x00;
212  static const unsigned char VISCA_AUTO_EXP_MANUAL = 0x03;
213  static const unsigned char VISCA_AUTO_EXP_SHUTTER_PRIORITY = 0x0A;
214  static const unsigned char VISCA_AUTO_EXP_IRIS_PRIORITY = 0x0B;
215  static const unsigned char VISCA_AUTO_EXP_GAIN_PRIORITY = 0x0C;
216  static const unsigned char VISCA_AUTO_EXP_BRIGHT = 0x0D;
217  static const unsigned char VISCA_AUTO_EXP_SHUTTER_AUTO = 0x1A;
218  static const unsigned char VISCA_AUTO_EXP_IRIS_AUTO = 0x1B;
219  static const unsigned char VISCA_AUTO_EXP_GAIN_AUTO = 0x1C;
220  static const unsigned char VISCA_SLOW_SHUTTER = 0x5A;
221  static const unsigned char VISCA_SLOW_SHUTTER_AUTO = 0x02;
222  static const unsigned char VISCA_SLOW_SHUTTER_MANUAL = 0x03;
223  static const unsigned char VISCA_SHUTTER = 0x0A;
224  static const unsigned char VISCA_SHUTTER_VALUE = 0x4A;
225  static const unsigned char VISCA_IRIS = 0x0B;
226  static const unsigned char VISCA_IRIS_VALUE = 0x4B;
227  static const unsigned char VISCA_GAIN = 0x0C;
228  static const unsigned char VISCA_GAIN_VALUE = 0x4C;
229  static const unsigned char VISCA_BRIGHT = 0x0D;
230  static const unsigned char VISCA_BRIGHT_VALUE = 0x4D;
231  static const unsigned char VISCA_EXP_COMP = 0x0E;
232  static const unsigned char VISCA_EXP_COMP_POWER = 0x3E;
233  static const unsigned char VISCA_EXP_COMP_VALUE = 0x4E;
234  static const unsigned char VISCA_BACKLIGHT_COMP = 0x33;
235  static const unsigned char VISCA_APERTURE = 0x02;
236  static const unsigned char VISCA_APERTURE_VALUE = 0x42;
237  static const unsigned char VISCA_ZERO_LUX = 0x01;
238  static const unsigned char VISCA_IR_LED = 0x31;
239  static const unsigned char VISCA_WIDE_MODE = 0x60;
240  static const unsigned char VISCA_WIDE_MODE_OFF = 0x00;
241  static const unsigned char VISCA_WIDE_MODE_CINEMA = 0x01;
242  static const unsigned char VISCA_WIDE_MODE_16_9 = 0x02;
243  static const unsigned char VISCA_MIRROR = 0x61;
244  static const unsigned char VISCA_FREEZE = 0x62;
245  static const unsigned char VISCA_PICTURE_EFFECT = 0x63;
246  static const unsigned char VISCA_PICTURE_EFFECT_OFF = 0x00;
247  static const unsigned char VISCA_PICTURE_EFFECT_PASTEL = 0x01;
248  static const unsigned char VISCA_PICTURE_EFFECT_NEGATIVE = 0x02;
249  static const unsigned char VISCA_PICTURE_EFFECT_SEPIA = 0x03;
250  static const unsigned char VISCA_PICTURE_EFFECT_BW = 0x04;
251  static const unsigned char VISCA_PICTURE_EFFECT_SOLARIZE = 0x05;
252  static const unsigned char VISCA_PICTURE_EFFECT_MOSAIC = 0x06;
253  static const unsigned char VISCA_PICTURE_EFFECT_SLIM = 0x07;
254  static const unsigned char VISCA_PICTURE_EFFECT_STRETCH = 0x08;
255  static const unsigned char VISCA_DIGITAL_EFFECT = 0x64;
256  static const unsigned char VISCA_DIGITAL_EFFECT_OFF = 0x00;
257  static const unsigned char VISCA_DIGITAL_EFFECT_STILL = 0x01;
258  static const unsigned char VISCA_DIGITAL_EFFECT_FLASH = 0x02;
259  static const unsigned char VISCA_DIGITAL_EFFECT_LUMI = 0x03;
260  static const unsigned char VISCA_DIGITAL_EFFECT_TRAIL = 0x04;
261  static const unsigned char VISCA_DIGITAL_EFFECT_LEVEL = 0x65;
262  static const unsigned char VISCA_MEMORY = 0x3F;
263  static const unsigned char VISCA_MEMORY_RESET = 0x00;
264  static const unsigned char VISCA_MEMORY_SET = 0x01;
265  static const unsigned char VISCA_MEMORY_RECALL = 0x02;
266  static const unsigned char VISCA_DISPLAY = 0x15;
267  static const unsigned char VISCA_DISPLAY_TOGGLE = 0x10;
268  static const unsigned char VISCA_DATE_TIME_SET = 0x70;
269  static const unsigned char VISCA_DATE_DISPLAY = 0x71;
270  static const unsigned char VISCA_TIME_DISPLAY = 0x72;
271  static const unsigned char VISCA_TITLE_DISPLAY = 0x74;
272  static const unsigned char VISCA_TITLE_DISPLAY_CLEAR = 0x00;
273  static const unsigned char VISCA_TITLE_SET = 0x73;
274  static const unsigned char VISCA_TITLE_SET_PARAMS = 0x00;
275  static const unsigned char VISCA_TITLE_SET_PART1 = 0x01;
276  static const unsigned char VISCA_TITLE_SET_PART2 = 0x02;
277  static const unsigned char VISCA_IRRECEIVE = 0x08;
278  static const unsigned char VISCA_IRRECEIVE_ON = 0x02;
279  static const unsigned char VISCA_IRRECEIVE_OFF = 0x03;
280  static const unsigned char VISCA_IRRECEIVE_ONOFF = 0x10;
281  static const unsigned char VISCA_PT_DRIVE = 0x01;
282  static const unsigned char VISCA_PT_DRIVE_HORIZ_LEFT = 0x01;
283  static const unsigned char VISCA_PT_DRIVE_HORIZ_RIGHT = 0x02;
284  static const unsigned char VISCA_PT_DRIVE_HORIZ_STOP = 0x03;
285  static const unsigned char VISCA_PT_DRIVE_VERT_UP = 0x01;
286  static const unsigned char VISCA_PT_DRIVE_VERT_DOWN = 0x02;
287  static const unsigned char VISCA_PT_DRIVE_VERT_STOP = 0x03;
288  static const unsigned char VISCA_PT_ABSOLUTE_POSITION = 0x02;
289  static const unsigned char VISCA_PT_RELATIVE_POSITION = 0x03;
290  static const unsigned char VISCA_PT_HOME = 0x04;
291  static const unsigned char VISCA_PT_RESET = 0x05;
292  static const unsigned char VISCA_PT_LIMITSET = 0x07;
293  static const unsigned char VISCA_PT_LIMITSET_SET = 0x00;
294  static const unsigned char VISCA_PT_LIMITSET_CLEAR = 0x01;
295  static const unsigned char VISCA_PT_LIMITSET_SET_UR = 0x01;
296  static const unsigned char VISCA_PT_LIMITSET_SET_DL = 0x00;
297  static const unsigned char VISCA_PT_DATASCREEN = 0x06;
298  static const unsigned char VISCA_PT_DATASCREEN_ON = 0x02;
299  static const unsigned char VISCA_PT_DATASCREEN_OFF = 0x03;
300  static const unsigned char VISCA_PT_DATASCREEN_ONOFF = 0x10;
301  static const unsigned char VISCA_PT_VIDEOSYSTEM_INQ = 0x23;
302  static const unsigned char VISCA_PT_MODE_INQ = 0x10;
303  static const unsigned char VISCA_PT_MAXSPEED_INQ = 0x11;
304  static const unsigned char VISCA_PT_POSITION_INQ = 0x12;
305  static const unsigned char VISCA_PT_DATASCREEN_INQ = 0x06;
306  /*****************/
307  /* D30/D31 CODES */
308  /*****************/
309  static const unsigned char VISCA_WIDE_CON_LENS = 0x26;
310  static const unsigned char VISCA_WIDE_CON_LENS_SET = 0x00;
311 
312  static const unsigned char VISCA_AT_MODE = 0x01;
313  static const unsigned char VISCA_AT_ONOFF = 0x10;
314  static const unsigned char VISCA_AT_AE = 0x02;
315  static const unsigned char VISCA_AT_AUTOZOOM = 0x03;
316  static const unsigned char VISCA_ATMD_FRAMEDISPLAY = 0x04;
317  static const unsigned char VISCA_AT_FRAMEOFFSET = 0x05;
318  static const unsigned char VISCA_ATMD_STARTSTOP = 0x06;
319  static const unsigned char VISCA_AT_CHASE = 0x07;
320  static const unsigned char VISCA_AT_CHASE_NEXT = 0x10;
321 
322  static const unsigned char VISCA_MD_MODE = 0x08;
323  static const unsigned char VISCA_MD_ONOFF = 0x10;
324  static const unsigned char VISCA_MD_FRAME = 0x09;
325  static const unsigned char VISCA_MD_DETECT = 0x0A;
326 
327  static const unsigned char VISCA_MD_ADJUST = 0x00;
328  static const unsigned char VISCA_MD_ADJUST_YLEVEL = 0x0B;
329  static const unsigned char VISCA_MD_ADJUST_HUELEVEL = 0x0C;
330  static const unsigned char VISCA_MD_ADJUST_SIZE = 0x0D;
331  static const unsigned char VISCA_MD_ADJUST_DISPTIME = 0x0F;
332  static const unsigned char VISCA_MD_ADJUST_REFTIME = 0x0B;
333  static const unsigned char VISCA_MD_ADJUST_REFMODE = 0x10;
334 
335  static const unsigned char VISCA_AT_ENTRY = 0x15;
336  static const unsigned char VISCA_AT_LOSTINFO = 0x20;
337  static const unsigned char VISCA_MD_LOSTINFO = 0x21;
338  static const unsigned char VISCA_ATMD_LOSTINFO1 = 0x20;
339  static const unsigned char VISCA_ATMD_LOSTINFO2 = 0x07;
340 
341  static const unsigned char VISCA_MD_MEASURE_MODE_1 = 0x27;
342  static const unsigned char VISCA_MD_MEASURE_MODE_2 = 0x28;
343 
344  static const unsigned char VISCA_ATMD_MODE = 0x22;
345  static const unsigned char VISCA_AT_MODE_QUERY = 0x23;
346  static const unsigned char VISCA_MD_MODE_QUERY = 0x24;
347  static const unsigned char VISCA_MD_REFTIME_QUERY = 0x11;
348  static const unsigned char VISCA_AT_POSITION = 0x20;
349  static const unsigned char VISCA_MD_POSITION = 0x21;
350 
351  static const unsigned int VISCA_NONBLOCKING_PANTILT = 0;
352  static const unsigned int VISCA_NONBLOCKING_ZOOM = 1;
353  static const unsigned int VISCA_NONBLOCKING_NUM = 2;
354 
355  void recv_packet(unsigned int max_wait_ms = 10);
356  void handle_response();
357  void finish_nonblocking(unsigned int socket);
358 
359  int dev;
360  bool opened;
361 
362  unsigned int inquire;
363 
364  // Visca specific
365  unsigned char recipient;
366  unsigned char sender;
367 
368  unsigned char obuffer[16];
369  unsigned char ibuffer[1024];
370  int obuffer_length;
371  int ibuffer_length;
372 
373  unsigned int num_commands_running;
374  bool blocking;
375  bool nonblocking_running[2];
376  unsigned int nonblocking_sockets[2];
377 #ifdef TIMETRACKER_VISCA
378  fawkes::TimeTracker *tracker;
379  std::ofstream track_file;
380  unsigned int ttcls_pantilt_get_send;
381  unsigned int ttcls_pantilt_get_read;
382  unsigned int ttcls_pantilt_get_handle;
383  unsigned int ttcls_pantilt_get_interpret;
384 #endif
385 
386 };
387 
388 } // end namespace firevision
389 
390 #endif
static const unsigned int VISCA_WHITEBALANCE_OUTDOOR
Outdoor white balance preset.
Definition: visca.h:61
static const unsigned int VISCA_WHITEBALANCE_ATW
ATW white balance preset.
Definition: visca.h:63
static const unsigned int VISCA_WHITEBALANCE_ONE_PUSH
One push white balance preset.
Definition: visca.h:62
ViscaControlException(const char *msg)
Constructor.
Definition: visca.cpp:47
Visca inquire running exception.
Definition: visca.h:49
int _errno
Error number, should be used if the error was caused by a method that supplies errno.
Definition: exception.h:111
Visca control protocol implementation over a serial line.
Definition: visca.h:56
Base class for exceptions in Fawkes.
Definition: exception.h:36
static const unsigned int VISCA_WHITEBALANCE_INDOOR
Indoor white balance preset.
Definition: visca.h:60
Time tracking utility.
Definition: tracker.h:38
Visca exception.
Definition: visca.h:42
static const unsigned int VISCA_WHITEBLANCE_AUTO
Automatic white balance.
Definition: visca.h:59
static const unsigned int VISCA_WHITEBALANCE_MANUAL
Manual white balance.
Definition: visca.h:64