23#ifndef _PLUGINS_PANTILT_SONY_VISCA_H_
24#define _PLUGINS_PANTILT_SONY_VISCA_H_
26#include <core/exception.h>
28#ifdef TIMETRACKER_VISCA
29# warning Visca time tracker enabled
30# include <utils/timetracker.h>
96 Visca(
const char *device_file,
unsigned int def_timeout_ms = 10,
bool blocking =
true);
112 void recv(
unsigned int timeout_ms = 0xFFFFFFFF);
113 void recv_ack(
unsigned int *socket = NULL);
166 static const unsigned int VISCA_RUNINQ_NONE = 0;
167 static const unsigned int VISCA_RUNINQ_PANTILT = 1;
170 static const unsigned char VISCA_BUS_0 = 0;
171 static const unsigned char VISCA_BUS_1 = 1;
172 static const unsigned char VISCA_BUS_2 = 2;
173 static const unsigned char VISCA_BUS_3 = 3;
174 static const unsigned char VISCA_BUS_4 = 4;
175 static const unsigned char VISCA_BUS_5 = 5;
176 static const unsigned char VISCA_BUS_6 = 6;
177 static const unsigned char VISCA_BUS_7 = 7;
178 static const unsigned char VISCA_BUS_BROADCAST = 8;
181 static const unsigned char VISCA_COMMAND = 0x01;
182 static const unsigned char VISCA_CANCEL = 0x20;
183 static const unsigned char VISCA_INQUIRY = 0x09;
184 static const unsigned char VISCA_TERMINATOR = 0xFF;
187 static const unsigned char VISCA_RESPONSE_CLEAR = 0x40;
188 static const unsigned char VISCA_RESPONSE_ADDRESS = 0x30;
189 static const unsigned char VISCA_RESPONSE_ACK = 0x40;
190 static const unsigned char VISCA_RESPONSE_COMPLETED = 0x50;
191 static const unsigned char VISCA_RESPONSE_ERROR = 0x60;
194 static const unsigned char VISCA_ERROR_LENGTH = 0x01;
195 static const unsigned char VISCA_ERROR_SYNTAX = 0x02;
196 static const unsigned char VISCA_ERROR_BUFFERFULL = 0x03;
197 static const unsigned char VISCA_ERROR_CANCELLED = 0x04;
198 static const unsigned char VISCA_ERROR_NOSOCKET = 0x05;
199 static const unsigned char VISCA_ERROR_NOTEXECABLE = 0x41;
202 static const unsigned char VISCA_CATEGORY_INTERFACE = 0x00;
203 static const unsigned char VISCA_CATEGORY_CAMERA1 = 0x04;
204 static const unsigned char VISCA_CATEGORY_PAN_TILTER = 0x06;
205 static const unsigned char VISCA_CATEGORY_CAMERA2 = 0x07;
207 static const unsigned char VISCA_POWER = 0x00;
208 static const unsigned char VISCA_POWER_ON = 0x02;
209 static const unsigned char VISCA_POWER_OFF = 0x03;
210 static const unsigned char VISCA_DEVICE_INFO = 0x02;
211 static const unsigned char VISCA_KEYLOCK = 0x17;
212 static const unsigned char VISCA_ID = 0x22;
213 static const unsigned char VISCA_ZOOM = 0x07;
214 static const unsigned char VISCA_ZOOM_STOP = 0x00;
215 static const unsigned char VISCA_ZOOM_TELE = 0x02;
216 static const unsigned char VISCA_ZOOM_WIDE = 0x03;
217 static const unsigned char VISCA_ZOOM_TELE_SPEED = 0x20;
218 static const unsigned char VISCA_ZOOM_WIDE_SPEED = 0x30;
219 static const unsigned char VISCA_ZOOM_VALUE = 0x47;
220 static const unsigned char VISCA_ZOOM_FOCUS_VALUE = 0x47;
221 static const unsigned char VISCA_DZOOM = 0x06;
222 static const unsigned char VISCA_DZOOM_ON = 0x02;
223 static const unsigned char VISCA_DZOOM_OFF = 0x03;
224 static const unsigned char VISCA_FOCUS = 0x08;
225 static const unsigned char VISCA_FOCUS_STOP = 0x00;
226 static const unsigned char VISCA_FOCUS_FAR = 0x02;
227 static const unsigned char VISCA_FOCUS_NEAR = 0x03;
228 static const unsigned char VISCA_FOCUS_FAR_SPEED = 0x20;
229 static const unsigned char VISCA_FOCUS_NEAR_SPEED = 0x30;
230 static const unsigned char VISCA_FOCUS_VALUE = 0x48;
231 static const unsigned char VISCA_FOCUS_AUTO = 0x38;
232 static const unsigned char VISCA_FOCUS_AUTO_MAN = 0x10;
233 static const unsigned char VISCA_FOCUS_ONE_PUSH = 0x18;
234 static const unsigned char VISCA_FOCUS_ONE_PUSH_TRIG = 0x01;
235 static const unsigned char VISCA_FOCUS_ONE_PUSH_INF = 0x02;
236 static const unsigned char VISCA_FOCUS_AUTO_SENSE = 0x58;
237 static const unsigned char VISCA_FOCUS_AUTO_SENSE_HIGH = 0x02;
238 static const unsigned char VISCA_FOCUS_AUTO_SENSE_LOW = 0x03;
239 static const unsigned char VISCA_FOCUS_NEAR_LIMIT = 0x28;
240 static const unsigned char VISCA_WB = 0x35;
241 static const unsigned char VISCA_WB_AUTO = 0x00;
242 static const unsigned char VISCA_WB_INDOOR = 0x01;
243 static const unsigned char VISCA_WB_OUTDOOR = 0x02;
244 static const unsigned char VISCA_WB_ONE_PUSH = 0x03;
245 static const unsigned char VISCA_WB_ATW = 0x04;
246 static const unsigned char VISCA_WB_MANUAL = 0x05;
247 static const unsigned char VISCA_WB_ONE_PUSH_TRIG = 0x05;
248 static const unsigned char VISCA_RGAIN = 0x03;
249 static const unsigned char VISCA_RGAIN_VALUE = 0x43;
250 static const unsigned char VISCA_BGAIN = 0x04;
251 static const unsigned char VISCA_BGAIN_VALUE = 0x44;
252 static const unsigned char VISCA_AUTO_EXP = 0x39;
253 static const unsigned char VISCA_AUTO_EXP_FULL_AUTO = 0x00;
254 static const unsigned char VISCA_AUTO_EXP_MANUAL = 0x03;
255 static const unsigned char VISCA_AUTO_EXP_SHUTTER_PRIORITY = 0x0A;
256 static const unsigned char VISCA_AUTO_EXP_IRIS_PRIORITY = 0x0B;
257 static const unsigned char VISCA_AUTO_EXP_GAIN_PRIORITY = 0x0C;
258 static const unsigned char VISCA_AUTO_EXP_BRIGHT = 0x0D;
259 static const unsigned char VISCA_AUTO_EXP_SHUTTER_AUTO = 0x1A;
260 static const unsigned char VISCA_AUTO_EXP_IRIS_AUTO = 0x1B;
261 static const unsigned char VISCA_AUTO_EXP_GAIN_AUTO = 0x1C;
262 static const unsigned char VISCA_SLOW_SHUTTER = 0x5A;
263 static const unsigned char VISCA_SLOW_SHUTTER_AUTO = 0x02;
264 static const unsigned char VISCA_SLOW_SHUTTER_MANUAL = 0x03;
265 static const unsigned char VISCA_SHUTTER = 0x0A;
266 static const unsigned char VISCA_SHUTTER_VALUE = 0x4A;
267 static const unsigned char VISCA_IRIS = 0x0B;
268 static const unsigned char VISCA_IRIS_VALUE = 0x4B;
269 static const unsigned char VISCA_GAIN = 0x0C;
270 static const unsigned char VISCA_GAIN_VALUE = 0x4C;
271 static const unsigned char VISCA_BRIGHT = 0x0D;
272 static const unsigned char VISCA_BRIGHT_VALUE = 0x4D;
273 static const unsigned char VISCA_EXP_COMP = 0x0E;
274 static const unsigned char VISCA_EXP_COMP_POWER = 0x3E;
275 static const unsigned char VISCA_EXP_COMP_VALUE = 0x4E;
276 static const unsigned char VISCA_BACKLIGHT_COMP = 0x33;
277 static const unsigned char VISCA_APERTURE = 0x02;
278 static const unsigned char VISCA_APERTURE_VALUE = 0x42;
279 static const unsigned char VISCA_ZERO_LUX = 0x01;
280 static const unsigned char VISCA_IR_LED = 0x31;
281 static const unsigned char VISCA_WIDE_MODE = 0x60;
282 static const unsigned char VISCA_WIDE_MODE_OFF = 0x00;
283 static const unsigned char VISCA_WIDE_MODE_CINEMA = 0x01;
284 static const unsigned char VISCA_WIDE_MODE_16_9 = 0x02;
285 static const unsigned char VISCA_MIRROR = 0x61;
286 static const unsigned char VISCA_MIRROR_ON = 0x02;
287 static const unsigned char VISCA_MIRROR_OFF = 0x03;
288 static const unsigned char VISCA_FREEZE = 0x62;
289 static const unsigned char VISCA_PICTURE_EFFECT = 0x63;
290 static const unsigned char VISCA_PICTURE_EFFECT_OFF = 0x00;
291 static const unsigned char VISCA_PICTURE_EFFECT_PASTEL = 0x01;
292 static const unsigned char VISCA_PICTURE_EFFECT_NEGATIVE = 0x02;
293 static const unsigned char VISCA_PICTURE_EFFECT_SEPIA = 0x03;
294 static const unsigned char VISCA_PICTURE_EFFECT_BW = 0x04;
295 static const unsigned char VISCA_PICTURE_EFFECT_SOLARIZE = 0x05;
296 static const unsigned char VISCA_PICTURE_EFFECT_MOSAIC = 0x06;
297 static const unsigned char VISCA_PICTURE_EFFECT_SLIM = 0x07;
298 static const unsigned char VISCA_PICTURE_EFFECT_STRETCH = 0x08;
299 static const unsigned char VISCA_DIGITAL_EFFECT = 0x64;
300 static const unsigned char VISCA_DIGITAL_EFFECT_OFF = 0x00;
301 static const unsigned char VISCA_DIGITAL_EFFECT_STILL = 0x01;
302 static const unsigned char VISCA_DIGITAL_EFFECT_FLASH = 0x02;
303 static const unsigned char VISCA_DIGITAL_EFFECT_LUMI = 0x03;
304 static const unsigned char VISCA_DIGITAL_EFFECT_TRAIL = 0x04;
305 static const unsigned char VISCA_DIGITAL_EFFECT_LEVEL = 0x65;
306 static const unsigned char VISCA_MEMORY = 0x3F;
307 static const unsigned char VISCA_MEMORY_RESET = 0x00;
308 static const unsigned char VISCA_MEMORY_SET = 0x01;
309 static const unsigned char VISCA_MEMORY_RECALL = 0x02;
310 static const unsigned char VISCA_DISPLAY = 0x15;
311 static const unsigned char VISCA_DISPLAY_TOGGLE = 0x10;
312 static const unsigned char VISCA_DATE_TIME_SET = 0x70;
313 static const unsigned char VISCA_DATE_DISPLAY = 0x71;
314 static const unsigned char VISCA_TIME_DISPLAY = 0x72;
315 static const unsigned char VISCA_TITLE_DISPLAY = 0x74;
316 static const unsigned char VISCA_TITLE_DISPLAY_CLEAR = 0x00;
317 static const unsigned char VISCA_TITLE_SET = 0x73;
318 static const unsigned char VISCA_TITLE_SET_PARAMS = 0x00;
319 static const unsigned char VISCA_TITLE_SET_PART1 = 0x01;
320 static const unsigned char VISCA_TITLE_SET_PART2 = 0x02;
321 static const unsigned char VISCA_IRRECEIVE = 0x08;
322 static const unsigned char VISCA_IRRECEIVE_ON = 0x02;
323 static const unsigned char VISCA_IRRECEIVE_OFF = 0x03;
324 static const unsigned char VISCA_IRRECEIVE_ONOFF = 0x10;
325 static const unsigned char VISCA_PT_DRIVE = 0x01;
326 static const unsigned char VISCA_PT_DRIVE_HORIZ_LEFT = 0x01;
327 static const unsigned char VISCA_PT_DRIVE_HORIZ_RIGHT = 0x02;
328 static const unsigned char VISCA_PT_DRIVE_HORIZ_STOP = 0x03;
329 static const unsigned char VISCA_PT_DRIVE_VERT_UP = 0x01;
330 static const unsigned char VISCA_PT_DRIVE_VERT_DOWN = 0x02;
331 static const unsigned char VISCA_PT_DRIVE_VERT_STOP = 0x03;
332 static const unsigned char VISCA_PT_ABSOLUTE_POSITION = 0x02;
333 static const unsigned char VISCA_PT_RELATIVE_POSITION = 0x03;
334 static const unsigned char VISCA_PT_HOME = 0x04;
335 static const unsigned char VISCA_PT_RESET = 0x05;
336 static const unsigned char VISCA_PT_LIMITSET = 0x07;
337 static const unsigned char VISCA_PT_LIMITSET_SET = 0x00;
338 static const unsigned char VISCA_PT_LIMITSET_CLEAR = 0x01;
339 static const unsigned char VISCA_PT_LIMITSET_SET_UR = 0x01;
340 static const unsigned char VISCA_PT_LIMITSET_SET_DL = 0x00;
341 static const unsigned char VISCA_PT_DATASCREEN = 0x06;
342 static const unsigned char VISCA_PT_DATASCREEN_ON = 0x02;
343 static const unsigned char VISCA_PT_DATASCREEN_OFF = 0x03;
344 static const unsigned char VISCA_PT_DATASCREEN_ONOFF = 0x10;
345 static const unsigned char VISCA_PT_VIDEOSYSTEM_INQ = 0x23;
346 static const unsigned char VISCA_PT_MODE_INQ = 0x10;
347 static const unsigned char VISCA_PT_MAXSPEED_INQ = 0x11;
348 static const unsigned char VISCA_PT_POSITION_INQ = 0x12;
349 static const unsigned char VISCA_PT_DATASCREEN_INQ = 0x06;
353 static const unsigned char VISCA_WIDE_CON_LENS = 0x26;
354 static const unsigned char VISCA_WIDE_CON_LENS_SET = 0x00;
356 static const unsigned char VISCA_AT_MODE = 0x01;
357 static const unsigned char VISCA_AT_ONOFF = 0x10;
358 static const unsigned char VISCA_AT_AE = 0x02;
359 static const unsigned char VISCA_AT_AUTOZOOM = 0x03;
360 static const unsigned char VISCA_ATMD_FRAMEDISPLAY = 0x04;
361 static const unsigned char VISCA_AT_FRAMEOFFSET = 0x05;
362 static const unsigned char VISCA_ATMD_STARTSTOP = 0x06;
363 static const unsigned char VISCA_AT_CHASE = 0x07;
364 static const unsigned char VISCA_AT_CHASE_NEXT = 0x10;
366 static const unsigned char VISCA_MD_MODE = 0x08;
367 static const unsigned char VISCA_MD_ONOFF = 0x10;
368 static const unsigned char VISCA_MD_FRAME = 0x09;
369 static const unsigned char VISCA_MD_DETECT = 0x0A;
371 static const unsigned char VISCA_MD_ADJUST = 0x00;
372 static const unsigned char VISCA_MD_ADJUST_YLEVEL = 0x0B;
373 static const unsigned char VISCA_MD_ADJUST_HUELEVEL = 0x0C;
374 static const unsigned char VISCA_MD_ADJUST_SIZE = 0x0D;
375 static const unsigned char VISCA_MD_ADJUST_DISPTIME = 0x0F;
376 static const unsigned char VISCA_MD_ADJUST_REFTIME = 0x0B;
377 static const unsigned char VISCA_MD_ADJUST_REFMODE = 0x10;
379 static const unsigned char VISCA_AT_ENTRY = 0x15;
380 static const unsigned char VISCA_AT_LOSTINFO = 0x20;
381 static const unsigned char VISCA_MD_LOSTINFO = 0x21;
382 static const unsigned char VISCA_ATMD_LOSTINFO1 = 0x20;
383 static const unsigned char VISCA_ATMD_LOSTINFO2 = 0x07;
385 static const unsigned char VISCA_MD_MEASURE_MODE_1 = 0x27;
386 static const unsigned char VISCA_MD_MEASURE_MODE_2 = 0x28;
388 static const unsigned char VISCA_ATMD_MODE = 0x22;
389 static const unsigned char VISCA_AT_MODE_QUERY = 0x23;
390 static const unsigned char VISCA_MD_MODE_QUERY = 0x24;
391 static const unsigned char VISCA_MD_REFTIME_QUERY = 0x11;
392 static const unsigned char VISCA_AT_POSITION = 0x20;
393 static const unsigned char VISCA_MD_POSITION = 0x21;
395 void recv_packet(
unsigned int timeout_ms);
396 void handle_response();
397 void finish_nonblocking(
unsigned int socket);
402 unsigned int default_timeout_ms_;
404 unsigned int inquire_;
406 unsigned char recipient_;
407 unsigned char sender_;
409 unsigned char obuffer_[16];
410 unsigned char ibuffer_[1024];
415 bool nonblocking_running_[2];
416 unsigned int nonblocking_sockets_[2];
418 unsigned char pan_speed_;
419 unsigned char tilt_speed_;
421#ifdef TIMETRACKER_VISCA
423 unsigned int ttc_pantilt_get_send_;
424 unsigned int ttc_pantilt_get_read_;
425 unsigned int ttc_pantilt_get_handle_;
426 unsigned int ttc_pantilt_get_interpret_;
ViscaException(const char *msg)
Constructor.
Visca inquire running exception.
ViscaInquiryRunningException()
Constructor.
Visca control protocol implementation over a serial line.
void set_mirror(bool mirror)
Sett mirror sate.
static const unsigned int VISCA_WHITEBALANCE_MANUAL
Manual white balance.
static const unsigned int VISCA_ZOOM_VALUE_1X
Zoom value: 1x.
void set_pan_tilt(int pan, int tilt)
Set pan tilt.
static const unsigned int VISCA_ZOOM_VALUE_8X
Zoom value: 8x.
static const unsigned int MAX_TILT_SPEED
Number of non-blocking items.
static const unsigned int VISCA_WHITEBALANCE_ATW
ATW white balance preset.
static const unsigned int NONBLOCKING_ZOOM
Non-blocking zoom item.
static const unsigned int VISCA_ZOOM_VALUE_10X
Zoom value: 10x.
void set_zoom_speed_tele(unsigned int speed)
Set zoom speed in tele.
bool is_powered()
Check if camera is powered.
void open()
Open serial port.
void reset_zoom()
Reset zoom.
static const unsigned int VISCA_WHITEBALANCE_ONE_PUSH
One push white balance preset.
void clear()
Clear command buffers.
void recv_ack(unsigned int *socket=NULL)
Receive ACK packet.
static const unsigned int VISCA_ZOOM_VALUE_WIDE
Zoom value: wide.
void apply_effect_bnw()
Apply B/W effect.
void get_pan_tilt_speed(unsigned char &pan_speed, unsigned char &tilt_speed)
Get pan/tilt speed.
void recv(unsigned int timeout_ms=0xFFFFFFFF)
Receive data.
static const unsigned int VISCA_WHITEBALANCE_INDOOR
Indoor white balance preset.
bool is_nonblocking_finished(unsigned int item) const
Check if a non-blocking operation has been finished.
void cancel_command(unsigned int socket)
Cancel a running command.
static const unsigned int VISCA_ZOOM_VALUE_2X
Zoom value: 2x.
static const unsigned int NONBLOCKING_NUM
Number of non-blocking items.
static const unsigned int VISCA_ZOOM_VALUE_DIG_40X
Zoom value: 40x.
void get_pan_tilt(int &pan, int &tilt)
Get pan and tilt values.
void apply_effect_stretch()
Apply stretch effect.
void reset_effect()
Reset effects.
void get_zoom(unsigned int &zoom)
Get zoom.
static const unsigned int VISCA_WHITEBLANCE_AUTO
Automatic white balance.
void reset_pan_tilt_limit()
Reset pan/tilt limit.
void apply_effect_sepia()
Apply sepia effect.
static const unsigned int VISCA_ZOOM_VALUE_4X
Zoom value: 4x.
void reset_pan_tilt()
Reset pan/tilt.
static const unsigned int VISCA_ZOOM_VALUE_5X
Zoom value: 5x.
void set_zoom_speed_wide(unsigned int speed)
Set zoom speed in wide angle.
void apply_effect_mosaic()
Apply mosaic effect.
static const unsigned int VISCA_ZOOM_VALUE_9X
Zoom value: 9x.
void apply_effect_neg_art()
Apply negative art effect.
void apply_effect_solarize()
Apply solarize effect.
void process()
Process incoming data.
static const unsigned int VISCA_ZOOM_VALUE_3X
Zoom value: 3x.
void apply_effect_pastel()
Apply pastel effect.
static const unsigned int VISCA_ZOOM_VALUE_7X
Zoom value: 7x.
bool data_available()
Check data availability.
void set_pan_tilt_speed(unsigned char pan_speed, unsigned char tilt_speed)
Set pan/tilt speed.
void set_power(bool powered)
Set power state.
void send_nonblocking(unsigned int *socket=NULL)
Send non-blocking.
void send()
Send outbound queue.
void set_address()
Set addresses of cameras.
virtual ~Visca()
Destructor.
void set_zoom(unsigned int zoom)
Set zoom.
static const unsigned int MAX_PAN_SPEED
Number of non-blocking items.
static const unsigned int VISCA_ZOOM_VALUE_6X
Zoom value: 6x.
void set_zoom_digital_enabled(bool enabled)
Enable or disable digital zoome.
void apply_effect(unsigned char effect)
Apply effect.
unsigned int get_white_balance_mode()
Get white balance mode.
static const unsigned int NONBLOCKING_PANTILT
Non-blocking pan/tilt item.
void set_pan_tilt_limit(int pan_left, int pan_right, int tilt_up, int tilt_down)
Set pan tilt limit.
bool get_mirror()
Get mirror sate.
static const unsigned int VISCA_WHITEBALANCE_OUTDOOR
Outdoor white balance preset.
static const unsigned int VISCA_ZOOM_VALUE_DIG_20X
Zoom value: 20x.
Visca(const char *device_file, unsigned int def_timeout_ms=10, bool blocking=true)
Constructor.
void send_with_reply()
Send and wait for reply, blocking.
static const unsigned int VISCA_ZOOM_VALUE_DIG_30X
Zoom value: 30x.
void apply_effect_slim()
Apply slim effect.
void start_get_pan_tilt()
Query for pan/tilt but do not wait until finished This will send an inquire to the camera that asks f...
Base class for exceptions in Fawkes.
int _errno
Error number, should be used if the error was caused by a method that supplies errno.