/camera/camlib

To get this branch, use:
bzr branch http://darksoft.org/webbzr/camera/camlib

« back to all changes in this revision

Viewing changes to misc/power.pl

  • Committer: Suren A. Chilingaryan
  • Date: 2011-02-13 01:33:37 UTC
  • Revision ID: csa@dside.dyndns.org-20110213013337-ibm4w4n5a3hu4k7u
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
use LWP::UserAgent;
 
3
use HTTP::Headers;
 
4
use HTTP::Response;
 
5
use HTTP::Request;
 
6
use URI::URL;
 
7
 
 
8
$inf_url = "http://hpeat127.fzk.de:8000/cmd.html";
 
9
$cmd_url = $inf_url;
 
10
#$proxy = "http://proxy.fzk.de:8000";
 
11
$user = 'ufo';
 
12
$pass = 'fast';
 
13
 
 
14
$ua=new LWP::UserAgent;
 
15
if ($proxy) { $ua->proxy(['http','ftp'],$proxy); }
 
16
 
 
17
sub status {
 
18
    my ($req_url) = @_;
 
19
    
 
20
    my $url = new URI::URL($req_url);
 
21
    my $hdr = new HTTP::Headers("Referer"=>$url);
 
22
    $hdr->authorization_basic($user, $pass);
 
23
    my $req = new HTTP::Request("GET",$url,$hdr);
 
24
    my $resp = $ua->request($req);
 
25
    my $status = $resp->content;
 
26
 
 
27
#print $status;
 
28
    while ($status =~ /socket\((\d+)\s*,([^,]+)\s*,(\d+)\s*,(\d+)\s*\)/g) {
 
29
        print "$1 $2 = $3 \n"
 
30
    }
 
31
}
 
32
 
 
33
 
 
34
if ($#ARGV < 0) {
 
35
    print 
 
36
"Usage: 
 
37
    $0 <var>=<value>
 
38
        Example: $0 P1=0
 
39
        Example: $0 P1=1
 
40
        Example: $0 'P1=1&P2=0'
 
41
    $0 val1 val2 val3 val4
 
42
        Example: $0 1 1 0 0
 
43
\n\n";
 
44
    status($inf_url);
 
45
    exit(0);
 
46
}
 
47
 
 
48
if (($#ARGV>0)||($ARGV[0] =~ /^\d+$/)) {
 
49
    $POST = "";
 
50
    foreach ($i = 0; $i <= $#ARGV; $i++) {
 
51
        if ($i) { $POST .= "&"; }
 
52
        $POST .= "P".($i+1)."=".$ARGV[$i];
 
53
    }
 
54
} else {
 
55
    $POST = $ARGV[0];
 
56
}
 
57
 
 
58
$retries = 3;
 
59
 
 
60
RETRY:
 
61
$url = new URI::URL($cmd_url);
 
62
$hdr=new HTTP::Headers("Referer"=>$cmd_url);
 
63
$hdr->authorization_basic($user, $pass);
 
64
$req = new HTTP::Request("POST",$url,$hdr,$POST);
 
65
$req->content_type('application/x-www-form-urlencoded');
 
66
$resp = $ua->request($req);
 
67
if ($resp->content) { 
 
68
    if (($resp->content =~ /401\s+Authorization\s+Required/i)&&(--$i>0)) { goto RETRY; }
 
69
    print($resp->content . "\n"); 
 
70
}
 
71
 
 
72
status($inf_url);