my $USERNAME="Jan Kratochvil";
my $PASSWORD=&_priv_postget("uzivatel.gtsnovera.cz.pwd");
my $IFDEV="eth0";
-my $SECS=8;
+my $SECS=4;
my $RX_THRESHOLD=200000; # 226085
my $TX_THRESHOLD=200000; # 291251
-my $STABILIZE_OFF=2;
-my $STABILIZE_ON=10;
+my $STABILIZE_OFF=1;
+my $STABILIZE_ON=5*60;
+$RX_THRESHOLD=$RX_THRESHOLD*$SECS/8;
+$TX_THRESHOLD=$TX_THRESHOLD*$SECS/8;
+$STABILIZE_OFF/=$SECS;
+$STABILIZE_ON /=$SECS;
$|=1;
my $ua=LWP::UserAgent->new();
#$ua->timeout(60);
$login=~m{<span class="textTitle1">\Q$USERNAME\E,</span>} or die $login."\nNo name found";
}
+my $on=-1;
+my($ignore_read,$ignore_write);
sub change($)
{
-my($on)=@_;
+my($new)=@_;
- $on=($on ? 1 : 0);
+ $new=($new ? 1 : 0);
+ return if $on==$new;
+ return if $ignore_read;
my $try=0;
my $change;
do {
die "Looping to login" if $try++>0x10;
login() if $try;
$change=simple("https://uzivatel.gtsnovera.cz/cgi-bin/fup.pl",
- 'action.'.($on ? 'setManual' : 'unsetManual').'=1',
- )->decoded_content() or die "change: ".$on;
+ 'action.'.($new ? 'setManual' : 'unsetManual').'=1',
+ )->decoded_content() or die "change: ".$new;
} while $change=~m{No authentication cookie was sent.};
my $is_on =($change=~m{\bFUP active\b});
my $is_off=($change=~m{\bFUP not active\b});
$is_on==!$is_off or die $change."\nInvalid change state";
- $on==$is_on or die $change."\nChange not changed, wanted: ".$on;
- print "<$on>";
- return $on;
+ $new==$is_on or die $change."\nChange not changed, wanted: ".$new;
+ print "<$new>";
+ $ignore_write=1;
+ $on=$new;
}
if (defined(my $change=$ARGV[0])) {
}
my($rx_last,$tx_last);
-my $on=0;
-change($on);
+change(0);
my @history;
sub history($$)
{
my($what,$length)=@_;
+ return if $what==$on;
my $idx=@history;
while ($length-->0) {
return if --$idx<0;
return if $what!=$history[$idx];
}
- return 1;
+ change($what);
}
for (;;) {
$rx_last=$rx;
$tx_last=$tx;
push @history,$on_now;
- print $on_now;
- $on=change(1) if $on==0 && history(1,$STABILIZE_ON);
- $on=change(0) if $on==1 && history(0,$STABILIZE_OFF);
+ print(($ignore_read ? "_" : $on_now));
+ history(1,$STABILIZE_ON);
+ history(0,$STABILIZE_OFF);
+ $ignore_read=$ignore_write;
+ $ignore_write=0;
sleep $SECS;
}