we have completed a working module to use with Mobotix MegaPixel Camera.
Name this as Mobotix.pm and copy it in /usr/lib/perl5/site_perl/5.x.x/ZoneMinder/Control/Mobotix.pm
Code: Select all
# ==========================================================================
#
# This module contains the implementation of the Mobotix protocol
# It is easy to adapt to all Mobotix cameras. We have found a lot of commands
# using: http://<IP-Camera>/control/click.cgi?help or http://<IP-Camera>/control/click.cgi?list
# Any improve is welcome, and please share it
# Fabio Maresca AND Pasquale Riccio
# fabio.maresca[at]gmail[dot]com
package ZoneMinder::Control::Mobotix;
use 5.006;
use strict;
use warnings;
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
our $VERSION = $ZoneMinder::Base::VERSION;
# ==========================================================================
#
# Mobotix 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" );
#print( "http://$address/$cmd\n" );
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 receiveCmd
{
my $self = shift;
my $cmd = shift;
my $result = undef;
printMsg( $cmd, "Rx" );
#print( "http://$address/$cmd\n" );
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."$cmd" );
my $res = $self->{ua}->request($req);
my $content = $res->content();
if ( $res->is_success )
{
$result = $content;
}
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' );
my $imagewidth = $self->{Monitor}->{Width};
my $imageheight = $self->{Monitor}->{Height};
Debug( "Move Map to $xcoord,$ycoord at $imagewidth/$imageheight" );
if ( $imagewidth == "640" )
{
$xcoord = $xcoord/2;
$ycoord = $ycoord/2;
}
my $cmd = "/control/click.cgi?x=$xcoord&y=$ycoord";
$self->sendCmd( $cmd );
}
sub moveRelLeft
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Left - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=-$step&y=0";
$self->sendCmd( $cmd );
}
sub moveRelRight
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Right - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=$step&y=0";
$self->sendCmd( $cmd );
}
sub moveRelUp
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Up - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=0&y=$step";
$self->sendCmd( $cmd );
}
sub moveRelDown
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Down - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=0&y=-$step";
$self->sendCmd( $cmd );
}
sub moveRelUpRight
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Up Right - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=$step&y=$step";
$self->sendCmd( $cmd );
}
sub moveRelUpLeft
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Up Left - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=-$step&y=$step"
$self->sendCmd( $cmd );
}
sub moveRelDownRight
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Down Right - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=$step&y=-$step";
$self->sendCmd( $cmd );
}
sub moveRelDownLeft
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Move Down Left - Step $step" );
my $cmd = "/control/click.cgi?moverel&x=-$step&y=-$step";
$self->sendCmd( $cmd );
}
sub zoomRelTele
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Zoom Tele" );
my $cmd = "/control/click.cgi?zoomrel=$step";
$self->sendCmd( $cmd );
}
sub zoomRelWide
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'step' );
Debug( "Zoom Wide" );
my $cmd = "/control/click.cgi?zoomrel=-$step";
$self->sendCmd( $cmd );
}
sub presetClear
{
my $self = shift;
my $params = shift;
Debug( "Clear All Presets" );
my $cmd = "/control/click.cgi?delete_all_views";
$self->sendCmd( $cmd );
}
sub presetSet
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
my $preset = ( $preset - 1 );
my $cmd = "/control/click.cgi?setview=$preset";
Debug( "Set Preset $preset" );
$self->sendCmd( $cmd );
}
sub presetGoto
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
my $preset = ( $preset - 1 );
Debug( "Goto Preset $preset" );
my $cmd = "/control/click.cgi?loadview=$preset";
$self->sendCmd( $cmd );
}
sub presetHome
{
my $self = shift;
Debug( "Home Preset" );
my $cmd = "/control/click.cgi?zoom=1000";
$self->sendCmd( $cmd );
}
1;
__END__
In this module you have:
relative zoom (tele/wide)
relative pan/tilt
mapped movement
complete preset functions
special thx to
linuccio