projects
/
tpope-extra.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
d68179a
)
What a load of BS
author
Tim Pope
<code@tpope.net>
Wed, 1 Jun 2005 04:36:31 +0000
(
04:36
+0000)
committer
Tim Pope
<code@tpope.net>
Wed, 1 Jun 2005 04:36:31 +0000
(
04:36
+0000)
perl/mobile-phone-monitor
patch
|
blob
|
history
diff --git
a/perl/mobile-phone-monitor
b/perl/mobile-phone-monitor
index 535b4f67d898edd4e8e6ae4e4663bd95c6b0cf5e..5c7065f5c0f36ea8752cc0ba3490eb92a022c787 100755
(executable)
--- a/
perl/mobile-phone-monitor
+++ b/
perl/mobile-phone-monitor
@@
-1,8
+1,8
@@
#!/usr/bin/perl
# $Id$
#!/usr/bin/perl
# $Id$
-# -*- perl -*- vim:
ft=perl sw=4 sts=4
+# -*- perl -*- vim:
set ft=perl sw=4 sts=4:
-# Monitors a bluetooth mobile pho
m
e for calls. You'll need to bind rfcomm1 to
+# Monitors a bluetooth mobile pho
n
e for calls. You'll need to bind rfcomm1 to
# your mobile phone's SP service. You'll also need my Device::Nokia module
# (the name is misleading, it's not Nokia specific).
# your mobile phone's SP service. You'll also need my Device::Nokia module
# (the name is misleading, it's not Nokia specific).
@@
-12,7
+12,7
@@
my $number;
my %status;
my $quiton;
my $daemonize;
my %status;
my $quiton;
my $daemonize;
-
+my $last=0;
my $gsm = new Device::Nokia( port => '/dev/rfcomm1', log => 'file,/dev/null');
$SIG{INT} = 'death';
my $gsm = new Device::Nokia( port => '/dev/rfcomm1', log => 'file,/dev/null');
$SIG{INT} = 'death';
@@
-36,10
+36,11
@@
while($_=shift) {
daemonize() if $daemonize;
daemonize() if $daemonize;
+$|=1;
while(1) {
%status=("is_active"=>1);
while($status{"is_active"} ne 0) {
while(1) {
%status=("is_active"=>1);
while($status{"is_active"} ne 0) {
- for(my $i=0;$i<
8
;$i++) {
+ for(my $i=0;$i<
3
;$i++) {
sleep 1;
$number = wait_for_ring();
if($number) {
sleep 1;
$number = wait_for_ring();
if($number) {
@@
-50,18
+51,22
@@
while($status{"is_active"} ne 0) {
} elsif(!defined($number)) { $status{"is_active"}=0; last; };
}
my %newstatus=gather_data($gsm);
} elsif(!defined($number)) { $status{"is_active"}=0; last; };
}
my %newstatus=gather_data($gsm);
- ring() if($newstatus{"call"}!=0 && $status{"call"}!=0);
+ print $newstatus{'call'}." ".$status{'call'}."\n";
+ ring() if($newstatus{"call"}!=0 && $status{"call"}==0 && !$status{"number"});
foreach (keys %newstatus) {
$status{$_} = $newstatus{$_} if(defined ($newstatus{$_}));
}
undef $status{"number"} if (!$number && $status{"callsetup"}==0 && $status{"call"}==0);
output_status(%status);
foreach (keys %newstatus) {
$status{$_} = $newstatus{$_} if(defined ($newstatus{$_}));
}
undef $status{"number"} if (!$number && $status{"callsetup"}==0 && $status{"call"}==0);
output_status(%status);
- death() if ($status{"source"}==0 && $status{"callsetup"}==0 && $status{"call"}==0 && $quiton);
+ if ($status{"source"}==0 && $status{"callsetup"}==0 && $status{"call"}==0 && $quiton) {
+ death() if(time-$last>600);
+ } elsif ($quiton) {
+ $last=time;
+ }
}
$gsm->disconnect();
}
$gsm->disconnect();
-#print "Chillin'...\n";
output_status(is_active => 0);
output_status(is_active => 0);
-do {sleep
60
}
+do {sleep
(60-30*$quiton);
}
until(initialize($gsm));
}
until(initialize($gsm));
}
@@
-89,13
+94,13
@@
sub ring {
sub gather_data {
my %data;
my $gsm=shift;
sub gather_data {
my %data;
my $gsm=shift;
-
eval {
-
local $SIG{ALRM} = sub { die "alarm\n" };
-
alarm 15;
+ eval {
+ local $SIG{ALRM} = sub { die "alarm\n" };
+ alarm 15;
%data=$gsm->indicators();
my ($first, $second) = $gsm->battery_strength();
$data{"source"}=$first;
%data=$gsm->indicators();
my ($first, $second) = $gsm->battery_strength();
$data{"source"}=$first;
- $data{"battery"}=$second;
+
#
$data{"battery"}=$second;
($first, $second) = $gsm->signal_quality();
$data{"signal"}=$first;
alarm 0;
($first, $second) = $gsm->signal_quality();
$data{"signal"}=$first;
alarm 0;
@@
-119,22
+124,6
@@
sub output_status {
rename "/tmp/.phone-status.new", "/tmp/.phone-status" || die $!;
}
rename "/tmp/.phone-status.new", "/tmp/.phone-status" || die $!;
}
-
-sub daemonize {
- chdir "/";
- my $pid=fork();
- if($pid) {
- exit(0)
- }
- elsif(defined($pid))
- {
- close STDIN;
- close STDOUT;
- close STDERR;
- }
- else { exit(1); }
-}
-
sub death {
$gsm->disconnect() if($gsm);
unlink "/tmp/.phone-status.new", "/tmp/.phone-status";
sub death {
$gsm->disconnect() if($gsm);
unlink "/tmp/.phone-status.new", "/tmp/.phone-status";