adding debug, corr name resolution, code cleanup

This commit is contained in:
dg9vh 2016-10-12 15:45:24 +00:00
parent be58ad46fa
commit a4702b4005
7 changed files with 168 additions and 78 deletions

View file

@ -1,5 +1,5 @@
<?php
session_start();
//session_start();
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
include "config/config.php";
@ -10,7 +10,6 @@ $mmdvmconfigs = getMMDVMConfig();
$logLinesMMDVM = getMMDVMLog();
$reverseLogLinesMMDVM = $logLinesMMDVM;
array_multisort($reverseLogLinesMMDVM,SORT_DESC);
//$lastHeard = $_SESSION['lastHeard'];
if ($_GET['section'] == "mode") {
$mode = getActualMode(getLastHeard($reverseLogLinesMMDVM, TRUE), $mmdvmconfigs);
echo $mode;
@ -23,19 +22,28 @@ if ($_GET['section'] == "localTx") {
$localTXList = getHeardList($reverseLogLinesMMDVM, FALSE);
$lastHeard = Array();
for ($i = 0; $i < count($localTXList); $i++) {
$listElem = $localTXList[$i];
if ($listElem[6] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25")) {
$listElem[3] = getName($listElem[2]);
if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$listElem[2]\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
$listElem = $localTXList[$i];
if (defined("ENABLEXTDLOOKUP")) {
if ($listElem[6] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25")) {
$listElem[3] = getName($listElem[2]);
if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$listElem[2]\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://dmr.darc.de/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</a>";
}
array_push($lastHeard, $listElem);
}
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://dmr.darc.de/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</a>";
if ($listElem[5] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25")) {
if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$listElem[2]\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://dmr.darc.de/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</a>";
}
array_push($lastHeard, $listElem);
}
}
array_push($lastHeard, $listElem);
}
}
echo '{"data": '.json_encode($lastHeard)."}";
}
?>

View file

@ -5,8 +5,10 @@ function getMMDVMHostVersion() {
$filename = MMDVMHOSTPATH."/MMDVMHost";
exec($filename." -v 2>&1", $output);
if (!startsWith(substr($output[0],18,8),"20")) {
showLapTime("getMMDVMHostVersion");
return getMMDVMHostFileVersion();
} else {
showLapTime("getMMDVMHostVersion");
return substr($output[0],18,8)." (compiled ".getMMDVMHostFileVersion().")";
}
}
@ -15,6 +17,7 @@ function getMMDVMHostFileVersion() {
// returns creation-time of MMDVMHost as version-number
$filename = MMDVMHOSTPATH."/MMDVMHost";
if (file_exists($filename)) {
showLapTime("getMMDVMHostFileVersion");
return date("d M Y", filectime($filename));
}
}
@ -40,6 +43,7 @@ function getYSFGatewayConfig() {
}
fclose($configs);
}
showLapTime("getYSFGatewayConfig");
return $conf;
}
@ -118,7 +122,6 @@ function getMMDVMLog() {
function getShortMMDVMLog() {
// Open Logfile and copy loglines into LogLines-Array()
$logPath = MMDVMLOGPATH."/".MMDVMLOGPREFIX."-".date("Y-m-d").".log";
//$logLines = explode("\n", `tail -n100 $logPath`);
$logLines = explode("\n", `egrep -h "from|end|watchdog|lost" $logPath | tail -100`);
return $logLines;
}
@ -277,8 +280,12 @@ function getHeardList($logLines, $onlyLast) {
// Callsign or ID should be less than 11 chars long, otherwise it could be errorneous
if ( strlen($callsign) < 11 ) {
$name = "";//getName($callsign);
array_push($heardList, array($timestamp, $mode, $callsign, $name, $id, $target, $source, $duration, $loss, $ber));
$name = "";
if (defined("ENABLEXTDLOOKUP")) {
array_push($heardList, array($timestamp, $mode, $callsign, $name, $id, $target, $source, $duration, $loss, $ber));
} else {
array_push($heardList, array($timestamp, $mode, $callsign, $id, $target, $source, $duration, $loss, $ber));
}
$duration = "";
$loss ="";
$ber = "";
@ -300,11 +307,13 @@ function getLastHeard($logLines, $onlyLast) {
if ( ($listElem[1] == "D-Star") || ($listElem[1] == "YSF") || ($listElem[1] == "P25") || (startsWith($listElem[1], "DMR")) ) {
if(!(array_search($listElem[2]."#".$listElem[1].$listElem[4], $heardCalls) > -1)) {
array_push($heardCalls, $listElem[2]."#".$listElem[1].$listElem[4]);
if ($listElem[2] !== "??????????") {
$listElem[3] = getName($listElem[2]);
} else {
$listElem[3] = "---";
if (defined("ENABLEXTDLOOKUP")) {
if ($listElem[2] !== "??????????") {
//$listElem[3] = "Dummy"; //Should speed up this function - time-issue!
$listElem[3] = getName($listElem[2]); //Should speed up this function - time-issue!
} else {
$listElem[3] = "---";
}
}
if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$listElem[2]\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
@ -522,45 +531,13 @@ function getActiveYSFReflectors() {
$file = fopen(YSFHOSTSPATH."/".YSFHOSTSFILENAME, 'r');
if ($file) {
while (($line = fgetcsv($file, 1000, ";")) !== FALSE) {
//$line is an array of the csv elements
// print_r($line);
array_push($reflectorlist, array($line[1], $line[2], $line[0], $line[5]));
}
}
fclose($file);
return $reflectorlist;
}
/*
function getActiveYSFReflectors($logLines) {
// 00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122
// 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
// D: 2016-06-11 19:09:31.371 Have reflector status reply from 89164/FUSIONBE2 /FusionBelgium /002
$reflectors = Array();
$reflectorlist = Array();
foreach ($logLines as $logLine) {
if (strpos($logLine, "Have reflector status reply from")) {
$timestamp = substr($logLine, 3, 19);
$timestamp2 = new DateTime($timestamp);
$now = new DateTime();
$timestamp2->add(new DateInterval('PT2H'));
if ($now->format('U') <= $timestamp2->format('U')) {
$str = substr($logLine, 60);
$id = strtok($str, "/");
$name = strtok("/");
$description = strtok("/");
$concount = strtok("/");
if(!(array_search($name, $reflectors) > -1)) {
array_push($reflectors,$name);
array_push($reflectorlist, array($name, $description, $id, $concount, $timestamp));
}
}
}
}
array_multisort($reflectorlist);
return $reflectorlist;
}
*/
function getYSFReflectorById($id, $reflectors) {
if ($id ==-1) {
return "not linked";
@ -573,6 +550,39 @@ function getYSFReflectorById($id, $reflectors) {
}
}
/*
function getNames($delimiter) {
if (!isset($_SESSION['dmrIDs'])) {
$dmrIDs = Array();
$file = fopen(DMRIDDATPATH, 'r');
if ($file) {
while (($line = fgetcsv($file, 1000, $delimiter)) !== FALSE) {
array_push($dmrIDs, array('id'=>$line[0], 'callsign'=>$line[1], 'name'=>$line[2]));
}
}
$_SESSION['dmrIDs'] = $dmrIDs;
}
}
function getName($callsign) {
$dmrIDs = $_SESSION['dmrIDs'];
$key = array_search("$callsign", array_column($dmrIDs, 'callsign'));
//return $key;
$dmrID = $_SESSION['dmrIDs'][$key];
//var_dump($dmrID);
return $dmrID['name'];
}
function getName($callsign) {
// var_dump($_SESSION['dmrIDs']);
foreach ($_SESSION['dmrIDs'] as $dmrID) {
if ($dmrID[1] == $callsign) {
return $dmrID[2];
}
}
return "---";
}
*/
function getName($callsign) {
if (is_numeric($callsign)) {
return "---";
@ -596,4 +606,5 @@ function getName($callsign) {
return "DMRIDs.dat not correct!";
}
}
?>

View file

@ -2,17 +2,25 @@
//Some basic inits
$mmdvmconfigs = getMMDVMConfig();
$logLinesMMDVM = getMMDVMLog();
$_SESSION['logLinesMMDVM'] = $logLinesMMDVM;
showLapTime("getMMDVMLog");
//getNames(" ");
showLapTime("getNames");
//$_SESSION['logLinesMMDVM'] = $logLinesMMDVM;
$reverseLogLinesMMDVM = $logLinesMMDVM;
array_multisort($reverseLogLinesMMDVM,SORT_DESC);
$_SESSION['reverseLogLinesMMDVM'] = $reverseLogLinesMMDVM;
showLapTime("array_multisort");
//$_SESSION['reverseLogLinesMMDVM'] = $reverseLogLinesMMDVM;
$lastHeard = getLastHeard($reverseLogLinesMMDVM, FALSE);
$_SESSION['lastHeard'] = $lastHeard;
showLapTime("getLastHeard");
//$_SESSION['lastHeard'] = $lastHeard;
if (defined("ENABLEYSFGATEWAY")) {
$logLinesYSFGateway = getYSFGatewayLog();
showLapTime("getYSFGatewayLog");
$reverseLogLinesYSFGateway = $logLinesYSFGateway;
array_multisort($reverseLogLinesYSFGateway,SORT_DESC);
showLapTime("array_multisort");
$activeYSFReflectors = getActiveYSFReflectors();
showLapTime("getActiveYSFReflectors");
}
?>

View file

@ -5,10 +5,12 @@
exec("cat /sys/class/thermal/thermal_zone0/temp", $cputemp);
$cputemp = $cputemp[0] / 1000;
}
showLapTime("cputemp");
if (file_exists ("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")) {
exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", $cpufreq);
$cpufreq = $cpufreq[0] / 1000;
}
showLapTime("cpufreq");
if (defined("TEMPERATUREALERT") && $cputemp > TEMPERATUREHIGHLEVEL && $cputemp !== NULL) {
?>
@ -72,7 +74,7 @@
$output = shell_exec('cat /proc/loadavg');
$sysload = substr($output,0,strpos($output," "))*100;
showLapTime("sysload");
$stat1 = file('/proc/stat');
sleep(1);
$stat2 = file('/proc/stat');
@ -87,6 +89,7 @@
$cpu = array();
foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 1);
$cpuusage = round($cpu['user'] + $cpu['sys'], 2);
showLapTime("cpuusage");
$output = shell_exec('grep -c processor /proc/cpuinfo');
$cpucores = $output;
@ -94,7 +97,11 @@
$output = shell_exec('cat /proc/uptime');
$uptime = format_time(substr($output,0,strpos($output," ")));
$idletime = format_time((substr($output,strpos($output," ")))/$cpucores);
$pinStatus = trim(shell_exec("gpio -g read ".POWERONLINEPIN)); // Pin 18
showLapTime("idletime");
if (defined("SHOWPOWERSTATE")) {
$pinStatus = trim(shell_exec("gpio -g read ".POWERONLINEPIN)); // Pin 18
}
//returns 0 = low; 1 = high
?>
<div class="panel panel-default">

View file

@ -82,4 +82,28 @@ function checkSetup() {
}
error_reporting($el);
}
function startStopwatch() {
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$_SESSION['starttime'] = $time;
return $time;
}
function getLapTime() {
$start = $_SESSION['starttime'];
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$lap_time = round(($finish - $start), 4);
return $lap_time;
}
function showLapTime($func) {
if( defined("DEBUG") ) {
?><script>console.log('<?php echo $func . ": ". getLapTime(); ?> sec.');</script><?php
}
}
?>

View file

@ -1,14 +1,17 @@
<?php
session_start();
//session_start();
/*
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
$start = $time;*/
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// do not touch this includes!!! Never ever!!!
include "config/config.php";
include "include/tools.php";
startStopwatch();
showLapTime("Start of page");
include "include/functions.php";
include "include/init.php";
include "version.php";
@ -64,14 +67,22 @@ if (defined("ENABLEMANAGEMENT")) {
checkSetup();
// Here you can feel free to disable info-sections by commenting out with // before include
include "include/txinfo.php";
showLapTime("txinfo");
include "include/sysinfo.php";
showLapTime("sysinfo");
include "include/disk.php";
showLapTime("disk");
include "include/repeaterinfo.php";
showLapTime("repeaterinfo");
include "include/modes.php";
showLapTime("modes");
include "include/lh_ajax.php";
showLapTime("lh_ajax");
include "include/localtx_ajax.php";
showLapTime("localtx_ajax");
if (defined("ENABLEYSFGATEWAY")) {
include "include/ysfgatewayinfo.php";
showLapTime("ysfgatewayinfo");
}
?>
<div class="panel panel-info">
@ -79,12 +90,12 @@ if (defined("ENABLEYSFGATEWAY")) {
$datum = date("Y-m-d");
$uhrzeit = date("H:i:s");
echo "MMDVMHost-Dashboard V ".VERSION." | Last Reload $datum, $uhrzeit";
$time = microtime();
/*$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo '<!--Page generated in '.$total_time.' seconds.-->';
$total_time = round(($finish - $start), 4);*/
echo '<!--Page generated in '.getLapTime().' seconds.-->';
?> |
<?php
if (!isset($_GET['stoprefresh'])) {
@ -149,5 +160,13 @@ var ysfGatewaysT = $('#ysfGateways').dataTable( {
} );
});
</script>
<noscript>
For full functionality of this site it is necessary to enable JavaScript.
Here are the <a href="http://www.enable-javascript.com/" target="_blank">
instructions how to enable JavaScript in your web browser</a>.
</noscript>
</body>
</html>
<?php
showLapTime("End of Page");
?>

View file

@ -1,5 +1,5 @@
<?php
session_start();
//session_start();
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
include "config/config.php";
@ -16,7 +16,7 @@ var_dump($lastHeard);
echo"-->";
foreach ($lastHeard as $listElem) {
echo "<tr>";
if ($listElem[7] == null) {
if (defined("ENABLEXTDLOOKUP") && $listElem[7] == null || !defined("ENABLEXTDLOOKUP") && $listElem[6] == null) {
echo"<td nowrap>$listElem[0]</td>";
echo"<td nowrap>$listElem[1]</td>";
/*if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) {
@ -28,20 +28,33 @@ foreach ($lastHeard as $listElem) {
if (defined("ENABLEXTDLOOKUP")) {
//echo "<td nowrap>".getName($listElem[2])."</td>";
echo "<td nowrap>$listElem[3]</td>";
echo"<td nowrap>$listElem[3]</td>";
echo"<td nowrap>$listElem[4]</td>";
echo"<td nowrap>$listElem[5]</td>";
if ($listElem[6] == "RF"){
echo "<td nowrap><span class=\"label label-success\">RF</span></td>";
}else{
echo"<td nowrap>$listElem[6]</td>";
}
$UTC = new DateTimeZone("UTC");
$d1 = new DateTime($listElem[0], $UTC);
$d2 = new DateTime('now', $UTC);
$diff = $d2->getTimestamp() - $d1->getTimestamp();
echo"<td nowrap>$diff s</td>";
} else {
echo"<td nowrap>$listElem[3]</td>";
echo"<td nowrap>$listElem[4]</td>";
if ($listElem[5] == "RF"){
echo "<td nowrap><span class=\"label label-success\">RF</span></td>";
}else{
echo"<td nowrap>$listElem[5]</td>";
}
$UTC = new DateTimeZone("UTC");
$d1 = new DateTime($listElem[0], $UTC);
$d2 = new DateTime('now', $UTC);
$diff = $d2->getTimestamp() - $d1->getTimestamp();
echo"<td nowrap>$diff s</td>";
}
echo"<td nowrap>$listElem[4]</td>";
echo"<td nowrap>$listElem[5]</td>";
if ($listElem[5] == "RF"){
echo "<td nowrap><span class=\"label label-success\">RF</span></td>";
}else{
echo"<td nowrap>$listElem[6]</td>";
}
$UTC = new DateTimeZone("UTC");
$d1 = new DateTime($listElem[0], $UTC);
$d2 = new DateTime('now', $UTC);
$diff = $d2->getTimestamp() - $d1->getTimestamp();
echo"<td nowrap>$diff s</td>";
}
echo "</tr>";
}