Update, add url parsing to match other control scripts. Add getConfig and setConfig
This commit is contained in:
parent
cebe86feb2
commit
c864d0765b
|
@ -41,120 +41,133 @@ our @ISA = qw(ZoneMinder::Control);
|
||||||
|
|
||||||
use ZoneMinder::Logger qw(:all);
|
use ZoneMinder::Logger qw(:all);
|
||||||
use ZoneMinder::Config qw(:all);
|
use ZoneMinder::Config qw(:all);
|
||||||
|
use ZoneMinder::General qw(:all);
|
||||||
|
|
||||||
use Time::HiRes qw( usleep );
|
use Time::HiRes qw( usleep );
|
||||||
|
use URI::Encode qw(uri_encode);
|
||||||
|
|
||||||
sub open
|
our $REALM = '';
|
||||||
{
|
our $PROTOCOL = 'http://';
|
||||||
my $self = shift;
|
our $USERNAME = 'admin';
|
||||||
|
our $PASSWORD = '';
|
||||||
|
our $ADDRESS = '';
|
||||||
|
our $BASE_URL = '';
|
||||||
|
|
||||||
$self->loadMonitor();
|
sub open {
|
||||||
Debug( "Camera open" );
|
my $self = shift;
|
||||||
use LWP::UserAgent;
|
$self->loadMonitor();
|
||||||
$self->{ua} = LWP::UserAgent->new;
|
|
||||||
$self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION );
|
|
||||||
|
|
||||||
$self->{state} = 'open';
|
if (($self->{Monitor}->{ControlAddress} =~ /^(?<PROTOCOL>https?:\/\/)?(?<USERNAME>[^:@]+)?:?(?<PASSWORD>[^\/@]+)?@?(?<ADDRESS>.*)$/)) {
|
||||||
|
$PROTOCOL = $+{PROTOCOL} if $+{PROTOCOL};
|
||||||
|
$USERNAME = $+{USERNAME} if $+{USERNAME};
|
||||||
|
$PASSWORD = $+{PASSWORD} if $+{PASSWORD};
|
||||||
|
$ADDRESS = $+{ADDRESS} if $+{ADDRESS};
|
||||||
|
} else {
|
||||||
|
Error('Failed to parse auth from address ' . $self->{Monitor}->{ControlAddress});
|
||||||
|
$ADDRESS = $self->{Monitor}->{ControlAddress};
|
||||||
|
}
|
||||||
|
if ( !($ADDRESS =~ /:/) ) {
|
||||||
|
Error('You generally need to also specify the port. I will append :80');
|
||||||
|
$ADDRESS .= ':80';
|
||||||
|
}
|
||||||
|
$BASE_URL = $PROTOCOL.($USERNAME?$USERNAME.':'.$PASSWORD.'@':'').$ADDRESS;
|
||||||
|
|
||||||
|
use LWP::UserAgent;
|
||||||
|
$self->{ua} = LWP::UserAgent->new;
|
||||||
|
$self->{ua}->agent( 'ZoneMinder Control Agent/'.ZoneMinder::Base::ZM_VERSION );
|
||||||
|
$self->{state} = 'open';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub close
|
sub close {
|
||||||
{
|
my $self = shift;
|
||||||
my $self = shift;
|
$self->{state} = 'closed';
|
||||||
$self->{state} = 'closed';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub printMsg
|
sub sendCmd {
|
||||||
{
|
my ($self, $cmd, $speedcmd) = @_;
|
||||||
my $msg = shift;
|
|
||||||
my $msg_len = length($msg);
|
|
||||||
|
|
||||||
Debug( $msg."[".$msg_len."]" );
|
$self->printMsg( $speedcmd, 'Tx' );
|
||||||
|
$self->printMsg( $cmd, 'Tx' );
|
||||||
|
|
||||||
|
my $req = HTTP::Request->new( GET => $BASE_URL."/cgi-bin/camctrl/eCamCtrl.cgi?stream=0&$speedcmd&$cmd");
|
||||||
|
my $res = $self->{ua}->request($req);
|
||||||
|
|
||||||
|
if (!$res->is_success) {
|
||||||
|
Error('Request failed: '.$res->status_line().' (URI: '.$req->as_string().')');
|
||||||
|
}
|
||||||
|
return $res->is_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub sendCmd
|
sub moveConUp {
|
||||||
{
|
my ($self, $params) = @_;
|
||||||
my ($self, $cmd, $speedcmd) = @_;
|
my $speed = 'speedtilt=' . ($params->{tiltspeed} - 6);
|
||||||
|
$self->sendCmd( 'move=up', $speed );
|
||||||
my $result = undef;
|
|
||||||
|
|
||||||
printMsg( $speedcmd, "Tx" );
|
|
||||||
printMsg( $cmd, "Tx" );
|
|
||||||
|
|
||||||
my $req = HTTP::Request->new( GET => "http://" . $self->{Monitor}->{ControlAddress} . "/cgi-bin/camctrl/eCamCtrl.cgi?stream=0&$speedcmd&$cmd" );
|
|
||||||
my $res = $self->{ua}->request($req);
|
|
||||||
|
|
||||||
if ( $res->is_success )
|
|
||||||
{
|
|
||||||
$result = !undef;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Error( "Request failed: '" . $res->status_line() . "' (URI: '" . $req->as_string() . "')" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( $result );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub moveConUp
|
sub moveConDown {
|
||||||
{
|
my ($self, $params) = @_;
|
||||||
my ($self, $params) = @_;
|
my $speed = 'speedtilt=' . ($params->{tiltspeed} - 6);
|
||||||
my $speed = 'speedtilt=' . ($params->{tiltspeed} - 6);
|
$self->sendCmd( 'move=down', $speed );
|
||||||
Debug( "Move Up" );
|
|
||||||
$self->sendCmd( 'move=up', $speed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub moveConDown
|
sub moveConLeft {
|
||||||
{
|
my ($self, $params) = @_;
|
||||||
my ($self, $params) = @_;
|
my $speed = 'speedpan=-' . $params->{panspeed};
|
||||||
my $speed = 'speedtilt=' . ($params->{tiltspeed} - 6);
|
$self->sendCmd( 'move=left', $speed );
|
||||||
Debug( "Move Down" );
|
|
||||||
$self->sendCmd( 'move=down', $speed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub moveConLeft
|
sub moveConRight {
|
||||||
{
|
my ($self, $params) = @_;
|
||||||
my ($self, $params) = @_;
|
my $speed = 'speedpan=' . ($params->{panspeed} - 6);
|
||||||
my $speed = 'speedpan=-' . $params->{panspeed};
|
$self->sendCmd( 'move=right', $speed );
|
||||||
Debug( "Move Left" );
|
|
||||||
$self->sendCmd( 'move=left', $speed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub moveConRight
|
sub moveStop {
|
||||||
{
|
my $self = shift;
|
||||||
my ($self, $params) = @_;
|
Debug( "Move Stop: not implemented" );
|
||||||
my $speed = 'speedpan=' . ($params->{panspeed} - 6);
|
# not implemented
|
||||||
Debug( "Move Right" );
|
|
||||||
$self->sendCmd( 'move=right', $speed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub moveStop
|
sub zoomConTele {
|
||||||
{
|
my ($self, $params) = @_;
|
||||||
my $self = shift;
|
my $speed = 'speedzoom=' . ($params->{speed} - 6);
|
||||||
Debug( "Move Stop" );
|
$self->sendCmd( 'zoom=tele', $speed );
|
||||||
# not implemented
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub zoomConTele
|
sub zoomConWide {
|
||||||
{
|
my ($self, $params) = @_;
|
||||||
my ($self, $params) = @_;
|
my $speed = 'speedzoom=' . ($params->{speed} - 6);
|
||||||
my $speed = 'speedzoom=' . ($params->{speed} - 6);
|
$self->sendCmd( 'zoom=wide', $speed );
|
||||||
Debug( "Zoom In" );
|
|
||||||
$self->sendCmd( 'zoom=tele', $speed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub zoomConWide
|
sub reset {
|
||||||
{
|
my $self = shift;
|
||||||
my ($self, $params) = @_;
|
$self->sendCmd( 'move=home' );
|
||||||
my $speed = 'speedzoom=' . ($params->{speed} - 6);
|
|
||||||
Debug( "Zoom Out" );
|
|
||||||
$self->sendCmd( 'zoom=wide', $speed );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub reset
|
sub get_config {
|
||||||
{
|
my $self = shift;
|
||||||
my $self = shift;
|
|
||||||
Debug( "Camera Reset" );
|
my $url = $BASE_URL.'/cgi-bin/admin/lsctrl.cgi?cmd=queryStatus&retType=javascript';
|
||||||
$self->sendCmd( 'move=home' );
|
my $req = new HTTP::Request(GET => $url);
|
||||||
|
my $response = $self->{ua}->request($req);
|
||||||
|
if ( $response->is_success() ) {
|
||||||
|
my $resp = $response->decoded_content;
|
||||||
|
return ZoneMinder::General::parseNameEqualsValueToHash($resp);
|
||||||
|
}
|
||||||
|
Warn("Failed to get config from $url: " . $response->status_line());
|
||||||
|
return;
|
||||||
|
} # end sub get_config
|
||||||
|
|
||||||
|
sub set_config {
|
||||||
|
my $self = shift;
|
||||||
|
my $diff = shift;
|
||||||
|
|
||||||
|
my $url = $BASE_URL.'/cgi-bin/'.$USERNAME.'/setparam.cgi?'.
|
||||||
|
join('&', map { $_.'='.uri_encode($$diff{$_}) } keys %$diff);
|
||||||
|
my $response = $self->{ua}->get($url);
|
||||||
|
Debug($response->content);
|
||||||
|
return $response->is_success();
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in New Issue