summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoretienne2006-09-27 15:47:44 +0000
committeretienne2006-09-27 15:47:44 +0000
commite607d0461bb9aa024360831eaac12ce727750a2f (patch)
tree180a19db80f3b78fe16aa95654855aae8d193824
parentc55152a7e9a94e524cf4b9df46ef4d77d8ca35db (diff)
downloadivymon-e607d0461bb9aa024360831eaac12ce727750a2f.zip
ivymon-e607d0461bb9aa024360831eaac12ce727750a2f.tar.gz
ivymon-e607d0461bb9aa024360831eaac12ce727750a2f.tar.bz2
ivymon-e607d0461bb9aa024360831eaac12ce727750a2f.tar.xz
added a time regulation system for replay functionality.
It works only when speed rate = 1. fixed a bug in speed buttons bar
-rwxr-xr-xsrc/ivymon198
1 files changed, 130 insertions, 68 deletions
diff --git a/src/ivymon b/src/ivymon
index 8a88982..4bb967a 100755
--- a/src/ivymon
+++ b/src/ivymon
@@ -92,7 +92,7 @@ use vars qw/$VERSION $opt_help $opt_b $opt_bus $opt_history @opt_bind @opt_send
$opt_undersize $opt_out $opt_loadingmode $opt_replayrepeat $opt_replaystartregexp
$opt_replaystopregexp $opt_replaytimegranularity/;
# **** VERSION ***
-$VERSION = '1.15.1';
+$VERSION = '1.16';
# options initialisation
$opt_loadingmode = 'replay-pause';
@@ -176,6 +176,17 @@ my @bind_def;
my @effectivebind;
# replay
+my $replay_current_t0;
+my $replay_current_t;
+my $replay_data_t0;
+my $replay_data_t;
+my $replay_pause_t;
+my $replay_pause_duration = 0;
+my $replay_maxgap = 0.2; # sec
+my $replay_regulpct = [50, 20]; # %
+my $replay_factor = 1000; # msec
+my $replay_current_factor = $replay_factor;
+
my $replay_speed = 1;
my $replay_runnable = 1;
my $replay_running = 0;
@@ -2290,42 +2301,60 @@ sub loadfileForReplay {
$replay_fg_orig = $replay_text->cget(-foreground);
&wheelmousebindings($replay_text);
# build speed control buttons
+ my $realspeedrate = 1;
my $ctrl_fm1 = $ctrl_fm->Frame()->pack(-side => 'left', -padx => 10);
- $ctrl_fm1->Checkbutton(-text => "x0.1", -indicatoron => 0,
+ $ctrl_fm1->Radiobutton(-text => "x0.1", -indicatoron => 0,
-height => 2,
-width => 4,
- -onvalue => 0.1,
+ -value => 0.1,
-variable => \$replay_speed,
+ -command => sub { $realspeedrate = 0 },
-selectcolor => 'white')->pack(-side => 'left');
- $ctrl_fm1->Checkbutton(-text => "x0.5", -indicatoron => 0,
+ $ctrl_fm1->Radiobutton(-text => "x0.5", -indicatoron => 0,
-height => 2,
-width => 4,
- -onvalue => 0.5,
+ -value => 0.5,
-variable => \$replay_speed,
+ -command => sub { $realspeedrate = 0 },
-selectcolor => 'white')->pack(-side => 'left');
- $ctrl_fm1->Checkbutton(-text => "x1", -indicatoron => 0,
+ $ctrl_fm1->Radiobutton(-text => "x1", -indicatoron => 0,
-height => 2,
-width => 4,
- -onvalue => 1,
+ -value => 1,
-variable => \$replay_speed,
+ -command => sub {
+ return if $realspeedrate == 1;
+ $realspeedrate = 1;
+ $replay_data_t0 = $replay_time;
+ $replay_current_t0 = gettimeofday();
+ if ($replay_running == 0) {
+ $replay_pause_t = $replay_current_t0;
+ } else {
+ $replay_pause_t = undef;
+ }
+ $replay_pause_duration = 0;
+ },
-selectcolor => 'white')->pack(-side => 'left');
- $ctrl_fm1->Checkbutton(-text => "x2", -indicatoron => 0,
+ $ctrl_fm1->Radiobutton(-text => "x2", -indicatoron => 0,
-height => 2,
-width => 4,
- -onvalue => 2,
+ -value => 2,
-variable => \$replay_speed,
+ -command => sub { $realspeedrate = 0 },
-selectcolor => 'white')->pack(-side => 'left');
- $ctrl_fm1->Checkbutton(-text => "x5", -indicatoron => 0,
+ $ctrl_fm1->Radiobutton(-text => "x5", -indicatoron => 0,
-height => 2,
-width => 4,
- -onvalue => 5,
+ -value => 5,
-variable => \$replay_speed,
+ -command => sub { $realspeedrate = 0 },
-selectcolor => 'white')->pack(-side => 'left');
- $ctrl_fm1->Checkbutton(-text => "x10", -indicatoron => 0,
+ $ctrl_fm1->Radiobutton(-text => "x10", -indicatoron => 0,
-height => 2,
-width => 4,
- -onvalue => 10,
+ -value => 10,
-variable => \$replay_speed,
+ -command => sub { $realspeedrate = 0 },
-selectcolor => 'white')->pack(-side => 'left');
# build hour label
my $ctrl_fm2 = $ctrl_fm->Frame()->pack(-side => 'left', -padx => 10);
@@ -2609,61 +2638,93 @@ sub setProgressbar {
#----------------------------------------------------------------------------------
sub replayStart {
- my $loopflag = ($_[0] == 1) ? 1 : undef;
- my $t = $replay_text;
- #print "abort 1 replayStart\n" if $replay_running and not $loopflag;
- return if $replay_running and not $loopflag;
- #print "abort 2 replayStart\n" if $loopflag and not $replay_running ;
- return if $loopflag and not $replay_running;
- $replay_runnable = 0;
- $replay_running = 1;
- if ($replay_time > $replay_max_time) {
- if ($replay_repeat == 1) {
- $replay_time = $replay_min_time;
- } else {
- $t->tagConfigure($replay_last_time,
- -foreground => $replay_fg_orig,
- -background => $replay_bg_orig)
- if defined $replay_last_time;
- $replay_running = 0;
- $replay_runnable = 1;
- return;
- }
- }
- $replay_hour = &replayTime($replay_time);
- if (defined $replay_msg{$replay_time}) {
- for my $msg (@{$replay_msg{$replay_time}}) {
- &sendMsg($msg);
- $t->tagConfigure($replay_last_time,
- -foreground => $replay_fg_orig,
- -background => $replay_bg_orig)
- if defined $replay_last_time;
- $t->tagConfigure($replay_time,
- -foreground => $replay_fg,
- -background => $replay_bg);
- }
- $replay_last_time = $replay_time;
- my $i = $t->tagRanges($replay_time);
- $t->see($i) if defined $i;
- }
- $replay_time += $replay_time_granularity;
- $replay_time = sprintf("%.".$replay_time_decimalplaces."f", $replay_time) if
- $replay_time_decimalplaces > 0;
- # step by step mode
- if ($replay_stepbystep) {
- while (not defined $replay_msg{$replay_time}) {
- $replay_time += $replay_time_granularity;
- $replay_time = sprintf("%.".$replay_time_decimalplaces."f", $replay_time) if
- $replay_time_decimalplaces > 0;
- last if $replay_time > $replay_max_time;
- }
- $replay_running = 0;
- $replay_runnable = 1;
- } else {
- $replay_timer = $mw->after(1000*$replay_time_granularity/$replay_speed,
- [\&replayStart, 1]);
-
- }
+ my $loopflag = ($_[0] == 1) ? 1 : undef;
+ $replay_data_t0 = $replay_time unless defined $replay_data_t0;
+ $replay_current_t0 = gettimeofday() unless defined $replay_current_t0;
+ my $t = $replay_text;
+ return if $replay_running and not $loopflag;
+ return if $loopflag and not $replay_running;
+ if (defined $replay_pause_t and $replay_speed == 1) {
+ $replay_pause_duration += gettimeofday() - $replay_pause_t;
+ }
+ $replay_pause_t = undef;
+ $replay_runnable = 0;
+ $replay_running = 1;
+ if ($replay_time > $replay_max_time) {
+ if ($replay_repeat == 1) {
+ $replay_time = $replay_min_time;
+ } else {
+ $t->tagConfigure($replay_last_time,
+ -foreground => $replay_fg_orig,
+ -background => $replay_bg_orig)
+ if defined $replay_last_time;
+ $replay_running = 0;
+ $replay_runnable = 1;
+ return;
+ }
+ }
+ $replay_hour = &replayTime($replay_time);
+ my $data_dt = $replay_time - $replay_data_t0;
+ if (defined $replay_msg{$replay_time}) {
+ for my $msg (@{$replay_msg{$replay_time}}) {
+ &sendMsg($msg);
+ $t->tagConfigure($replay_last_time,
+ -foreground => $replay_fg_orig,
+ -background => $replay_bg_orig)
+ if defined $replay_last_time;
+ $t->tagConfigure($replay_time,
+ -foreground => $replay_fg,
+ -background => $replay_bg);
+ }
+ $replay_last_time = $replay_time;
+ my $i = $t->tagRanges($replay_time);
+ $t->see($i) if defined $i;
+ }
+ $replay_time += $replay_time_granularity;
+ $replay_time = sprintf("%.".$replay_time_decimalplaces."f", $replay_time) if
+ $replay_time_decimalplaces > 0;
+ # step by step mode
+ if ($replay_stepbystep) {
+ while (not defined $replay_msg{$replay_time}) {
+ $replay_time += $replay_time_granularity;
+ $replay_time = sprintf("%.".$replay_time_decimalplaces."f", $replay_time) if
+ $replay_time_decimalplaces > 0;
+ last if $replay_time > $replay_max_time;
+ }
+ $replay_running = 0;
+ $replay_runnable = 1;
+
+ # continuous mode
+ } else {
+ my $dt = gettimeofday() - $replay_current_t0 - $replay_pause_duration;
+ my $dt2 = sprintf("%.2f", $dt);
+ my $d = sprintf("%.3f", $dt-$data_dt);
+
+ # if speed rate != 1, time regulation is deactivated
+ if ($replay_speed != 1) {
+ $replay_current_factor = $replay_factor;
+ #print "replay_speed=$replay_speed => time regulation deactivated\n";
+
+ # if replay is running behind schedule
+ } elsif ($dt > $data_dt + $replay_maxgap and $replay_current_factor <= $replay_factor) {
+ $replay_current_factor *= (1 - $replay_regulpct->[0]/100);
+ #print "data_dt=$data_dt dt=$dt2 delay=$d [--] replay_factor=$replay_current_factor\n";
+
+ # if replay is getting ahead of schedule
+ } elsif ($dt < $data_dt - $replay_maxgap and $replay_current_factor >= $replay_factor) {
+ $replay_current_factor *= (1 + $replay_regulpct->[1]/100);
+ #print "data_dt=$data_dt dt=$dt2 delay=$d [++] replay_factor=$replay_current_factor\n";
+
+ # if replay is on time
+ } else {
+ #print "data_dt=$data_dt dt=$dt2 delay=$d\n";
+ $replay_current_factor = $replay_factor;
+ }
+
+ $replay_timer =
+ $mw->after($replay_current_factor*$replay_time_granularity/$replay_speed,
+ [\&replayStart, 1]);
+ }
} # end replayStart
@@ -2672,6 +2733,7 @@ sub replayStop {
$replay_running = 0;
$replay_runnable = 1;
$replay_text->afterCancel($replay_timer) if defined $replay_timer;
+ $replay_pause_t = gettimeofday();
} # end replayStop