summaryrefslogtreecommitdiff
path: root/contrib/skyview.php
diff options
context:
space:
mode:
authorChris Kuethe <chris.kuethe@gmail.com>2007-10-22 01:45:13 +0000
committerChris Kuethe <chris.kuethe@gmail.com>2007-10-22 01:45:13 +0000
commita1e948040c02ddc4817e40c28da9e989e2eb5b64 (patch)
treed9940e17da6017c0bd589a184b617bbc0adb104b /contrib/skyview.php
parentbdbba7658effa6e91a3a4acf5af6c8138156dd71 (diff)
downloadgpsd-a1e948040c02ddc4817e40c28da9e989e2eb5b64.tar.gz
add a "cell" mode to the skyview plotter.
this will plot the average signal strength in a patch of sky. also speed up the plot by storing all the signal strengths in an array which means i'll never have to store more than about 32.5k points. much better than trying to plot 86400 points (1 satellite info report per second for a day). The old "slug trail" mode is invoked as before: skyview.php log.txt picture.png The new "cell" mode is invoked by adding the "cell" keyword skyview.php log.txt picture2.png cell
Diffstat (limited to 'contrib/skyview.php')
-rwxr-xr-xcontrib/skyview.php82
1 files changed, 77 insertions, 5 deletions
diff --git a/contrib/skyview.php b/contrib/skyview.php
index 587c8556..dedf61d9 100755
--- a/contrib/skyview.php
+++ b/contrib/skyview.php
@@ -1,7 +1,7 @@
#!/usr/local/bin/php
<?php
-# Copyright (c) 2006 Chris Kuethe <chris.kuethe@gmail.com>
+# Copyright (c) 2006,2007 Chris Kuethe <chris.kuethe@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -15,12 +15,18 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+$cellmode = 0;
if ($argc != 3){
- die("usage: ${argv[0]} logfile imagefile\n");
+ if (($argc != 4) || strcmp("cells", $argv[3])){
+ die("usage: ${argv[0]} logfile imagefile [cells]\n");
+ } else {
+ $cellmode = 1;
+ }
}
$sz = 640;
-$radius = 8;
+$cellsize = 5; # degrees
+$radius = 8; # pixels
$filled = 0;
$im = imageCreate($sz, $sz);
@@ -28,17 +34,39 @@ $C = colorsetup($im);
skyview($im, $sz, $C);
legend($im, $sz, $C);
+$sky = array();
+
$lines = file($argv[1]);
foreach ($lines as $line_num => $line) {
if (preg_match('/,Y=\S+ [0-9\.]+ (\d+):/', $line, $m)){
$n = $m[1];
$s = explode(':', $line);
for($i = 1; $i <= $n; $i++){
- $e = explode(' ', $s[$i]);
- splot($im, $sz, $C, $radius, $filled, $e);
+ list($sv, $az, $el, $snr, $u) = explode(' ', $s[$i]);
+ if ($cellmode){
+ $az = $cellsize * (int)($az/$cellsize);
+ $el = $cellsize * (int)($el/$cellsize);
+ }
+ if (isset($sky[$az][$el]['avg'])){
+ $sky[$az][$el]['snr'] += $snr;
+ $sky[$az][$el]['num']++;
+ } else {
+ $sky[$az][$el]['snr'] = $snr;
+ $sky[$az][$el]['num'] = 1;
+ }
+ $sky[$az][$el]['avg'] = $sky[$az][$el]['snr'] / $sky[$az][$el]['num'];
}
}
}
+foreach($sky as $az => $x){
+ foreach ($sky[$az] as $el => $y){
+ $e = array(-1, $az, $el, $sky[$az][$el]['avg'], -1);
+ if ($cellmode)
+ cellplot($im, $sz, $C, $cellsize, $e);
+ else
+ splot($im, $sz, $C, $radius, $filled, $e);
+ }
+}
skygrid($im, $sz, $C); # redraw grid over satellites
imagePNG($im, $argv[2]);
@@ -117,6 +145,50 @@ function azel2xy($az, $el, $sz){
return array($x, $y);
}
+function cellplot($im, $sz, $C, $cellsize, $e){
+ list($sv, $el, $az, $snr, $u) = $e;
+
+ if ((0 == $sv) || (0 == $az + $el + $snr))
+ return;
+
+ $color = $C['brightgreen'];
+ if ($snr < 40)
+ $color = $C['darkgreen'];
+ if ($snr < 35)
+ $color = $C['yellow'];
+ if ($snr < 30)
+ $color = $C['red'];
+ if ($snr == 0)
+ $color = $C['black'];
+
+ #consider an N-degree cell plotted at (0,0). its top left corner
+ #will be (0,0) and its bottom right corner will be at (N,N). The
+ #sides are straight lines from (0,0)-(0,N) and (N,0)-(N,N). The
+ #top and bottom edges will be approximated by segments from
+ #(0,0):(0,1)..(0,N-1):(0,N) and (N,0):(N,1)...(N,N-1):(N,N).
+ #Plotting that unholy mess is the job of
+ # imagefilledpolygon ( $image, array $points, $num_points, $color )
+
+ $np = 0;
+ $points = array();
+ for($x = $az; $x <= $az+$cellsize; $x++){
+ list($px,$py) = azel2xy($x, $el, $sz);
+ array_push($points, $px, $py);
+ $np++;
+ }
+ for($x = $az+$cellsize; $x >= $az; $x--){
+ list($px,$py) = azel2xy($x, $el+$cellsize, $sz);
+ array_push($points, $px, $py);
+ $np++;
+ }
+ list($px,$py) = azel2xy($az, $el, $sz);
+ array_push($points, $px, $py);
+ $np++;
+
+ if ($snr > 0)
+ imageFilledPolygon($im, $points, $np, $color);
+}
+
function splot($im, $sz, $C, $r, $filled, $e){
list($sv, $az, $el, $snr, $u) = $e;