Update is_time_format_correct. Added extra delay after each rfcmd call to get more robust operation.
This commit is contained in:
parent
b1b178084f
commit
f6ed1545bd
2 changed files with 19 additions and 52 deletions
|
@ -33,23 +33,8 @@ This software is freely distributable under the GNU General Public License,
|
|||
the full content of the license is included in the file LICENSE.
|
||||
Bug reports are welcome, but even more appreciated are patches with the solution to the problem.
|
||||
|
||||
Revision history
|
||||
=================
|
||||
2008-02-18 0.3.5 Changed sunset calculation parameters. Added init script for Debian and adaptions of tellstickd. All contributions of Anders Betner.
|
||||
2008-02-17 0.3.4 Now possible to use a minus sign (-) when setting <off when bright delay> and <prelight in afternoon>
|
||||
2008-02-15 0.3.3 General improvements.
|
||||
2008-02-15 0.3.2 Corrected a fatal bug regarding switch logic.
|
||||
2008-02-15 0.3.1 Changed update interval back from 50 to 60 seconds.
|
||||
2008-02-14 0.3.0 New feature: On- and off times can be randomized within a given interval. Changed update interval from 60 to 50 seconds.
|
||||
2008-02-12 0.2.1 Changed behaviour when program is called without argument. Now presents: Try "tellstickd --help" for more information.
|
||||
2008-02-11 0.2.0 Added support for SARTANO devices. General code cleanups.
|
||||
2008-02-11 0.1.4 Completely new switch logic, hopefully more robust with fewer bugs.
|
||||
2008-02-10 0.1.3 Modified switch logic. When dawn is before on-time, lights are not switched on. If dusk time is after off time, lights are not switched on.
|
||||
2008-01-30 0.1.2 Corrected a bug regarding datetimelocal.
|
||||
2008-01-15 0.1.1 Fixed some bugs. Added logfile capability.
|
||||
2008-01-11 0.1.0 Initial release
|
||||
|
||||
Author
|
||||
=================
|
||||
Magnus Juntti
|
||||
mjuntti@gmail.com
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ sub rfcmd_exec {
|
|||
printf("$PROGRAM_NAME: Time is $current_time. Switching on $device_cfg[$device_id][0] device $device_cfg[$device_id][1]$device_cfg[$device_id][2].\n");
|
||||
`$RFCMD $RFCMD_OPTIONS 1`;
|
||||
$device_cfg[$device_id][22] = 1;
|
||||
|
||||
sleep(1);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
@ -148,7 +148,7 @@ sub rfcmd_exec {
|
|||
printf("$PROGRAM_NAME: Time is $current_time. Switching off $device_cfg[$device_id][0] device $device_cfg[$device_id][1]$device_cfg[$device_id][2].\n");
|
||||
`$RFCMD $RFCMD_OPTIONS 0`;
|
||||
$device_cfg[$device_id][22] = 0;
|
||||
|
||||
sleep(1);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
@ -281,40 +281,13 @@ sub randomize_off
|
|||
sub is_time_format_correct
|
||||
{
|
||||
my $time = $_[0];
|
||||
my $number_of_matches = 0;
|
||||
my $tmp = $time;
|
||||
|
||||
# Remove a leading signs, if it exists
|
||||
$time =~ s/^.*?[0-9]//g;
|
||||
|
||||
if (length($time) < 4 || length($time) > 5) {
|
||||
return $NO;
|
||||
(my $hour, my $minute) = $time =~ /^-?(\d\d)\:(\d\d)$/;
|
||||
if ($hour && $minute) {
|
||||
if ($hour >=0 && $hour <= 23 && $minute >= 0 && $minute <= 59) {
|
||||
return $YES;
|
||||
}
|
||||
}
|
||||
|
||||
while ($tmp =~ /\:/g) {
|
||||
$number_of_matches++;
|
||||
}
|
||||
|
||||
if ($number_of_matches != 1) {
|
||||
return $NO;
|
||||
}
|
||||
|
||||
(my $hour, my $minute) = $time =~ /^(.*?)\:(.*?)$/;
|
||||
|
||||
if ($hour !~ /^[0-9]+$/) {
|
||||
return $NO;
|
||||
}
|
||||
|
||||
if ($minute !~ /^[0-9]+$/) {
|
||||
return $NO;
|
||||
}
|
||||
|
||||
if ($hour < 0 || $hour > 23 || $minute < 0 || $minute > 59) {
|
||||
return $NO;
|
||||
}
|
||||
|
||||
|
||||
return $YES;
|
||||
return $NO;
|
||||
}
|
||||
|
||||
sub read_config
|
||||
|
@ -521,6 +494,8 @@ else {
|
|||
# Now to the eternal loop
|
||||
my $first_loop = $YES;
|
||||
while (1) {
|
||||
$n_rfcmd_calls = 0;
|
||||
|
||||
# What is the current time
|
||||
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
|
||||
$year = 1900 + $yearOffset;
|
||||
|
@ -580,9 +555,11 @@ while (1) {
|
|||
if ($device_cfg[$i][5] == $YES) {
|
||||
if (is_inbetween_times($device_cfg[$i][3], $device_cfg[$i][4], $current_time) == $YES && is_inbetween_times($device_cfg[$i][20], $device_cfg[$i][21], $current_time) == $NO) {
|
||||
rfcmd_exec($i, 1);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
else {
|
||||
rfcmd_exec($i, 0);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -591,9 +568,11 @@ while (1) {
|
|||
else {
|
||||
if (is_inbetween_times($device_cfg[$i][3], $device_cfg[$i][4], $current_time) == $YES) {
|
||||
rfcmd_exec($i, 1);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
else {
|
||||
rfcmd_exec($i, 0);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,5 +580,8 @@ while (1) {
|
|||
}
|
||||
|
||||
$first_loop = $NO;
|
||||
sleep(60); # Wait a while until next round [seconds].
|
||||
|
||||
if ($n_rfcmd_calls < 30) {
|
||||
sleep(60 - 2*$n_rfcmd_calls); # Wait a while until next round [seconds]. If rfcmd has been called, reduce this figure by 2 seconds per call.
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue