-
-
Save edwork/3564a711805889e0a2d53cd074807712 to your computer and use it in GitHub Desktop.
Control script for Sannce Cameras (work in progress)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ZoneMinder::Control::Sannce; | |
use 5.006; | |
use strict; | |
use warnings; | |
require ZoneMinder::Base; | |
require ZoneMinder::Control; | |
our @ISA = qw(ZoneMinder::Control); | |
our %CamParams = (); | |
# ========================================================================== | |
# | |
# Sannce 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( ) || 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/".ZoneMinder::Base::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}."/cgi-bin/action.cgi?cmd=$cmd" ); | |
my $res = $self->{ua}->request($req); | |
if ( $res->is_success ) | |
{ | |
$result = !undef; | |
} | |
else | |
{ | |
Error( "Error check failed:'".$res->status_line()."'" ); | |
} | |
return( $result ); | |
} | |
# Reset the Camera | |
sub reset | |
{ | |
my $self = shift; | |
Debug( "Camera Reset" ); | |
$self->sendCmd( "reboot" ); | |
} | |
#Up Arrow | |
sub moveRelUp | |
{ | |
my $self = shift; | |
Debug( "Move Up" ); | |
my $cmd = "decoder_control.cgi?command=0"; | |
$self->sendCmd( "motor_up" ); | |
} | |
#Down Arrow | |
sub moveRelDown | |
{ | |
my $self = shift; | |
Debug( "Move Down" ); | |
my $cmd = "decoder_control.cgi?command=2"; | |
$self->sendCmd( "motor_down" ); | |
} | |
#Left Arrow | |
sub moveRelLeft | |
{ | |
my $self = shift; | |
Debug( "Move Left" ); | |
my $cmd = "decoder_control.cgi?command=4"; | |
$self->sendCmd( "motor_left" ); | |
} | |
#Right Arrow | |
sub moveRelRight | |
{ | |
my $self = shift; | |
Debug( "Move Right" ); | |
my $cmd = "decoder_control.cgi?command=6"; | |
$self->sendCmd( "motor_right" ); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Profile for Sannce cameras in Zoneminder for PTZ control.
WIP - This is still mostly code for Xiomi Dafang Cameras!