Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: Perl  |  size: 6.11 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # ==========================================================================
  2. #
  3. # ZoneMinder Foscam FI8918W IP Control Protocol Module, $Date: 2009-11-25 09:20:00 +0000 (Wed, 04 Nov 2009) $, $Revision: 0001 $
  4. # Copyright (C) 2001-2008 Philip Coombes
  5. # Modified for use with Foscam FI8918W IP Camera by Dave Harris
  6. # Modified Feb 2011 by Howard Durdle (http://durdl.es/x) to:
  7. #       fix horizontal panning, add presets and IR on/off
  8. #       use Control Device field to pass username and password
  9. #
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. #
  23. # ==========================================================================
  24. #
  25. # This module contains the implementation of the Foscam FI8918W IP camera control
  26. # protocol
  27. #
  28.  
  29. package ZoneMinder::Control::FoscamFI8918W;
  30.  
  31. use 5.006;
  32. use strict;
  33. use warnings;
  34.  
  35. require ZoneMinder::Base;
  36. require ZoneMinder::Control;
  37.  
  38. our @ISA = qw(ZoneMinder::Control);
  39.  
  40. our $VERSION = $ZoneMinder::Base::VERSION;
  41.  
  42. # ==========================================================================
  43. #
  44. # Foscam FI8918W IP Control Protocol
  45. #
  46. # ==========================================================================
  47.  
  48. use ZoneMinder::Debug qw(:all);
  49. use ZoneMinder::Config qw(:all);
  50.  
  51.    use Time::HiRes qw( usleep );
  52.  
  53. sub new
  54. {
  55.         my $class = shift;
  56.         my $id = shift;
  57.         my $self = ZoneMinder::Control->new( $id );
  58.         my $longindetails = "";
  59.         bless( $self, $class );
  60.         srand( time() );
  61.         return $self;
  62. }
  63.  
  64. our $AUTOLOAD;
  65.  
  66. sub AUTOLOAD
  67. {
  68.         my $self = shift;
  69.         my $class = ref($self) || croak( "$self not object" );
  70.         my $name = $AUTOLOAD;
  71.         $name =~ s/.*://;
  72.         if ( exists($self->{$name}) )
  73.         {
  74.                 return( $self->{$name} );
  75.         }
  76.         Fatal( "Can't access $name member of object of class $class" );
  77. }
  78. our $stop_command;
  79.  
  80. sub open
  81. {
  82.         my $self = shift;
  83.        
  84.         $self->loadMonitor();
  85.  
  86.         use LWP::UserAgent;
  87.         $self->{ua} = LWP::UserAgent->new;
  88.         $self->{ua}->agent( "ZoneMinder Control Agent/".ZM_VERSION );
  89.  
  90.         $self->{state} = 'open';
  91. }
  92.  
  93. sub close
  94. {
  95.         my $self = shift;
  96.         $self->{state} = 'closed;
  97. }
  98.  
  99. sub printMsg
  100. {
  101.         my $self = shift;
  102.         my $msg = shift;
  103.         my $msg_len = length($msg);
  104.  
  105.         Debug( $msg."[".$msg_len."]" );
  106. }
  107.  
  108. sub sendCmd
  109. {
  110.         my $self = shift;
  111.         my $cmd = shift;
  112.         my $result = undef;
  113.         printMsg( $cmd, "Tx" );
  114.  
  115.         my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/$cmd".$self->{Monitor}->{ControlDevice} );
  116.         my $res = $self->{ua}->request($req);
  117.         if ( $res->is_success )
  118.         {
  119.                 $result = !undef;
  120.         }
  121.         else
  122.         {
  123.                 Error( "Error check failed:'".$res->status_line()."'" );
  124.         }
  125.         return( $result );
  126. }
  127.  
  128. sub reset
  129. {
  130.         my $self = shift;
  131.         Debug(  "Camera Reset" };
  132.         my $cmd = "reboot.cgi?";
  133.         $self->sendCmd( $cmd );
  134. }
  135.  
  136. #Up Arrow
  137. sub moveConUp
  138. {
  139.         my $self = shift;
  140.         $stop_command = "1";
  141.         Debug( "Move Up" );
  142.         my $cmd =  "decoder_control.cgi?command=0&";
  143.         $self->sendCmd( $cmd );
  144. }
  145.  
  146. #Down Arrow
  147. sub moveConDown
  148. {
  149.         my $self = shift;
  150.         $stop_command = "1";
  151.         Debug( "Move Down" );
  152.         my $cmd =  "decoder_control.cgi?command=2&";
  153.         $self->sendCmd( $cmd );
  154. }
  155.  
  156. #Left Arrow
  157. sub moveConLeft
  158. {
  159.         my $self = shift;
  160.         $stop_command = "1";
  161.         Debug( "Move Left" );
  162.         my $cmd =  "decoder_control.cgi?command=6&";
  163.         $self->sendCmd( $cmd );
  164. }
  165.  
  166. #Right Arrow
  167. sub moveConRight
  168. {
  169.         my $self = shift;
  170.         $stop_command = "1";
  171.         Debug( "Move Right" );
  172.         my $cmd =  "decoder_control.cgi?command=4&";
  173.         $self->sendCmd( $cmd );
  174. }
  175.  
  176. #Diagonally Up Right Arrow
  177. sub moveConUpRight
  178. {
  179.         my $self = shift;
  180.         $stop_command = "1";
  181.         Debug( "Move Diagonally Up Right" );
  182.         my $cmd =  "decoder_control.cgi?command=90&";
  183.         $self->sendCmd( $cmd );
  184. }
  185.  
  186. #Diagonally Down Right Arrow
  187. sub moveConDownRight
  188. {
  189.         my $self = shift;
  190.         $stop_command = "1";
  191.         Debug( "Move Diagonally Down Right" );
  192.         my $cmd =  "decoder_control.cgi?command=92&";
  193.         $self->sendCmd( $cmd );
  194. }
  195.  
  196. #Diagonally Up Left Arrow
  197. sub moveConUpLeft
  198. {
  199.         my $self = shift;
  200.         $stop_command = "1";
  201.         Debug( "Move Diagonally Up Left" );
  202.         my $cmd =  "decoder_control.cgi?command=91&";
  203.         $self->sendCmd( $cmd );
  204. }
  205.  
  206. #Diagonally Down Left Arrow
  207. sub moveConDownLeft
  208. {
  209.         my $self = shift;
  210.         $stop_command = "1";
  211.         Debug( "Move Diagonally Down Left" );
  212.         my $cmd =  "decoder_control.cgi?command=93&";
  213.         $self->sendCmd( $cmd );
  214. }
  215.  
  216. #Stop
  217. sub moveStop
  218. {
  219.         my $self = shift;
  220.         Debug( "Move Stop" );
  221.         my $cmd =  "decoder_control.cgi?command=1&";
  222.         $self->sendCmd( $cmd );
  223. }
  224.  
  225. #Move Camera to Home Position
  226. sub presetHome
  227. {
  228.         my $self = shift;
  229.         Debug( "Home Preset" );
  230.         my $cmd = "decoder_control.cgi?command=25&";
  231.         $self->sendCmd( $cmd );
  232. }
  233.  
  234. #Set preset
  235. sub presetSet
  236. {
  237.         my $self = shift;
  238.         my $params = shift;
  239.         my $preset = $self->getParam( $params, 'preset' );
  240.                 my $presetCmd = 30 + ($preset*2);
  241.         Debug( "Set Preset $preset with cmd $presetCmd" );
  242.         my $cmd = "decoder_control.cgi?command=$presetCmd&";
  243.         $self->sendCmd( $cmd );
  244. }
  245.  
  246. #Goto preset
  247. sub presetGoto
  248. {
  249.         my $self = shift;
  250.         my $params = shift;
  251.         $stop_command = "1";
  252.         my $preset = $self->getParam( $params, 'preset' );
  253.         my $presetCmd = 31 + ($preset*2);
  254.         Debug( "Goto Preset $preset with cmd $presetCmd" );
  255.         my $cmd = "decoder_control.cgi?command=$presetCmd&";
  256.         $self->sendCmd( $cmd );
  257. }
  258.  
  259. #Turn IR on
  260. sub wake
  261. {
  262.         my $self = shift;
  263.         Debug( "Wake - IR on" );
  264.         my $cmd = "decoder_control.cgi?command=95&";
  265.         $self->sendCmd( $cmd );
  266. }
  267.  
  268. #Turn IR off
  269. sub sleep
  270. {
  271.         my $self = shift;
  272.         Debug( "Sleep - IR off" );
  273.         my $cmd = "decoder_control.cgi?command=94&";
  274.         $self->sendCmd( $cmd );
  275. }
  276.  
  277. 1;