Revision 26c98f36

View differences:

utils/set-acpi-alarm
1
#!/usr/bin/perl
2
# set acpi alarm to a few minutes before next job
3
# (if acpi alarm is not already earlier).
4

  
5
# NB: ACPI alarm time is in GMT
6

  
7
use Date::Parse;
8
use Date::Format;
9
use Time::Local;
10
use strict;
11

  
12
my $alarmfile = "/proc/acpi/alarm";
13

  
14
sub getAlarmTime() {
15
    open ALARM, "<$alarmfile"
16
        or die "Failed to read $alarmfile: $!";
17
    my $date = <ALARM>;    
18
    chomp $date;
19
    close ALARM;
20
    return $date
21
}
22

  
23
sub setAlarmTime ($) {
24
    my ($date) = @_;
25
    print "Setting ACPI alarm to GMT $date\n";
26
    open ALARM, ">$alarmfile"
27
        or die "Failed to write $alarmfile: $!";
28
    print ALARM "$date\n";
29
    close ALARM;
30
}
31

  
32
sub convertGmtTime($) {
33
    my ($date) =  @_;
34
    my ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date);
35
    return timegm($ss,$mm,$hh,$day,$month,$year);
36
}
37

  
38
sub convertLocalTime($) {
39
    my ($date) =  @_;
40
    my ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date);
41
    return timelocal($ss,$mm,$hh,$day,$month,$year);
42
}
43

  
44
sub getDvbdNextJob() {
45
    my $date = `dvblist -n`;
46
    
47
}
48

  
49
my $acpiDate = getAlarmTime();
50
my $acpiAlarm = convertGmtTime($acpiDate);
51
#print "Current ACPI alarm: $acpiAlarm\n";
52

  
53
my $dvbdNextJobDate = getDvbdNextJob();
54
my $dvbdAlarm = convertLocalTime($dvbdNextJobDate);
55

  
56
if (!defined($dvbdAlarm)) {
57
    print "No dvbd jobs scheduled\n";
58
}
59

  
60
#print "Next DVBD Job: $dvbdAlarm\n";
61
# Subtract some boot up time from the dvbdAlarm
62

  
63
$dvbdAlarm -= 3*60;
64
my $now = time;
65
if ($dvbdAlarm > $now && ($dvbdAlarm < $acpiAlarm || $acpiAlarm < $now)) {
66
    my @t = gmtime($dvbdAlarm);
67
    my $textAlarm = strftime("%Y-%m-%d %H:%M:%S", @t);
68
    setAlarmTime($textAlarm);
69
}

Also available in: Unified diff