Zoneminder: modulo di controllo per Bosesh SD13W

Modulo Perl per controllare la Bosesh SD13W con Zoneminder.

SD13W.pm:

# ==========================================================================
#
# ZoneMinder Bosesh SD13W IP Control Protocol Module, $Date: 2017-05-30 01:18:22 +0100 (Wed, 04 Nov 2009) $, $Revision: 1 $
# Copyright (C) 2017 Mentor (http://www.internauta37.altervista.org)
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ==========================================================================
#
# This module is based on SPP1802SWPTZ.pm
#
# ==========================================================================
#
# This module contains the implementation of the Bosesh SD13W IP camera control
# protocol
#

package MyAgent;

use base 'LWP::UserAgent';


package ZoneMinder::Control::SD13W;
 
use 5.006;
use strict;
use warnings;
 
require ZoneMinder::Base;
require ZoneMinder::Control;
 
our @ISA = qw(ZoneMinder::Control);
 
our $VERSION = $ZoneMinder::Base::VERSION;
 
# ==========================================================================
#
# Bosesh SD13W IP Control Protocol
#
# ==========================================================================
 
use ZoneMinder::Logger 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 );
	my $logindetails = "";
	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" );
}
our $stop_command;
 
sub open
{
	my $self = shift;
 
	$self->loadMonitor();
 
	$self->{ua} = MyAgent->new;
	$self->{ua}->agent( "ZoneMinder Control Agent/" );
 
	$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"."&".$self->{Monitor}->{ControlDevice});
	my $res = $self->{ua}->request($req);
 
	if ( $res->is_success )
	{
		$result = !undef;
	}
	else
	{
		Error( "Error really, REALLY check failed:'".$res->status_line()."'" );
		Error ("Cmd:".$cmd);
	}
 
	return( $result );
}
 
sub reset
{
	my $self = shift;
	Debug( "Camera Reset" );
	my $cmd = "sysreboot.cgi?";
	$self->sendCmd( $cmd );
}

#Up Arrow
sub Up
{
        my $self = shift;
        Debug( "Move Up" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=up";
        $self->sendCmd( $cmd );
}

#Down Arrow
sub Down
{
        my $self = shift;
        Debug( "Move Up" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=down";
        $self->sendCmd( $cmd );
}

#Left Arrow
sub Left
{
        my $self = shift;
        Debug( "Move Up" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=left";
        $self->sendCmd( $cmd );
}

#Right Arrow
sub Right
{
        my $self = shift;
        Debug( "Move Up" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=right";
        $self->sendCmd( $cmd );
}

#Up Arrow
sub moveConUp
{
	my $self = shift;
	Debug( "Move Up" );
	my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=up";
	$self->sendCmd( $cmd );
	$self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}
 
#Down Arrow
sub moveConDown
{
	my $self = shift;
	Debug( "Move Down" );
	my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=down";
	$self->sendCmd( $cmd );
}
 
#Left Arrow
sub moveConLeft
{
	my $self = shift;
	Debug( "Move Left" );
	my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=left";
	$self->sendCmd( $cmd );
	$self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}
 
#Right Arrow
sub moveConRight
{
	my $self = shift;
	Debug( "Move Right" );
	my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=right";
	$self->sendCmd( $cmd );
	$self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}
 
#Stop
sub moveStop
{
	my $self = shift;
	Debug( "Move Stop" );
	my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=stop";
	$self->sendCmd( $cmd );
}

sub autoStop
{
	my $self = shift;
	my $autostop = shift;
	if( $autostop ) {
		Debug( "Auto Stop" );
		usleep( $autostop );
		my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=stop";
		$self->sendCmd( $cmd );
	}
}

##Zoom
sub Tele
{
    my $self = shift;
    Debug( "Zoom Tele" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=zoomin";
    $self->sendCmd( $cmd );
}

sub Wide
{
    my $self = shift;
    Debug( "Zoom Wide" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=zoomout";
    $self->sendCmd( $cmd );
}

sub zoomConTele
{
    my $self = shift;
    Debug( "Zoom Tele" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=zoomin";
    $self->sendCmd( $cmd );
    $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}

sub zoomConWide
{
    my $self = shift;
    Debug( "Zoom Wide" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=zoomout";
    $self->sendCmd( $cmd );
    $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}

sub zoomStop
{
        my $self = shift;
        Debug( "Zoom Stop" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=stop";
        $self->sendCmd( $cmd );
}

##Focus
sub focusNear
{
    my $self = shift;
    Debug( "Focus Near" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=focusin";
    $self->sendCmd( $cmd );
}

sub focusFar
{
    my $self = shift;
    Debug( "Focus Far" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=focusout";
    $self->sendCmd( $cmd );
}

sub focusConNear
{
    my $self = shift;
    Debug( "Focus Near" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=focusin";
    $self->sendCmd( $cmd );
    $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}

sub focusConFar
{
    my $self = shift;
    Debug( "Focus Far" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=focusout";
    $self->sendCmd( $cmd );
    $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}
 
#Move Camera to Home Position
sub presetHome
{
	my $self = shift;
	Debug( "Home Preset" );
	my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=home";
	$self->sendCmd( $cmd );
}
 
#Set preset
sub presetSet
{
    my $self = shift;
    my $params = shift;
    my $preset = ( $self->getParam( $params, 'preset' ) -1 );
    my $presetCmd = "cgi-bin/hi3510/preset.cgi?-act=set&-status=1&-number=$preset";
    Debug( "Set Preset $preset with cmd $presetCmd" );
    my $cmd = $presetCmd;
    $self->sendCmd( $cmd );
}
 
#Goto preset
sub presetGoto
{
    my $self = shift;
    my $params = shift;
    my $preset = ( $self->getParam( $params, 'preset' ) -1 );
    my $presetCmd = "cgi-bin/hi3510/preset.cgi?-act=goto&-status=1&-number=$preset";
    Debug( "Set Preset $preset with cmd $presetCmd" );
    my $cmd = $presetCmd;
    $self->sendCmd( $cmd );
}
 
#Turn IR on
sub wake
{
	my $self = shift;
	Debug( "Wake - IR on" );
	my $cmd = "cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=auto";
	$self->sendCmd( $cmd );
}
 
#Turn IR off
sub sleep
{
	my $self = shift;
	Debug( "Sleep - IR off" );
	my $cmd = "cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=close";
	$self->sendCmd( $cmd );
}
 
1;
__END__
=head1 NAME
ZoneMinder::Database - Perl extension for Bosesh SD13W
=head1 SYNOPSIS
  use ZoneMinder::Control::SD13W
  Control module for for Bosesh SD13W
=head1 DESCRIPTION
This module contains the implementation of the Bosesh SD13W IP
camera control protocol.
=head2 EXPORT
None by default.
=head1 SEE ALSO
You can find the documentation at:
http://www.internauta37.altervista.org/en/zoneminder-control-module-bosesh-sd13w
=head1 AUTHOR
Philip Coombes, <[email protected]>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2001-2008  Philip Coombes
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
=cut

Il modulo SD13W.pm deve essere messo nel percorso:

/usr/share/perl5/ZoneMinder/Control

con permessi 644.

In Zoneminder deve essere abilitato Options>System>OPT_CONTROL √.

Il monitor per la Bosesh SD13W può essere configurato come segue:

Main

Name: NAME_YOU_WANT
Source Type: Remote
Function: Modect
Enabled: √
 
Source
 
Remote Protocol: HTTP
Remote Method: Simple
Remote Host Name: IP
Remote Host Port: 80 (80 is the default port of Bosesh SD13W)
Remote Host Path: /tmpfs/auto.jpg?usr=admin&pwd=admin (admin is the default password of Bosesh SD13W)
Target colorspace: 24 bit colour
Capture Width (pixels): 640
Capture Width (pixels): 352
 
Control
 
Controllable: √
Control Type: Edit
Add New Control
 
Main
 
Name: SD13W
Type: Remote
Protocol: SD13W
Can Wake: √
Can Sleep: √
Can Reset: √
 
Move
 
Can Move: √
Can Move Continuous: √
 
Pan
 
Can Pan: √
Has Pan Speed: √
Min Pan Speed: 1
Max Pan Speed: 63
 
Tilt
 
Can Tilt: √
Has Tilt Speed: √
Min Tilt Speed: 1
Max Tilt Speed: 63
 
Zoom
 
Can Zoom: √
Can Zoom Continuous: √
Has Zoom Speed: √
Min Zoom Speed: 1
Max Zoom Speed: 63
 
Focus
 
Can Focus: √
Can Focus Continuous: √
Has Focus Speed: √
Min Focus Speed: 1
Max Focus Speed: 63
 
Presets
 
Has presets: √
Num Presets: 32
Has Home Preset: √
Can Set Presets: √
 
Control Type: SD13W
Control Device: usr=admin&pwd=admin
Control Address: IP:PORT (ex. 192.168.1.100)

 

La Bosesh SD13W può anche essere configurata per la risoluzione 1280x720 come segue:

Remote Host Path: /tmpfs/snap.jpg?usr=admin&pwd=admin
Target colorspace: 24 bit colour
Capture Width (pixels): 1280
Capture Width (pixels): 720

 

La Bosesh SD13W può anche essere configurata per usare lo stream video ffmpeg come segue:

Main stream:               rtsp://admin:PWD@IP:554/11 o rtsp://IP:554/11       1280*720
Sub stream:                rtsp://admin:PWD@IP:554/12 o rtsp://IP:554/12        640*352
Mobile stream:            rtsp://admin:PWD@IP:554/13 o rtsp://IP:554/13        320*176

 

Path alternativi per la configurazione Remote:

Main stream:               /cgi-bin/hi3510/snap.cgi?&-getstream&-chn=1?usr=admin&pwd=PWD       1280*720
Sub stream:                /cgi-bin/hi3510/snap.cgi?&-getstream&-chn=2?usr=admin&pwd=PWD        640*352
Mobile stream:            /cgi-bin/hi3510/snap.cgi?&-getstream&-chn=3?usr=admin&pwd=PWD        320*176

 

L'ultimo firmware 11.1.4.x può essere scaricato da qui.

Section: 

Commenti

Aggiungi un commento