1 ###RUN_PERL: #!/usr/bin/perl
3 # ong.pl is generated from ong.1.pl.
7 # Copyright (C) 2016, 2017, 2023 Balthasar SzczepaĆski
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as
11 # published by the Free Software Foundation, either version 3 of the
12 # License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU Affero General Public License for more details.
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # use Encode::Locale ('decode_argv');
25 use Encode ('encode', 'decode');
27 ###PERL_LIB: use lib /botm/lib/bsta
29 'read_data_file', 'write_data_file'
36 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
37 ###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
56 $ongtime = int($time / 3600) * 3600; # check time as if it was last full hour!
58 print $time.' - '.$ongtime."\n";
60 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
61 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
63 unless (open ($fh, "+<:encoding(UTF-8)", encode('locale_fs', DATA_STATE_PATH()))) {
64 print "NO STATEFILE\n";
67 unless (flock($fh, 2)) {
68 print "NO STATELOCK\n";
71 %state = read_data_file($fh);
72 $ongstate = int($state{'state'});
73 print 'state: '.$ongstate."\n";
74 unless ($ongstate > STATE->{'inactive'}) {
78 $next_ong = int($state{'nextong'});
79 print 'ongtime: '.$next_ong."\n";
81 unless ($ongtime >= $next_ong) {
85 %settings = read_data_file(DATA_SETTINGS_PATH());
86 $static_timer = int($settings{'ongtime'});
87 $timer = int($settings{'dynamicongtime'});
88 $last = int($settings{'last'});
89 $frame = int($state {'last'})+1;
91 if (($timer > 0) && ($frame < $last)) {
92 $timer = int($timer / ($last - $frame));
98 if ($static_timer > $timer) {
99 $timer = $static_timer;
101 $next_ong = $ongtime + ($timer*3600);
102 $state{'nextong'} = $next_ong;
103 print 'next ongtime: '.$next_ong.' (+'.$timer.")\n";
104 $state{'ongtime'}=$timer;
106 if ($ongstate == STATE->{'ready'}) {
107 print 'next frame: '.$frame."\n";
112 $timer, # timer to next ONG
122 $state{'last'} = $frame;
127 $state{'ongtime'}= $timer;
134 write_data_file($fh, '', '', \%state);