1# ========================================================================== 2# 3# ZoneMinder Vivotek ePTZ Control Protocol Module 4# Copyright (C) 2015 Robin Daermann 5# 6# This program is free software; you can redistribute it and/or 7# modify it under the terms of the GNU General Public License 8# as published by the Free Software Foundation; either version 2 9# of the License, or (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19# 20# ========================================================================== 21# 22# This module contains the implementation of the Vivotek ePTZ camera control 23# protocol 24# 25package ZoneMinder::Control::Vivotek_ePTZ; 26 27use 5.006; 28use strict; 29use warnings; 30 31require ZoneMinder::Base; 32require ZoneMinder::Control; 33 34our @ISA = qw(ZoneMinder::Control); 35 36# ========================================================================== 37# 38# Vivotek ePTZ Control Protocol 39# 40# ========================================================================== 41 42use ZoneMinder::Logger qw(:all); 43use ZoneMinder::Config qw(:all); 44 45use Time::HiRes qw( usleep ); 46 47sub open 48{ 49 my $self = shift; 50 51 $self->loadMonitor(); 52 Debug( "Camera open" ); 53 use LWP::UserAgent; 54 $self->{ua} = LWP::UserAgent->new; 55 $self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION ); 56 57 $self->{state} = 'open'; 58} 59 60sub close 61{ 62 my $self = shift; 63 $self->{state} = 'closed'; 64} 65 66sub printMsg 67{ 68 my $msg = shift; 69 my $msg_len = length($msg); 70 71 Debug( $msg."[".$msg_len."]" ); 72} 73 74sub sendCmd 75{ 76 my ($self, $cmd, $speedcmd) = @_; 77 78 my $result = undef; 79 80 printMsg( $speedcmd, "Tx" ); 81 printMsg( $cmd, "Tx" ); 82 83 my $req = HTTP::Request->new( GET => "http://" . $self->{Monitor}->{ControlAddress} . "/cgi-bin/camctrl/eCamCtrl.cgi?stream=0&$speedcmd&$cmd" ); 84 my $res = $self->{ua}->request($req); 85 86 if ( $res->is_success ) 87 { 88 $result = !undef; 89 } 90 else 91 { 92 Error( "Request failed: '" . $res->status_line() . "' (URI: '" . $req->as_string() . "')" ); 93 } 94 95 return( $result ); 96} 97 98sub moveConUp 99{ 100 my ($self, $params) = @_; 101 my $speed = 'speedtilt=' . ($params->{tiltspeed} - 6); 102 Debug( "Move Up" ); 103 $self->sendCmd( 'move=up', $speed ); 104} 105 106sub moveConDown 107{ 108 my ($self, $params) = @_; 109 my $speed = 'speedtilt=' . ($params->{tiltspeed} - 6); 110 Debug( "Move Down" ); 111 $self->sendCmd( 'move=down', $speed ); 112} 113 114sub moveConLeft 115{ 116 my ($self, $params) = @_; 117 my $speed = 'speedpan=-' . $params->{panspeed}; 118 Debug( "Move Left" ); 119 $self->sendCmd( 'move=left', $speed ); 120} 121 122sub moveConRight 123{ 124 my ($self, $params) = @_; 125 my $speed = 'speedpan=' . ($params->{panspeed} - 6); 126 Debug( "Move Right" ); 127 $self->sendCmd( 'move=right', $speed ); 128} 129 130sub moveStop 131{ 132 my $self = shift; 133 Debug( "Move Stop" ); 134 # not implemented 135} 136 137sub zoomConTele 138{ 139 my ($self, $params) = @_; 140 my $speed = 'speedzoom=' . ($params->{speed} - 6); 141 Debug( "Zoom In" ); 142 $self->sendCmd( 'zoom=tele', $speed ); 143} 144 145sub zoomConWide 146{ 147 my ($self, $params) = @_; 148 my $speed = 'speedzoom=' . ($params->{speed} - 6); 149 Debug( "Zoom Out" ); 150 $self->sendCmd( 'zoom=wide', $speed ); 151} 152 153sub reset 154{ 155 my $self = shift; 156 Debug( "Camera Reset" ); 157 $self->sendCmd( 'move=home' ); 158} 159 1601; 161__END__ 162 163=head1 NAME 164 165ZoneMinder::Control::Vivotek_ePTZ - ZoneMinder Perl extension for Vivotek ePTZ 166camera control protocol 167 168=head1 SYNOPSIS 169 170 use ZoneMinder::Control::Vivotek_ePTZ; 171 172=head1 DESCRIPTION 173 174This module implements the ePTZ protocol used in various Vivotek IP cameras, 175developed with a Vivotek IB8369 model. 176 177Currently, only simple pan, tilt and zoom function is implemented. Presets will 178follow later. 179 180=head2 EXPORT 181 182None. 183 184=head1 SEE ALSO 185 186I would say, see ZoneMinder::Control documentation. But it is a stub. 187 188=head1 AUTHOR 189 190Robin Daermann E<lt>r.daermann@ids-services.deE<gt> 191 192=head1 COPYRIGHT AND LICENSE 193 194Copyright (C) 2015 by Robin Daermann 195 196This library is free software; you can redistribute it and/or modify 197it under the same terms as Perl itself, either Perl version 5.8.3 or, 198at your option, any later version of Perl 5 you may have available. 199 200=cut 201