code:ground_data
This is a local php based display tool for mini rogallo data. Positions, altitudes and headings are relayed to natrium42's tracker.
<?php session_register("time"); session_register("packets"); //used for the time since last packet include("php_includes/pChart/pChart.class"); include("php_includes/pChart/pData.class"); if($_POST["reset"]=='true') { $HTTP_SESSION_VARS ["time"]=0; $HTTP_SESSION_VARS ["packets"]=0; } /* function hitUrl($url) { $url = parse_url($url); $port = isset($url['port']) ? $url['port'] : 80; $socket = fsockopen($url['host'], $port); fputs($socket, "GET " . $url['path'] . " HTTP/1.0\n"); fputs($socket, "User-Agent: shmertmethod\n"); fputs($socket, "\n"); fclose($socket); }*/ $kml=array('<?xml version="1.0" encoding="UTF-8" ?><kml xmlns="http://earth.google.com/kml/2.1"><Document><Style id="track"><LineStyle><color>fff010c0</color></LineStyle><PolyStyle><color>3fc00880</color></PolyStyle></Style><Style id="place"><IconStyle><scale>1</scale><Icon><href>http://weather.uwyo.edu/icons/purple.gif</href></Icon></IconStyle></Style><Placemark><name>Launch</name><styleUrl>#place</styleUrl><description>Launch location was... at...</description><Point><altitudeMode>absolute</altitudeMode><coordinates>','</coordinates></Point></Placemark><Placemark><name>FlightPath</name><styleUrl>#track</styleUrl><LineString><extrude>1</extrude><altitudeMode>absolute</altitudeMode><coordinates>','</coordinates></LineString></Placemark><Placemark><name>PositionNow</name><styleUrl>#place</styleUrl><description>Current Position is... at...</description><Point><altitudeMode>absolute</altitudeMode><coordinates>','</coordinates></Point></Placemark></Document></kml>'); $kml_file="/home/laurence/Documents/earth_viewer/every5.kml"; $update_time=5; //refresh every x seconds echo "<html><head><title>Mini Rogallo</title><META HTTP-EQUIV='REFRESH' CONTENT='$update_time'><link rel='stylesheet' type='text/css' href='style.css'><script language='JavaScript'>function submit() { document.getElementById('hiddenresetform').submit() }</script></head><body>"; $HTTP_SESSION_VARS ["time"]++; //we ran again $DataSet_headings = new pData; $DataSet_positions = new pData; $DataSet_voltage = new pData; $DataSet_temperature = new pData; $date_string=substr(str_replace("-","",date("c")),0,8); $callsign="UKHAS"; $logfile = "/home/laurence/.fldigi/fldigi".$date_string.".log"; $fh = fopen($logfile, "r") or die("Cant open the logfile"); $theData = fread($fh, filesize($logfile)); fclose($fh); $offset=0; $telemlenght=80; $firstpos=strpos($theData,$callsign); $gnd=''; $status="ascending"; $maxalt=0; $numberofpackets=0; $firstposition=1; while($firstpos) //we have found another header { $offset=$firstpos; $firstpos=strpos($theData,$callsign,$offset+1); $ourstring=substr($theData,$offset,$telemlenght); $substrings=split(",",$ourstring,13); $checksum=0; //zero this ready for our count $stringpasses=FALSE; //this will be set to true if all conditions met if($substrings[0]=="UKHAS>" or $substrings[0]=="UKHAS-") //the short lenght packet $thelenght=8; elseif($substrings[0]=="UKHAS<") { //the long packet $thelenght=12; if(count($substrings)>=6) { $up=floatval($substrings[5]); if($up<=200) $thelenght++; //the ground control status increases packet lenght } } else $thelenght=200; //nothing can run if we have a dodgy header if(count($substrings)>=$thelenght) //are there enough variables { for($n=1;$n<($thelenght-1);$n++) { for($m=0;$m<strlen($substrings[$n]);$m++) { $checksum+=ord(substr($substrings[$n],$m,1)); $checksum=$checksum%256; } $checksum+=ord(","); $checksum=$checksum%256; } //$checksum+=ord(substr(strtoupper(dechex($checksum)),0,1)); //add on the first checksum hex character //$checksum%=256; $stringpasses=(strtoupper(dechex($checksum))==substr($substrings[$thelenght-1],0,2));//check the checksum //echo "check=".$checksum; echo " ".$substrings[$thelenght-1];echo $stringpasses;echo $thelenght; } if($stringpasses) //process the packet { $north=floatval($substrings[1]); $east=floatval($substrings[2]); $up=floatval($substrings[3]); $north_kml[]=$north*57.29577951; //for google earth $east_kml[]=$east*57.29577951; $altitude_kml[]=$up; $sats=floatval($substrings[4]); if($firstposition==1) { $takeoffnorth=$north*6378; //record the takeoff point $takeoffeast=$east*6378*cos($east); $firstposition=0; } $DataSet_positions->AddPoint($north*6378-$takeoffnorth,"Serie1"); //North in KM $DataSet_positions->AddPoint($east*6378*cos($east)-$takeoffeast,"Serie2"); //East in Km $DataSet_positions->AddPoint($up,"Serie3"); //Altitude if($substrings[0]=="UKHAS<") { $status="descending"; $headings[]=floatval($substrings[5]); $targets[]=floatval($substrings[6]); $headingsf[]=floatval($substrings[7]); $rates[]=floatval($substrings[8]); if($up<200) { $DataSet_voltage->Addpoint(floatval($substrings[10]),"Serie1"); $DataSet_temperature->AddPoint(floatval($substrings[11]),"Serie1");//Bat voltage, Internal temperature $gnd=$substrings[9]; } else { $DataSet_voltage->AddPoint(floatval($substrings[9]),"Serie1"); $DataSet_temperature->AddPoint(floatval($substrings[10]),"Serie1"); } } else { $DataSet_voltage->Addpoint(floatval($substrings[5]),"Serie1"); if($substrings[6]!=="0") $DataSet_temperature->AddPoint(floatval($substrings[6]),"Serie1");//Bat voltage, Internal temperature if($status=="descending") $status="touchdown!"; } if(floatval($up)>$maxalt) $maxalt=floatval($up); $numberofpackets++; //we have got a new packet if($numberofpackets>$HTTP_SESSION_VARS ["packets"] ) { $HTTP_SESSION_VARS ["time"]=0; $HTTP_SESSION_VARS ["packets"]=$numberofpackets; $request = 'http://spacenear.us/tracker/track'; //send to natrium42 tracker $format = 'php'; // this can be xml, json, html, or php $args .= 'vehicle='.$callsign; $args .= '&time=0'; $args .= '&lat='.$north*57.29577951; $args .= '&lon='.$east*57.29577951; $args .= '&alt='.$up; if($substrings[0]=="UKHAS<") $args .= '&heading='.$substrings[10]; else $args .= '&heading=0'; $args .= '&speed=0'; $args .= '&pass='.$pass; // Get and config the curl session object $session = curl_init($request.'.'.$format.'?'.$args); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); //execute the request and close ob_start(); $response = curl_exec($session); ob_end_clean(); curl_close($session); unset($response); $newdata=TRUE; } else $newdata=FALSE; } } for($n=count($headings)-1;$n>count($headings)-21;$n--) //The last 20 seconds { $DataSet_headings->AddPoint($headings[$n]*57.295,"Serie1"); $DataSet_headings->AddPoint($headingsf[$n]*57.295,"Serie2"); $DataSet_headings->AddPoint($rates[$n]*57.295,"Serie3"); $DataSet_headings->AddPoint($targets[$n]*57.295,"Serie4"); } $link="<a href='http://maps.google.com/?q=@"; $link.=strval($north*57.29577951); $link.=","; $link.=strval($east*57.29577951); $link.="' target='_blank'>View in Google maps</a>"; if($newdata){ $DataSet_headings->AddAllSeries(); $DataSet_headings->SetAbsciseLabelSerie(); $DataSet_headings->SetSerieName("GPS","Serie1"); $DataSet_headings->SetSerieName("Filtered","Serie2"); $DataSet_headings->SetSerieName("Turn Rate","Serie3"); $DataSet_headings->SetSerieName("Target","Serie4"); // Initialise the graph $Test = new pChart(700,230); $Test->setFontProperties("php_includes/Fonts/tahoma.ttf",8); $Test->setGraphArea(70,30,680,200); $Test->drawGraphArea(213,217,221,FALSE); $Test->drawGraphAreaGradient(30,30,30,-50); $Test->setFixedScale(-180,180,6,0,$numberofpackets,20); $Test->drawScale($DataSet_headings->GetData(),$DataSet_headings->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); $Test->drawGrid(4,TRUE,230,230,230,20); // Draw the 0 line $Test->setFontProperties("php_includes/Fonts/tahoma.ttf",6); $Test->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the line graph $Test->drawLineGraph($DataSet_headings->GetData(),$DataSet_headings->GetDataDescription()); $Test->clearShadow(); // Finish the graph $Test->setFontProperties("php_includes/Fonts/tahoma.ttf",8); $Test->drawLegend(75,35,$DataSet_headings->GetDataDescription(),255,255,255); $Test->setFontProperties("php_includes/Fonts/tahoma.ttf",10); $Test->drawTitle(60,22,"Heading - last 20 seconds",50,50,50,585); $Test->Render("Headings.png"); unset($Test); $DataSet_headings->RemoveSerie("Serie1","Serie2","Serie3"); //the position graph $DataSet_positions->AddSerie("Serie1","Serie2"); $DataSet_positions->SetSerieName("Position","Serie1"); $DataSet_positions->SetXAxisName("East (Km)"); $DataSet_positions->SetYAxisName("North (Km)"); // Initialise the graph $Test2 = new pChart(300,300); $Test2->drawGraphAreaGradient(0,0,0,-100,TARGET_BACKGROUND); // Prepare the graph area $Test2->setFontProperties("php_includes/Fonts/tahoma.ttf",8); $Test2->setGraphArea(55,30,270,230); $Test2->drawXYScale($DataSet_positions->GetData(),$DataSet_positions->GetDataDescription(),"Serie1","Serie2",213,217,221,TRUE,45); $Test2->drawGraphArea(213,217,221,FALSE); $Test2->drawGraphAreaGradient(30,30,30,-50); $Test2->drawGrid(4,TRUE,230,230,230,20); // Draw the chart $Test2->setShadowProperties(2,2,0,0,0,60,4); $Test2->drawXYGraph($DataSet_positions->GetData(),$DataSet_positions->GetDataDescription(),"Serie1","Serie2",0); $Test2->clearShadow(); // Draw the title $Title = "Rogallo position: "; $Title.= strval($north*57.29577951); $Title.= ","; $Title.= strval($east*57.29577951); $Test2->drawTextBox(0,280,300,300,$Title,0,255,255,255,ALIGN_LEFT,TRUE,0,0,0,30); //draw altitude box $title = "Altitude:"; $title.= strval(floatval($up)/1000); $title.= " Km, Max:"; $title.= strval(floatval($maxalt)/1000); $title.= " Km"; $Test2->drawTextBox(0,0,300,30,$title,0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30); // Draw the legend $Test2->setFontProperties("php_includes/Fonts/pf_arma_five.ttf",6); $Test2->drawLegend(5,260,$DataSet_positions->GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE); $Test2->Render("Positions.png"); $DataSet_positions->RemoveSerie("Serie1","Serie2"); //the data plots //the temperature $DataSet_temperature->AddSerie("Serie1"); $DataSet_temperature->SetAbsciseLabelSerie(); $DataSet_temperature->SetSerieName("Temperature (C)","Serie1"); // Initialise the graph $Test3 = new pChart(400,150); $Test3->setFontProperties("php_includes/Fonts/tahoma.ttf",8); $Test3->setGraphArea(30,10,390,130); $Test3->drawGraphArea(213,217,221,FALSE); $Test3->drawGraphAreaGradient(30,30,30,-50); $Test3->drawScale($DataSet_temperature->GetData(),$DataSet_temperature->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,FALSE,120); //$Test3->drawGrid(1,TRUE,230,230,230,20); // Draw the 0 line $Test3->setFontProperties("php_includes/Fonts/tahoma.ttf",6); $Test3->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the line graph $Test3->drawLineGraph($DataSet_temperature->GetData(),$DataSet_temperature->GetDataDescription()); $Test3->clearShadow(); // Finish the graph $Test3->setFontProperties("php_includes/Fonts/tahoma.ttf",8); $Test3->drawLegend(35,14,$DataSet_temperature->GetDataDescription(),255,255,255); $Test3->setFontProperties("php_includes/Fonts/tahoma.ttf",10); $Test3->Render("Temperature.png"); unset($Test3); //voltage $DataSet_voltage->RemoveSerie("Serie2"); $DataSet_voltage->AddSerie("Serie1"); $DataSet_voltage->SetAbsciseLabelSerie(); $DataSet_voltage->SetSerieName("Battery voltage","Serie1"); // Initialise the graph $Test4 = new pChart(400,150); $Test4->setFontProperties("php_includes/Fonts/tahoma.ttf",8); $Test4->setGraphArea(30,10,390,130); $Test4->drawGraphArea(213,217,221,FALSE); $Test4->drawGraphAreaGradient(30,30,30,-50); $Test4->setFixedScale(5.5,8.5,6,0,$numberofpackets,20); $Test4->drawScale($DataSet_voltage->GetData(),$DataSet_voltage->GetDataDescription(),SCALE_START0,150,150,150,TRUE,0,2,FALSE,120); //$Test3->drawGrid(1,TRUE,230,230,230,20); // Draw the 0 line $Test4->setFontProperties("php_includes/Fonts/tahoma.ttf",6); $Test4->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the line graph $Test4->drawLineGraph($DataSet_voltage->GetData(),$DataSet_voltage->GetDataDescription()); $Test4->clearShadow(); // Finish the graph $Test4->setFontProperties("php_includes/Fonts/tahoma.ttf",8); $Test4->drawLegend(35,14,$DataSet_voltage->GetDataDescription(),255,255,255); $Test4->setFontProperties("php_includes/Fonts/tahoma.ttf",10); $Test4->Render("Voltage.png"); //now make the updated kml $fkml = fopen($kml_file, "w") or die("Cant open the kml file"); fprintf($fkml,"%s%f,%f,%f%s",$kml[0],$east_kml[0],$north_kml[0],$altitude_kml[0],$kml[1]); for($k=0;$k<count($north_kml);$k++) fprintf($fkml,"%f,%f,%f\n",$north_kml[$k],$east_kml[$k],$altitude_kml[$k]); $k--; fprintf($fkml,"%s%f,%f,%f%s",$kml[2],$north_kml[$k],$east_kml[$k],$altitude_kml[$k],$kml[3]); fclose($fkml); } ?> <form action="minirog.php" method="POST" id="hiddenresetform"> <input type="hidden" name="reset" value="true"> </form> <div id="container"> <div id="header"> <li><h1> Mini Rogallo Tracker - Status: <?php echo $status?> </h1></li> </div> <img src="Headings.png"> <div id="large_square"> <img src="Positions.png"> </div> <div id="small_rec_group"> <div class="small_rec"> <img src="Temperature.png"> </div> <div class="small_rec"> <img src="Voltage.png"> </div> </div> <div id="footer"> <span><a href="javascript:submit()">Reset</a> | Waiting: <?php echo ($update_time*$HTTP_SESSION_VARS["time"])?>(s) | Tracked sats: <?php echo $sats?> | Ground Status: <?php echo $gnd?> | Callsign:<?php echo $callsign ?> | <?php echo $link ?> | <a href="http://spacenear.us/tracker" target="_blank">Tracker</a> | By Laurence, 2009 </span> </div> </div> </body> </html>
code/ground_data.txt · Last modified: 2009/03/19 22:53 by laurenceb