MMDVMHost-Dashboard/include/functions.php

196 lines
5.4 KiB
PHP
Raw Normal View History

2016-04-30 15:38:12 +02:00
<?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;
}
2016-04-30 15:38:12 +02:00
// 00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122
// 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 19:43:21.839 DMR Slot 2, received network voice header from DL1ESZ to TG 9
2016-04-30 19:33:41 +02:00
// M: 2016-04-30 14:57:43.072 DMR Slot 2, received RF voice header from DG9VH to 5000
function getHeardList($logLines) {
2016-05-03 21:36:47 +02:00
array_multisort($logLines,SORT_DESC);
2016-04-30 15:38:12 +02:00
$heardList = array();
$ts1duration = "";
$ts1loss = "";
$ts1ber = "";
$ts2duration = "";
$ts2loss = "";
$ts2ber = "";
$dstarduration = "";
$dstarloss = "";
$dstarber = "";
foreach ($logLines as $logLine) {
$duration = "";
$loss = "";
$ber = "";
$endmode = "";
//removing invalid lines
if(strpos($logLine,"BS_Dwn_Act")) {
2016-05-03 06:50:49 +02:00
continue;
} else if(strpos($logLine,"invalid access")) {
2016-05-03 06:50:49 +02:00
continue;
}
2016-05-03 21:36:47 +02:00
if(strpos($logLine,"end of")) {
$lineTokens = explode(", ",$logLine);
2016-05-03 21:36:47 +02:00
$duration = strtok($lineTokens[2], " ");
$loss = $lineTokens[3];
if (startsWith($loss,"BER")) {
$ber = substr($loss, 5);
$loss = "";
} else {
$loss = strtok($loss, " ");
$ber = substr($lineTokens[4], 5);
}
switch (substr($logLine, 27, strpos($logLine,",") - 27)) {
case "D-Star":
$dstarduration = $duration;
$dstarloss = $loss;
$dstarber = $ber;
break;
case "DMR Slot 1":
$ts1duration = $duration;
$ts1loss = $loss;
$ts1ber = $ber;
break;
case "DMR Slot 2":
$ts2duration = $duration;
$ts2loss = $loss;
$ts2ber = $ber;
break;
}
2016-05-03 21:36:47 +02:00
}
$timestamp = substr($logLine, 3, 19);
$mode = substr($logLine, 27, strpos($logLine,",") - 27);
$callsign2 = substr($logLine, strpos($logLine,"from") + 5, strpos($logLine,"to") - strpos($logLine,"from") - 6);
$callsign = $callsign2;
if (strpos($callsign2,"/") > 0) {
$callsign = substr($callsign2, 0, strpos($callsign2,"/"));
}
$callsign = trim($callsign);
$id ="";
if ($mode == "D-Star") {
$id = substr($callsign2, strpos($callsign2,"/") + 1);
}
$target = substr($logLine, strpos($logLine, "to") + 3);
$source = "RF";
if (strpos($logLine,"network") > 0 ) {
$source = "Network";
}
switch ($mode) {
case "D-Star":
$duration = $dstarduration;
$loss = $dstarloss;
$ber = $dstarber;
break;
case "DMR Slot 1":
$duration = $ts1duration;
$loss = $ts1loss;
$ber = $ts1ber;
break;
case "DMR Slot 2":
$duration = $ts2duration;
$loss = $ts2loss;
$ber = $ts2ber;
break;
}
2016-05-03 06:50:49 +02:00
if ( strlen($callsign) < 7 ) {
2016-05-03 21:36:47 +02:00
array_push($heardList, array($timestamp, $mode, $callsign, $id, $target, $source, $duration, $loss, $ber));
$duration = "";
$loss ="";
$ber = "";
2016-04-30 15:38:12 +02:00
}
}
return $heardList;
}
function getLastHeard($logLines) {
$lastHeard = array();
$heardCalls = array();
$heardList = getHeardList($logLines);
2016-04-30 15:38:12 +02:00
foreach ($heardList as $listElem) {
if ( ($listElem[1] == "D-Star") || (startsWith($listElem[1], "DMR")) ) {
if(!(array_search($listElem[2]."#".$listElem[1].$listElem[3], $heardCalls) > -1)) {
array_push($heardCalls, $listElem[2]."#".$listElem[1].$listElem[3]);
array_push($lastHeard, $listElem);
}
2016-04-30 15:38:12 +02:00
}
}
return $lastHeard;
}
2016-05-02 10:19:08 +02:00
function getActualMode($logLines) {
array_multisort($logLines,SORT_DESC);
foreach ($logLines as $logLine) {
if (strpos($logLine, "Mode set to")) {
return substr($logLine, 39);
//break;
}
}
return "Idle";
}
function getActualLink($logLines, $mode) {
//M: 2016-05-02 07:04:10.504 D-Star link status set to "Verlinkt zu DCS002 S"
2016-05-02 17:36:19 +02:00
//M: 2016-04-03 16:16:18.638 DMR Slot 2, received network voice header from 4000 to 2625094
//M: 2016-04-03 19:30:03.099 DMR Slot 2, received network voice header from 4020 to 2625094
2016-05-02 10:19:08 +02:00
array_multisort($logLines,SORT_DESC);
switch ($mode) {
case "D-Star":
foreach ($logLines as $logLine) {
if (strpos($logLine, "D-Star link status set to")) {
return substr($logLine, 54, strlen($logLine) - 56);
2016-05-02 17:36:19 +02:00
}
2016-05-02 10:19:08 +02:00
}
2016-05-02 17:36:19 +02:00
return "not linked";
2016-05-02 10:19:08 +02:00
break;
case "DMR Slot 1":
2016-05-02 17:36:19 +02:00
foreach ($logLines as $logLine) {
if(substr($logLine, 27, strpos($logLine,",") - 27) == "DMR Slot 1") {
$from = substr($logLine, strpos($logLine,"from") + 5, strpos($logLine,"to") - strpos($logLine,"from") - 6);
if (strlen($from) == 4 && startsWith($from,"4")) {
if ($from == "4000") {
return "not linked";
} else {
return $from;
}
}
}
}
return "not linked";
2016-05-02 10:19:08 +02:00
break;
case "DMR Slot 2":
2016-05-02 17:36:19 +02:00
foreach ($logLines as $logLine) {
if(substr($logLine, 27, strpos($logLine,",") - 27) == "DMR Slot 2") {
$from = substr($logLine, strpos($logLine,"from") + 5, strpos($logLine,"to") - strpos($logLine,"from") - 6);
if (strlen($from) == 4 && startsWith($from,"4")) {
if ($from == "4000") {
return "not linked";
} else {
return $from;
}
}
}
}
return "not linked";
2016-05-02 10:19:08 +02:00
break;
2016-05-02 17:36:19 +02:00
}
return "something went wrong!";
2016-05-02 10:19:08 +02:00
}
//Some basic inits
$logLines = getLog();
2016-04-30 15:38:12 +02:00
?>