ABS MegaCam 4210 4220 PT module
Posted: Sun Jun 27, 2010 1:29 am
Here is a control module for ABS MegaCam 4210, 4220 series network cams (i have not tested on 421M and 422M cams but they should work)
Place the code in a file named "ABS_MegaCam.pm" and add it with the rest of the ZoneMinder Control Perl libraries (mine are in
/usr/local/share/perl/5.10.1/ZoneMinder/Control)the exact location depends on the distro.
Now under the control tab of your monitor click "edit" next to "Control Type"
On the new window "Control Capabilities" Click "Add New Control"
When done click "save" and refresh the "Control Capabilities" window, and then close.
At your monitor window, refresh it and from the pull-down menu at "Control Type" select "ABS MegaCam"
complete the rest and when done click "save":
If anything needs to be changed, feel free to yell at me! 
Place the code in a file named "ABS_MegaCam.pm" and add it with the rest of the ZoneMinder Control Perl libraries (mine are in
/usr/local/share/perl/5.10.1/ZoneMinder/Control)the exact location depends on the distro.
Code: Select all
# ==========================================================================
#
# ZoneMinder ABS MegaCam Control Protocol Module, $Date: 2010-06-25
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ==========================================================================
#
# This module contains the implementation of the ABS MegaCam camera control protocol.
# MegaCam 4210, MegaCam 4220
# And possibly MegaCam 421M and MegaCam 422M (not tested but they all use the same Firmware for MegaCam Series)
#
package ZoneMinder::Control::ABS_MegaCam;
use 5.006;
use strict;
use warnings;
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
our $VERSION = $ZoneMinder::Base::VERSION;
# ==========================================================================
#
# ABS MegaCam Control Protocol
#
# ==========================================================================
use ZoneMinder::Debug qw(:all);
use ZoneMinder::Config qw(:all);
use Time::HiRes qw( usleep );
sub new
{
my $class = shift;
my $id = shift;
my $self = ZoneMinder::Control->new( $id );
bless( $self, $class );
srand( time() );
return $self;
}
our $AUTOLOAD;
sub AUTOLOAD
{
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( exists($self->{$name}) )
{
return( $self->{$name} );
}
Fatal( "Can't access $name member of object of class $class" );
}
sub open
{
my $self = shift;
$self->loadMonitor();
use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new;
$self->{ua}->agent( "ZoneMinder Control Agent/".ZM_VERSION );
$self->{state} = 'open';
}
sub close
{
my $self = shift;
$self->{state} = 'closed';
}
sub printMsg
{
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);
Debug( $msg."[".$msg_len."]" );
}
sub sendCmd
{
my $self = shift;
my $cmd = shift;
my $result = undef;
printMsg( $cmd, "Tx" );
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."$cmd" );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed: '".$res->status_line()."'" );
}
return( $result );
}
sub moveMap
{
my $self = shift;
my $params = shift;
my $xcoord = $self->getParam( $params, 'xcoord' );
my $ycoord = $self->getParam( $params, 'ycoord' );
Debug( "Move Map to $xcoord,$ycoord" );
my $cmd = "/ptz.cgi?center=$xcoord,$ycoord&imagewidth=".$self->{Monitor}->{Width}."&imageheight=".$self->{Monitor}->{Height};
$self->sendCmd( $cmd );
}
sub moveRelUp
{
my $self = shift;
my $params = shift;
my $tiltstep = $self->getParam( $params, 'tiltstep' );
Debug( "Move Up - TiltStep $tiltstep" );
my $cmd = "/ptz.cgi?move=up&speed=$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelDown
{
my $self = shift;
my $params = shift;
my $tiltstep = $self->getParam( $params, 'tiltstep' );
Debug( "Move Down - TiltStep $tiltstep" );
my $cmd = "/ptz.cgi?move=down&speed=$tiltstep";
$self->sendCmd( $cmd );
}
sub moveRelLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panstep' );
Debug( "Move Left - PanStep $panstep" );
my $cmd = "/ptz.cgi?move=left&speed=$panstep";
$self->sendCmd( $cmd );
}
sub moveRelRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panstep' );
Debug( "Move Right - PanStep $panstep" );
my $cmd = "/ptz.cgi?move=right&speed=$panstep";
$self->sendCmd( $cmd );
}
sub moveRelUpRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panstep' );
Debug( "Move Up/Right - PanStep $panstep" );
my $cmd = "/ptz.cgi?move=rightup&speed=$panstep";
$self->sendCmd( $cmd );
}
sub moveRelUpLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panstep' );
Debug( "Move Up/Left - PanStep $panstep" );
my $cmd = "/ptz.cgi?move=leftup&speed=$panstep";
$self->sendCmd( $cmd );
}
sub moveRelDownRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panstep' );
Debug( "Move Down/Right - PanStep $panstep" );
my $cmd = "/ptz.cgi?move=rightdown&speed=$panstep";
$self->sendCmd( $cmd );
}
sub moveRelDownLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panstep' );
Debug( "Move Down/Left - PanStep $panstep" );
my $cmd = "/ptz.cgi?move=leftdown&speed=$panstep";
$self->sendCmd( $cmd );
}
sub presetSet
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Set Preset $preset" );
my $cmd = "/ptzconfig.cgi?setserverpresetname=$preset";
$self->sendCmd( $cmd );
}
sub presetGoto
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Goto Preset $preset" );
my $cmd = "/ptz.cgi?gotoserverpresetname=$preset";
$self->sendCmd( $cmd );
}
sub presetHome
{
my $self = shift;
Debug( "Home Preset" );
my $cmd = "/ptz.cgi?move=home&speed=1";
$self->sendCmd( $cmd );
}
1;
__END__
On the new window "Control Capabilities" Click "Add New Control"
Code: Select all
Main Tab:
-----------------
Name: ABS MegaCam
Type: Remote
Protocol: ABS_MegaCam
Move Tab:
-----------------
Can Move: check
Can Move Diagonally: check
Can Move Mapped: check
Can Move Relative: check
Pan Tab:
-----------------
Can Pan: check
Min Pan Step: 0
Max Pan Step: 10 (adjust to your needs. If you feel the need it will go as high as 100)
Tilt Tab:
-----------------
Can Tilt: check
Min Tilt Step: 0
Max Tilt Step: 10 (adjust to your needs. If you feel the need it will go as high as 100)
Presets tab:
-----------------
Has Presets: check
Num Presets: 10
Has Home Preset: check (for this to work you have to select a home preset on the cameras main home page)
Can Set Presets: check
When done click "save" and refresh the "Control Capabilities" window, and then close.
At your monitor window, refresh it and from the pull-down menu at "Control Type" select "ABS MegaCam"
complete the rest and when done click "save":
Code: Select all
Controllable: check
Control Type: ABS MegaCam
Control Device: leave blank
Control Address: user:pass@cameraIP
