commit c8f1a1229372f987d9ac0e38b91ebf525a426d46
parent 0419a4184a8dbf21eb4d7aacd8e234d8769581bf
Author: hackrid <hack.rid@gmail.com>
Date: Tue, 12 Apr 2016 10:15:22 +0200
dynamic y axis scaling enabled by default
-the signal swing is dependend from the current displayed maximunm ping response time.
-the meaning of the y axis scaling factor has changed slightly. it is supplyd to prevent dynamic scaling
Diffstat:
M | cnping.c | | | 43 | ++++++++++++++++++++++++++++++++++++++----- |
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/cnping.c b/cnping.c
@@ -24,6 +24,7 @@ unsigned long iframeno = 0;
short screenx, screeny;
const char * pinghost;
float GuiYScaleFactor;
+int GuiYscaleFactorIsConstant;
uint8_t pattern[8];
@@ -91,11 +92,37 @@ void * PingSend( void * r )
void HandleKey( int keycode, int bDown ){}
void HandleButton( int x, int y, int button, int bDown ){}
void HandleMotion( int x, int y, int mask ){}
+
+double GetGlobMaxPingTime( void )
+{
+ int i;
+ double maxtime = 0;
+
+ for( i = 0; i < screenx; i++ )
+ {
+ int index = ((current_cycle - i - 1) + PINGCYCLEWIDTH) & (PINGCYCLEWIDTH-1);
+ double st = PingSendTimes[index];
+ double rt = PingRecvTimes[index];
+
+ double dt = 0;
+
+ if( rt > st )
+ {
+ dt = rt - st;
+ dt *= 1000;
+ if( dt > maxtime ) maxtime = dt;
+ }
+ }
+
+ return maxtime;
+}
+
void DrawFrame( void )
{
int i, x, y;
double now = OGGetAbsoluteTime();
+ double globmaxtime = GetGlobMaxPingTime();
double totaltime = 0;
int totalcountok = 0;
@@ -130,6 +157,11 @@ void DrawFrame( void )
}
+ if (!GuiYscaleFactorIsConstant)
+ {
+ GuiYScaleFactor = screeny / globmaxtime;
+ }
+
if( last < 0 && rt > st )
last = dt;
int h = dt*GuiYScaleFactor;
@@ -226,10 +258,10 @@ int main( int argc, const char ** argv )
{
ERRM( "Usage: cnping [host] [period] [extra size] [y-axis scaling]\n"
- " [host] -- domain or IP address of ping target \n"
- " [period] -- period in seconds (optional), default 0.02 \n"
- " [extra size] -- ping packet extra size (above 12), optional, default = 0 \n"
- " [y-axis scaling] -- see more swing for small values (optional), default = 1\n");
+ " [host] -- domain or IP address of ping target \n"
+ " [period] -- period in seconds (optional), default 0.02 \n"
+ " [extra size] -- ping packet extra size (above 12), optional, default = 0 \n"
+ " [const y-axis scaling] -- use a fixed scaling factor instead of auto scaling (optional)\n");
return -1;
}
@@ -257,11 +289,12 @@ int main( int argc, const char ** argv )
if( argc > 4 )
{
GuiYScaleFactor = atof( argv[4] );
+ GuiYscaleFactorIsConstant = 1;
printf( "GuiYScaleFactor: %f\n", GuiYScaleFactor );
}
else
{
- GuiYScaleFactor = 1;
+ printf( "GuiYScaleFactor: %s\n", "dynamic" );
}
pinghost = argv[1];