1# ==========================================================================
2#
3# ZoneMinder Maginon Supra IPC Camera Control Protocol Module,
4# Copyright (C) 2017  Martin Gutenbrunner (martin.gutenbrunner@SPAMsonic.net)
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 Maginon Supra IPC camera
23# procotol version.
24#
25package ZoneMinder::Control::MaginonIPC;
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#   Maginon Supra IPC IP Camera 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
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 printMsg
61{
62    my $self = shift;
63    my $msg = shift;
64    my $msg_len = length($msg);
65
66    Debug( $msg."[".$msg_len."]" );
67}
68
69sub sendCmd
70{
71    my $self = shift;
72    my $cmd = shift;
73
74    #my $result = undef;
75
76    printMsg( $cmd, "Tx" );
77
78    my $url = "http://".$self->{Monitor}->{ControlAddress}."$cmd";
79#    Info($url);
80    my $req = HTTP::Request->new( GET=>$url );
81    my $res = $self->{ua}->request($req);
82    return( !undef );
83}
84
85sub moveStop
86{
87   Debug("moveStop");
88   my $self = shift;
89   my $params = shift;
90   my $cmd = "/decoder_control.cgi?command=1";
91   $self->sendCmd( $cmd );
92}
93
94sub moveConUp
95{
96   Debug("moveConUp");
97   my $self = shift;
98   my $params = shift;
99   my $cmd = "/decoder_control.cgi?command=0";
100   $self->sendCmd( $cmd );
101   my $autostop = $self->getParam( $params, 'autostop', 0 );
102   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
103   {
104      usleep( $self->{Monitor}->{AutoStopTimeout} );
105      $self->moveStop( $params );
106   }
107}
108
109sub moveConDown
110{
111   Debug("moveConDown");
112   my $self = shift;
113   my $params = shift;
114   my $cmd = "/decoder_control.cgi?command=2";
115   $self->sendCmd( $cmd );
116   my $autostop = $self->getParam( $params, 'autostop', 0 );
117   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
118   {
119      usleep( $self->{Monitor}->{AutoStopTimeout} );
120      $self->moveStop( $params );
121   }
122}
123
124sub moveConLeft
125{
126   Debug("moveConLeft");
127   my $self = shift;
128   my $params = shift;
129   my $cmd = "/decoder_control.cgi?command=4";
130   $self->sendCmd( $cmd );
131   my $autostop = $self->getParam( $params, 'autostop', 0 );
132   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
133   {
134      usleep( $self->{Monitor}->{AutoStopTimeout} );
135      $self->moveStop( $params );
136   }
137}
138
139sub moveConRight
140{
141   Debug("moveConRight");
142   my $self = shift;
143   my $params = shift;
144   my $cmd = "/decoder_control.cgi?command=6";
145   $self->sendCmd( $cmd );
146   my $autostop = $self->getParam( $params, 'autostop', 0 );
147   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
148   {
149      usleep( $self->{Monitor}->{AutoStopTimeout} );
150      $self->moveStop( $params );
151   }
152}
153
154sub moveConUpRight
155{
156   Debug("moveConUpRight");
157   my $self = shift;
158   my $params = shift;
159   my $cmd = "/decoder_control.cgi?command=91";
160   $self->sendCmd( $cmd );
161   my $autostop = $self->getParam( $params, 'autostop', 0 );
162   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
163   {
164      usleep( $self->{Monitor}->{AutoStopTimeout} );
165      $self->moveStop( $params );
166   }
167}
168
169sub moveConUpLeft
170{
171   Debug("moveConUpLeft");
172   my $self = shift;
173   my $params = shift;
174   my $cmd = "/decoder_control.cgi?command=90";
175   $self->sendCmd( $cmd );
176   my $autostop = $self->getParam( $params, 'autostop', 0 );
177   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
178   {
179      usleep( $self->{Monitor}->{AutoStopTimeout} );
180      $self->moveStop( $params );
181   }
182}
183
184sub moveConDownRight
185{
186   Debug("moveConDownRight");
187   my $self = shift;
188   my $params = shift;
189   my $cmd = "/decoder_control.cgi?command=93";
190   $self->sendCmd( $cmd );
191   my $autostop = $self->getParam( $params, 'autostop', 0 );
192   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
193   {
194      usleep( $self->{Monitor}->{AutoStopTimeout} );
195      $self->moveStop( $params );
196   }
197}
198
199sub moveConDownLeft
200{
201   Debug("moveConDownLeft");
202   my $self = shift;
203   my $params = shift;
204   my $cmd = "/decoder_control.cgi?command=92";
205   $self->sendCmd( $cmd );
206   my $autostop = $self->getParam( $params, 'autostop', 0 );
207   if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
208   {
209      usleep( $self->{Monitor}->{AutoStopTimeout} );
210      $self->moveStop( $params );
211   }
212}
213
214sub presetSet
215{
216    my $self = shift;
217    my $params = shift;
218    my $preset = $self->getParam( $params, 'preset' );
219    Info( "Set Preset $preset" );
220
221    my $cmdNum;
222    if ($preset == 1) {
223      $cmdNum = 30;
224    } elsif ($preset == 2) {
225      $cmdNum = 32;
226    } elsif ($preset == 3) {
227      $cmdNum = 34;
228    } elsif ($preset == 4) {
229      $cmdNum = 36;
230    } else {
231      $cmdNum = 36;
232    }
233
234    my $cmd = "/decoder_control.cgi?command=$cmdNum";
235    $self->sendCmd( $cmd );
236}
237
238sub presetGoto
239{
240    my $self = shift;
241    my $params = shift;
242    my $preset = $self->getParam( $params, 'preset' );
243    Info( "Goto Preset $preset" );
244
245    my $cmdNum;
246    if ($preset == 1) {
247      $cmdNum = 31;
248    } elsif ($preset == 2) {
249      $cmdNum = 33;
250    } elsif ($preset == 3) {
251      $cmdNum = 35;
252    } elsif ($preset == 4) {
253      $cmdNum = 37;
254    } else {
255      $cmdNum = 37;
256    }
257
258    my $cmd = "/decoder_control.cgi?command=$cmdNum";
259    $self->sendCmd( $cmd );
260}
261
2621;
263__END__
264# Below is stub documentation for your module. You'd better edit it!
265
266=head1 NAME
267
268ZoneMinder::Control::MaginonIPC - Zoneminder PTZ control module for the Maginon Supra-IPC 40 IP Camera
269
270=head1 SYNOPSIS
271
272  use ZoneMinder::Control::MaginonIPC;
273  blah blah blah
274
275=head1 DESCRIPTION
276
277   This is for Zoneminder PTZ control module for the Maginon Supra-IPC 40 camera. It probably also works with other models.
278
279=head2 EXPORT
280
281None by default.
282
283
284
285=head1 SEE ALSO
286
287www.zoneminder.com
288
289=head1 AUTHOR
290
291Martin Gutenbrunner, E<lt>martin.gutenbrunner@gmx.atE<gt>
292
293=head1 COPYRIGHT AND LICENSE
294
295Copyright (C) 2017 by Martin Gutenbrunner
296
297This library is free software; you can redistribute it and/or modify
298it under the same terms as Perl itself, either Perl version 5.8.3 or,
299at your option, any later version of Perl 5 you may have available.
300
301
302=cut
303