Page 1 of 1

Gadget-Spot NC1600HPT Control Script

Posted: Sun May 20, 2007 5:47 pm
by zakalwe
I copied the existing control scripts for other cameras, and took the commands from the html source of the cameras web page.

The pan/tilt speed seems to have no effect, and I don't have an auto-iris, or zoom lens, so I can't verify that those commands work.

Presets have never worked for me, even in the native interface. The camera just seems to go into a continuous pan back and forward forever.

As the movement is continuous only, I'm not entirely sure that this is correct. I can't seem to get the autostop to work. On the cameras native interface the movement is stopped by an "onmouseup" event, ie. to move the camera you must hold down the movement buttons. Have I missed something and can zoneminder do this itself?

Code: Select all

#!/usr/bin/perl -wT
#
# ==========================================================================
#
# ZoneMinder Panasonic IP Camera Control Script, $Date: 2006/05/08 12:37:48 $, $Revision: 1.5 $
# Copyright (C) 2003, 2004, 2005, 2006  Philip Coombes
#
# 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 script continuously monitors the recorded events for the given
# monitor and applies any filters which would delete and/or upload
# matching events
#
use strict;

# ==========================================================================
#
# These are the elements you can edit to suit your installation
#
# ==========================================================================

use constant DBG_ID => "zmctrl-gadip"; # Tag that appears in debug to identify source
use constant DBG_LEVEL => 0; # 0 is errors, warnings and info only, > 0 for debug

# ==========================================================================

use ZoneMinder;
use Getopt::Long;

$| = 1;

$ENV{PATH}  = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};

sub Usage
{
        print( "
Usage: zmcontrol-gadspot-ip.pl <various options>
");
        exit( -1 );
}

zmDbgInit( DBG_ID, level=>DBG_LEVEL );

my $arg_string = join( " ", @ARGV );

my $address;
my $command;
my ( $speed, $step );
my ( $xcoord, $ycoord );
my ( $width, $height );
my ( $panspeed, $tiltspeed );
my ( $panstep, $tiltstep );
my $preset;
my $autostop;

if ( !GetOptions(
        'address=s'=>\$address,
        'command=s'=>\$command,
        'autostop=f'=>\$autostop,
        'speed=i'=>\$speed,
        'step=i'=>\$step,
        'xcoord=i'=>\$xcoord,
        'ycoord=i'=>\$ycoord,
        'width=i'=>\$width,
        'height=i'=>\$height,
        'panspeed=i'=>\$panspeed,
        'tiltspeed=i'=>\$tiltspeed,
        'panstep=i'=>\$panstep,
        'tiltstep=i'=>\$tiltstep,
        'preset=i'=>\$preset
        )
)
{
        Usage();
}

if ( !$address )
{
        Usage();
}

if ( defined($autostop) )
{
        # Convert to microseconds.
        $autostop = int(1000000*$autostop);
}

Debug( $arg_string."\n" );

srand( time() );

sub printMsg
{
        my $msg = shift;
        my $msg_len = length($msg);

        Debug( $msg."[".$msg_len."]\n" );
}

sub sendCmd
{
        my $cmd = shift;

        my $result = undef;

        printMsg( $cmd, "Tx" );

        use LWP::UserAgent;
        my $ua = LWP::UserAgent->new;
        $ua->agent( "ZoneMinder Control Agent/".ZM_VERSION );

        #print( "http://$address/$cmd\n" );
        my $req = HTTP::Request->new( GET=>"http://$address/$cmd" );
        my $res = $ua->request($req);

        if ( $res->is_success )
        {
                $result = !undef;
        }
        else
        {
                Error( "Error check failed: '".$res->status_line()."'\n" );
        }

        return( $result );
}

sub moveUp
{
        Debug( "Move Up\n" );
        my $cmd = "PTZCmd.cgi?Cmd=UP";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub moveDown
{
        Debug( "Move Down\n" );
        my $cmd = "PTZCmd.cgi?Cmd=DOWN";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub moveLeft
{
        Debug( "Move Left\n" );
        my $cmd = "PTZCmd.cgi?Cmd=LEFT";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub moveRight
{
        Debug( "Move Right\n" );
        my $cmd = "PTZCmd.cgi?Cmd=RIGHT";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub moveUpRight
{
        Debug( "Move Right\n" );
        my $cmd = "PTZCmd.cgi?Cmd=RIGHT_UP";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub moveUpLeft
{
        Debug( "Move Right\n" );
        my $cmd = "PTZCmd.cgi?Cmd=LEFT_UP";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub moveDownRight
{
        Debug( "Move Right\n" );
        my $cmd = "PTZCmd.cgi?Cmd=RIGHT_DOWN";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub moveDownLeft
{
        Debug( "Move Right\n" );
        my $cmd = "PTZCmd.cgi?Cmd=LEFT_DOWN";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub setSpeed
{
        Debug( "Set Speed\n");
        my $cmd = "SetPTZ.cgi?Speed=$panspeed";
        sendCmd( $cmd );
}

sub stop
{
        Debug( "STOP\n" );
        my $cmd = "PTZCmd.cgi?Cmd=STOP";
        sendCmd( $cmd );
}


sub zoomTele
{
        Debug( "Zoom Tele\n" );
        my $cmd = "PTZCmd.cgi?Cmd=ZOOM_TELE";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub zoomWide
{
        Debug( "Zoom Wide\n" );
        my $cmd = "PTZCmd.cgi?Cmd=ZOOM_WIDE";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub focusNear
{
        Debug( "Focus Near\n" );
        my $cmd = "PTZCmd.cgi?Cmd==FOCUS_NEAR";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub focusFar
{
        Debug( "Focus Far\n" );
        my $cmd = "PTZCmd.cgi?Cmd=FOCUS_FAR";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }

}

sub focusAuto
{
        Debug( "Focus Auto\n" );
        my $cmd = "PTZCmd.cgi?Cmd=FOCUS_AUTO";
        sendCmd( $cmd );
}

sub irisClose
{
        Debug( "Iris Close\n" );
        my $cmd = "PTZCmd.cgi?Cmd=IRIS_CLOSE";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub irisOpen
{
        Debug( "Iris Open\n" );
        my $cmd = "PTZCmd.cgi?Cmd=IRIS_OPEN";
        sendCmd( $cmd );
        if ( $autostop )
        {
                usleep( $autostop );
                stop();
        }
}

sub irisAuto
{
        Debug( "Iris Auto\n" );
        my $cmd = "PTZCmd.cgi?Cmd=IRIS_AUTO";
        sendCmd( $cmd );
}

sub presetClear
{
        my $preset = shift || 1;
        Debug( "Clear Preset $preset\n" );
        my $cmd = "nphPresetNameCheck?Data=$preset";
        sendCmd( $cmd );
}

sub presetSet
{
        my $preset = shift || 1;
        Debug( "Set Preset $preset\n" );
        my $cmd = "PTZCmd.cgi?Cmd=SET_PRESET&PresetID=$preset";
        sendCmd( $cmd );
}

sub presetGoto
{
        my $preset = shift || 1;
        Debug( "Goto Preset $preset\n" );
        my $cmd = "PTZCmd.cgi?Cmd=CALL_PRESET&PresetID=$preset";
        sendCmd( $cmd );
}

if ( $command eq "move_con_up" )
{
        moveUp();
}
elsif ( $command eq "move_con_down" )
{
        moveDown();
}
elsif ( $command eq "move_con_left" )
{
        moveLeft();
}
elsif ( $command eq "move_con_right" )
{
        moveRight();
}
elsif ( $command eq "move_con_upleft" )
{
        moveUpLeft();
}
elsif ( $command eq "move_con_upright" )
{
        moveUpRight();
}
elsif ( $command eq "move_con_downleft" )
{
        moveDownLeft();
}
elsif ( $command eq "move_con_downright" )
{
        moveDownRight();
}
elsif ( $command eq "move_stop" )
{
        stop();
}
elsif ( $command eq "zoom_con_tele" )
{
        zoomTele();
}
elsif ( $command eq "zoom_con_wide" )
{
        zoomWide();
}
elsif ( $command eq "zoom_stop" )
{
        stop();
}
elsif ( $command eq "focus_con_near" )
{
        focusNear();
}
elsif ( $command eq "focus_con_far" )
{
        focusFar();
}
elsif ( $command eq "focus_auto" )
{
        focusAuto();
}
elsif ( $command eq "focus_stop" )
{
        stop();
}
elsif ($command eq "iris_con_close" )
{
        irisClose();
}
elsif ($command eq "iris_con_open" )
{
        irisOpen();
}
elsif ($command eq "iris_auto" )
{
        irisAuto();
}
elsif ( $command eq "iris_stop" )
{
        stop();
}

elsif ( $command eq "preset_set" )
{
        presetSet( $preset );
}
elsif ( $command eq "preset_goto" )
{
        presetGoto( $preset );
}
else
{
        Error( "Can't handle command $command\n" );
}