123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <?php
- $cellmode = 0;
- if ($argc != 3){
- if (($argc != 4) || strcmp("cells", $argv[3])){
- die("usage: ${argv[0]} count imagefile.png [cells]\n");
- } else {
- $cellmode = 1;
- }
- }
- $count = $argv[1] ;
- $sz = 640;
- $cellsize = 5;
- $radius = 8;
- $filled = 0;
- $im = imageCreate($sz, $sz);
- $C = colorsetup($im);
- skyview($im, $sz, $C);
- legend($im, $sz, $C);
- $sky = array();
- error_reporting(E_ALL);
- $service_port = 2947 ;
- $address = "127.0.0.1" ;
- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($socket === false) {
- echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
- }
- $result = socket_connect($socket, $address, $service_port);
- if ($result === false) {
- echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
- }
- $cmd = "?WATCH={\"enable\":true,\"json\":true};" ;
- socket_write($socket, $cmd, strlen($in));
- $out = '';
- $j = 0 ;
- while (($out = socket_read($socket, 2048)) && ( $j < $count) ) {
- if (strpos($out, "SKY")) {
- $j = $j + 1;
- $PRN = json_decode($out,true);
- $n = count($PRN["satellites"]) ;
- for($i = 0; $i < $n; $i++) {
- $sv = $PRN["satellites"][$i]["PRN"] ;
- $el = $PRN["satellites"][$i]["el"] ;
- $az = $PRN["satellites"][$i]["az"] ;
- $snr = $PRN["satellites"][$i]["ss"] ;
- $u = $PRN["satellites"][$i]["used"] ;
- 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, $el, $az, $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);
- imagePNG($im, $argv[2]);
- imageDestroy($im);
- exit(0);
- function colorsetup($im){
- $C['white'] = imageColorAllocate($im, 255, 255, 255);
- $C['ltgray'] = imageColorAllocate($im, 191, 191, 191);
- $C['mdgray'] = imageColorAllocate($im, 127, 127, 127);
- $C['dkgray'] = imageColorAllocate($im, 63, 63, 63);
- $C['black'] = imageColorAllocate($im, 0, 0, 0);
- $C['red'] = imageColorAllocate($im, 255, 0, 0);
- $C['brightgreen'] = imageColorAllocate($im, 0, 255, 0);
- $C['darkgreen'] = imageColorAllocate($im, 0, 192, 0);
- $C['blue'] = imageColorAllocate($im, 0, 0, 255);
- $C['cyan'] = imageColorAllocate($im, 0, 255, 255);
- $C['magenta'] = imageColorAllocate($im, 255, 0, 255);
- $C['yellow'] = imageColorAllocate($im, 255, 255, 0);
- $C['orange'] = imageColorAllocate($im, 255, 128, 0);
- return $C;
- }
- function legend($im, $sz, $C){
- $r = 30;
- $fn = 5;
- $x = $sz - (4*$r+7) - 2;
- $y = $sz - $r - 3;
- imageFilledRectangle($im, $x, $y, $x + 4*$r + 7, $y + $r +1, $C['dkgray']);
- imageRectangle($im, $x+0*$r+1, $y+1, $x + 1*$r + 0, $y + $r, $C['red']);
- imageRectangle($im, $x+1*$r+2, $y+1, $x + 2*$r + 2, $y + $r, $C['yellow']);
- imageRectangle($im, $x+2*$r+4, $y+1, $x + 3*$r + 4, $y + $r, $C['darkgreen']);
- imageRectangle($im, $x+4*$r+6, $y+1, $x + 3*$r + 6, $y + $r, $C['brightgreen']);
- imageString($im, $fn, $x+3+0*$r, $y+$r/3, "<30", $C['red']);
- imageString($im, $fn, $x+5+1*$r, $y+$r/3, "30+", $C['yellow']);
- imageString($im, $fn, $x+7+2*$r, $y+$r/3, "35+", $C['darkgreen']);
- imageString($im, $fn, $x+9+3*$r, $y+$r/3, "40+", $C['brightgreen']);
- }
- function radial($angle, $sz){
-
- $angle = deg2rad($angle);
-
- $r = $sz * 0.5 * 0.95;
-
- $x0 = sprintf("%d", (($sz * 0.5) - ($r * cos($angle))));
- $y0 = sprintf("%d", (($sz * 0.5) - ($r * sin($angle))));
- $x1 = sprintf("%d", (($sz * 0.5) + ($r * cos($angle))));
- $y1 = sprintf("%d", (($sz * 0.5) + ($r * sin($angle))));
- return array($x0, $y0, $x1, $y1);
- }
- function azel2xy($az, $el, $sz){
-
- $az += 270;
-
- $az = deg2rad($az);
-
- $r = $sz * 0.5 * 0.95;
- $r -= ($r * ($el/90));
-
- $x = sprintf("%d", (($sz * 0.5) + ($r * cos($az))));
- $y = sprintf("%d", (($sz * 0.5) + ($r * sin($az))));
- $x = $sz - $x;
- 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) ||
- ($az < 0) || ($el < 0))
- return;
- $color = $C['brightgreen'];
- if ($snr < 40)
- $color = $C['darkgreen'];
- if ($snr < 35)
- $color = $C['yellow'];
- if ($snr < 30)
- $color = $C['red'];
- if ($snr < 15)
- $color = $C['dkgray'];
-
-
-
-
-
-
-
- $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;
- 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'];
- list($x, $y) = azel2xy($el, $az, $sz);
- if ($snr > 0){
- if ($filled)
- imageFilledArc($im, $x, $y, $r, $r, 0, 360, $color, 0);
- else
- imageArc($im, $x, $y, $r, $r, 0, 360, $color);
- }
- }
- function elevation($im, $sz, $C, $a){
- $b = 90 - $a;
- $a = $sz * 0.95 * ($a/180);
- imageArc($im, $sz/2, $sz/2, $a*2, $a*2, 0, 360, $C['ltgray']);
- $x = $sz/2 - 16;
- $y = $sz/2 - $a;
- imageString($im, 2, $x, $y, $b, $C['ltgray']);
- }
- function skyview($im, $sz, $C){
- $a = 90; $a = $sz * 0.95 * ($a/180);
- imageFilledArc($im, $sz/2, $sz/2, $a*2, $a*2, 0, 360, $C['mdgray'], 0);
- imageArc($im, $sz/2, $sz/2, $a*2, $a*2, 0, 360, $C['black']);
- $x = $sz/2 - 16; $y = $sz/2 - $a;
- imageString($im, 2, $x, $y, "0", $C['ltgray']);
- $a = 85; $a = $sz * 0.95 * ($a/180);
- imageFilledArc($im, $sz/2, $sz/2, $a*2, $a*2, 0, 360, $C['white'], 0);
- imageArc($im, $sz/2, $sz/2, $a*2, $a*2, 0, 360, $C['ltgray']);
- imageString($im, 1, $sz/2 - 6, $sz+$a, '5', $C['black']);
- $x = $sz/2 - 16; $y = $sz/2 - $a;
- imageString($im, 2, $x, $y, "5", $C['ltgray']);
- skygrid($im, $sz, $C);
- $x = $sz/2 - 16; $y = $sz/2 - 8;
-
- imageString($im, 4, $sz/2 + 4, 2 , 'N', $C['black']);
- imageString($im, 4, $sz/2 + 4, $sz - 16 , 'S', $C['black']);
- imageString($im, 4, 4 , $sz/2 + 4, 'E', $C['black']);
- imageString($im, 4, $sz - 10 , $sz/2 + 4, 'W', $C['black']);
- }
- function skygrid($im, $sz, $C){
- for($i = 0; $i < 180; $i += 15){
- list($x0, $y0, $x1, $y1) = radial($i, $sz);
- imageLine($im, $x0, $y0, $x1, $y1, $C['ltgray']);
- }
- for($i = 15; $i < 90; $i += 15)
- elevation($im, $sz, $C, $i);
- }
- ?>
|