Code-reorg, filtering odd messages in LH

This commit is contained in:
dg9vh 2016-05-02 09:50:26 +02:00
parent c4da4570d7
commit a70608a6d4
2 changed files with 46 additions and 29 deletions

View file

@ -1,46 +1,60 @@
<?php <?php
function getLog() {
// Open Logfile and copy loglines into LogLines-Array()
$logLines = array();
if ($log = fopen(LOGFILE,'r')) {
while ($logLine = fgets($log)) {
array_push($logLines, $logLine);
}
fclose($log);
}
return $logLines;
}
// 00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122 // 00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122
// 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 // 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901
// M: 2016-04-29 00:15:00.013 D-Star, received network header from DG9VH /ZEIT to CQCQCQ via DCS002 S // M: 2016-04-29 00:15:00.013 D-Star, received network header from DG9VH /ZEIT to CQCQCQ via DCS002 S
// M: 2016-04-29 19:43:21.839 DMR Slot 2, received network voice header from DL1ESZ to TG 9 // M: 2016-04-29 19:43:21.839 DMR Slot 2, received network voice header from DL1ESZ to TG 9
// M: 2016-04-30 14:57:43.072 DMR Slot 2, received RF voice header from DG9VH to 5000 // M: 2016-04-30 14:57:43.072 DMR Slot 2, received RF voice header from DG9VH to 5000
function getHeardList() { function getHeardList($logLines) {
$heardList = array(); $heardList = array();
if ($log = fopen(LOGFILE,'r')) { foreach ($logLines as $logLine) {
while ($logLine = fgets($log)) { //removing invalid lines
// timestamp, mode, callsign, dstarid, target if(strpos($logLine,"BS_Dwn_Act")) {
$timestamp = substr($logLine, 3, 19); break;
$mode = substr($logLine, 27, strpos($logLine,",") - 27); } else if(strpos($logLine,"invalid access")) {
$callsign2 = substr($logLine, strpos($logLine,"from") + 5, strpos($logLine,"to") - strpos($logLine,"from") - 6); break;
$callsign = $callsign2; }
if (strpos($callsign2,"/") > 0) {
$callsign = substr($callsign2, 0, strpos($callsign2,"/")); $timestamp = substr($logLine, 3, 19);
} $mode = substr($logLine, 27, strpos($logLine,",") - 27);
$callsign = trim($callsign); $callsign2 = substr($logLine, strpos($logLine,"from") + 5, strpos($logLine,"to") - strpos($logLine,"from") - 6);
$id =""; $callsign = $callsign2;
if ($mode == "D-Star") { if (strpos($callsign2,"/") > 0) {
$id = substr($callsign2, strpos($callsign2,"/") + 1); $callsign = substr($callsign2, 0, strpos($callsign2,"/"));
} }
$target = substr($logLine, strpos($logLine, "to") + 3); $callsign = trim($callsign);
$source = "RF"; $id ="";
if (strpos($logLine,"network") > 0 ) { if ($mode == "D-Star") {
$source = "Network"; $id = substr($callsign2, strpos($callsign2,"/") + 1);
} }
$target = substr($logLine, strpos($logLine, "to") + 3);
if ( strlen($callsign <7) ) { $source = "RF";
array_push($heardList, array($timestamp, $mode, $callsign, $id, $target, $source)); if (strpos($logLine,"network") > 0 ) {
} $source = "Network";
}
if ( strlen($callsign <7) ) {
array_push($heardList, array($timestamp, $mode, $callsign, $id, $target, $source));
} }
fclose($log);
} }
return $heardList; return $heardList;
} }
function getLastHeard() { function getLastHeard($logLines) {
$lastHeard = array(); $lastHeard = array();
$heardCalls = array(); $heardCalls = array();
$heardList = getHeardList(); $heardList = getHeardList($logLines);
array_multisort($heardList,SORT_DESC); array_multisort($heardList,SORT_DESC);
foreach ($heardList as $listElem) { foreach ($heardList as $listElem) {
if ( ($listElem[1] == "D-Star") || (startsWith($listElem[1], "DMR")) ) { if ( ($listElem[1] == "D-Star") || (startsWith($listElem[1], "DMR")) ) {
@ -52,4 +66,7 @@ function getLastHeard() {
} }
return $lastHeard; return $lastHeard;
} }
//Some basic inits
$logLines = getLog();
?> ?>

View file

@ -1,5 +1,5 @@
<?php <?php
$lastHeard = getLastHeard(); $lastHeard = getLastHeard($logLines);
?> ?>
<div class="panel panel-default"> <div class="panel panel-default">
<!-- Standard-Panel-Inhalt --> <!-- Standard-Panel-Inhalt -->