From a4702b4005f46a66341c272d1352b4e132e5c2a1 Mon Sep 17 00:00:00 2001 From: dg9vh Date: Wed, 12 Oct 2016 15:45:24 +0000 Subject: [PATCH] adding debug, corr name resolution, code cleanup --- ajax.php | 32 +++++++++------ include/functions.php | 91 ++++++++++++++++++++++++------------------- include/init.php | 14 +++++-- include/sysinfo.php | 13 +++++-- include/tools.php | 24 ++++++++++++ index.php | 29 +++++++++++--- txinfo.php | 43 +++++++++++++------- 7 files changed, 168 insertions(+), 78 deletions(-) diff --git a/ajax.php b/ajax.php index e3af8b5..ede75db 100644 --- a/ajax.php +++ b/ajax.php @@ -1,5 +1,5 @@ ".str_replace("0","Ø",$listElem[2]).""; + $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] = "".str_replace("0","Ø",$listElem[2]).""; + } else { + $listElem[2] = "".$listElem[2].""; + } + array_push($lastHeard, $listElem); + } } else { - $listElem[2] = "".$listElem[2].""; + 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] = "".str_replace("0","Ø",$listElem[2]).""; + } else { + $listElem[2] = "".$listElem[2].""; + } + array_push($lastHeard, $listElem); + } } - array_push($lastHeard, $listElem); } -} echo '{"data": '.json_encode($lastHeard)."}"; } - ?> \ No newline at end of file diff --git a/include/functions.php b/include/functions.php index 59ba735..e1c10c3 100644 --- a/include/functions.php +++ b/include/functions.php @@ -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] = "".str_replace("0","Ø",$listElem[2]).""; @@ -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!"; } } + ?> diff --git a/include/init.php b/include/init.php index d5c3183..dd67ed4 100644 --- a/include/init.php +++ b/include/init.php @@ -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"); } ?> diff --git a/include/sysinfo.php b/include/sysinfo.php index 2d791d8..9ed138d 100644 --- a/include/sysinfo.php +++ b/include/sysinfo.php @@ -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'); @@ -86,7 +88,8 @@ $total = array_sum($dif); $cpu = array(); foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 1); - $cpuusage = round($cpu['user'] + $cpu['sys'], 2); + $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 ?>
diff --git a/include/tools.php b/include/tools.php index e9a423e..2ef3944 100644 --- a/include/tools.php +++ b/include/tools.php @@ -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") ) { + ?> diff --git a/index.php b/index.php index 9c274d7..5106a6a 100644 --- a/index.php +++ b/index.php @@ -1,14 +1,17 @@
@@ -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 ''; +$total_time = round(($finish - $start), 4);*/ +echo ''; ?> | + + \ No newline at end of file diff --git a/txinfo.php b/txinfo.php index 457b6d5..0e873bd 100644 --- a/txinfo.php +++ b/txinfo.php @@ -1,5 +1,5 @@ "; foreach ($lastHeard as $listElem) { echo ""; - if ($listElem[7] == null) { + if (defined("ENABLEXTDLOOKUP") && $listElem[7] == null || !defined("ENABLEXTDLOOKUP") && $listElem[6] == null) { echo"$listElem[0]"; echo"$listElem[1]"; /*if (constant("SHOWQRZ") && $listElem[2] !== "??????????" && !is_numeric($listElem[2])) { @@ -28,20 +28,33 @@ foreach ($lastHeard as $listElem) { if (defined("ENABLEXTDLOOKUP")) { //echo "".getName($listElem[2]).""; - echo "$listElem[3]"; + echo"$listElem[3]"; + echo"$listElem[4]"; + echo"$listElem[5]"; + if ($listElem[6] == "RF"){ + echo "RF"; + }else{ + echo"$listElem[6]"; + } + $UTC = new DateTimeZone("UTC"); + $d1 = new DateTime($listElem[0], $UTC); + $d2 = new DateTime('now', $UTC); + $diff = $d2->getTimestamp() - $d1->getTimestamp(); + echo"$diff s"; + } else { + echo"$listElem[3]"; + echo"$listElem[4]"; + if ($listElem[5] == "RF"){ + echo "RF"; + }else{ + echo"$listElem[5]"; + } + $UTC = new DateTimeZone("UTC"); + $d1 = new DateTime($listElem[0], $UTC); + $d2 = new DateTime('now', $UTC); + $diff = $d2->getTimestamp() - $d1->getTimestamp(); + echo"$diff s"; } - echo"$listElem[4]"; - echo"$listElem[5]"; - if ($listElem[5] == "RF"){ - echo "RF"; - }else{ - echo"$listElem[6]"; - } - $UTC = new DateTimeZone("UTC"); - $d1 = new DateTime($listElem[0], $UTC); - $d2 = new DateTime('now', $UTC); - $diff = $d2->getTimestamp() - $d1->getTimestamp(); - echo"$diff s"; } echo ""; }