diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79f9a60 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pub diff --git a/func.php b/func.php index 2a4b4df..0d75fe9 100644 --- a/func.php +++ b/func.php @@ -1,7 +1,35 @@ = 60 ) { + // in minutes + $minutes = intval( $uptime / 60 ); + $seconds = $uptime % 60; + if( $minutes >= 60 ) { + $hours = intval( $minutes / 60 ); + $minutes = $minutes % 60; + if( $hours >= 24 ) { + $days = intval( $hours / 24 ); + $hours = $hours % 24; + $out = "$days days $hours hours $minutes minutes and $seconds seconds"; + } else { + // no days, only hours minutes and seconds + $out = "$hours hours $minutes minutes and $seconds seconds"; + } + } else { + // mintes < 60 only minuts, hours + $out = "$minutes minutes and $seconds seconds"; + } + } else { + // only seconds + $out = "$uptime seconds"; + } + + return $out; +} + function linkCallsign( $callsign ) { - $call = $callsign; $tmp = explode( "-", $callsign ); $call = $tmp[0]; $suffix = $tmp[1]; @@ -34,13 +62,20 @@ function rssiCalc( $val ) { return "$rssi ($val dBm)"; } -function printTable( $time, $callsign, $dgid, $duration, $repeater, $loss = "0", $ber = "0" ) { +function printTable( $time, $callsign, $dgid, $duration, $repeater, $loss = "---", $ber = "---" ) { + if( $duration >= 60 ) { + $min = str_pad( intval( $duration / 60 ), 2, "0", STR_PAD_LEFT ); + $sec = str_pad( $duration % 60, 2, "0", STR_PAD_LEFT ); + $duration = "$min:$sec"; + } else { + $duration = "00:" . str_pad( $duration, 2, "0", STR_PAD_LEFT ); + } echo " \n" . "$time\n" . "" . linkCallsign( $callsign ) ."\n" . "$dgid\n" . - "$duration\n" . "$repeater\n" . + "$duration\n" . "$loss\n" . "$ber\n" . "\n"; @@ -48,9 +83,9 @@ function printTable( $time, $callsign, $dgid, $duration, $repeater, $loss = "0", function getLastHeard($limit = MAXENTRIES) { $logPath = LOGPATH."/".MMDVM_PREFIX."-*.log"; - //$logLines = explode( "\n", `egrep -h "network (data|watchdog)|RF end" $logPath | tail -$limit` ); + //$logLines = explode( "\n", `egrep -h "network (data|watchdog)|RF end of transmission" $logPath | tail -$limit` ); //$logLines = explode( "\n", `egrep -h "YSF" $logPath | tail -$limit` ); - $logLines = explode( "\n", `egrep -h "YSF" $logPath` ); + $logLines = explode( "\n", `egrep -h "YSF," $logPath` ); $oldline = ""; @@ -62,41 +97,16 @@ function getLastHeard($limit = MAXENTRIES) { $duration = ""; $repeater = ""; - //$key = 0; - $printLines = []; - //$old_time = ""; - $new_time = ""; foreach( $logLines as $line ) { - $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 23 )." UTC" )); - - if( strpos( $line, "network data" )) { - //if( empty( $old_time )) { - if( !strpos( $oldline, "network data" )) { - $old_time = strtotime( substr( $line, 3, 19 )); - } - //$old_time = substr( $line, 3, 23 ); - //} - $oldline = $line; - } else { - if( strpos( $line, "network watchdog" )) { - $callsign = substr( $oldline, 59, strpos( $oldline, "to" ) - 59 ); - $dgid = substr( $oldline, 79, strpos( $oldline, "at " ) - 79 ); - //$duration = substr( $line, 62, strpos( $line, "seconds,", 62 ) - 62 ) . "sec"; - //$duration = substr( $line, 62, strpos( $line, "seconds,", 62 ) - 62 ); - $new_time = strtotime( substr( $oldline, 3, 19 )); - //$new_time = substr( $line, 3, 19 ); - //$duration = floatval( $new_time - $old_time ); - $duration = round( floatval(( $new_time - $old_time )), 1); - //$duration = date("i:s", floatval( $new_time - $old_time ) / 100000 ); - //$old_time = ""; - echo "
$time\nold_time: $old_time\nnew_time: $new_time\n$callsign
"; - $repeater = substr( $oldline, strpos( $oldline, "at " ) + 3, strpos( $oldline, " ", strpos( $oldline, "at " ) + 3) - strpos( $oldline, "at " ) + 3 ); - $loss = substr( $line, 75, strpos( $line, "%", 75 ) - 74 ); - $ber = substr( $line, 96, strpos( $line, "%", 96 ) - 95 ); - } elseif( strpos( $line, "RF end of" )) { - $oldline = ""; + if( empty( $oldline ) && strpos( $line, "network watchdog" )) { + // $oldine=$line; + continue; + } + + if( strpos( $line, "RF end of transmission" )) { + $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 23 )." UTC" )); $callsign = substr( $line, 69, strpos( $line, "to" ) - 69 ); $dgid = substr( $line, 89, strpos( $line, ",", 89 ) - 89 ); $duration = trim( substr( $line, 92, strpos( $line, "seconds,", 92 ) - 92 ), " ,"); @@ -106,22 +116,54 @@ function getLastHeard($limit = MAXENTRIES) { $ber = substr( $line, 111, strpos( $line, ",", 111 ) - 111 ); if( empty( $ber )) $ber = "---"; $repeater = $rssi; // use this testwise, debug - } else { - $oldline = ""; + } elseif( strpos( $line, "network data" )) { + if( strpos( $oldline, "network data" )) { + $oldline = $line; + continue; + } else { + $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 23 )." UTC" )); + $old_time = strtotime( $time ); + $oldline=$line; continue; + } + } elseif( strpos( $line, "network watchdog" )) { + $time = date( "Y-m-d H:i:s", strtotime( substr( $oldline, 3, 23 )." UTC" )); + $callsign = substr( $oldline, 59, strpos( $oldline, "to" ) - 59 ); + $dgid = substr( $oldline, 79, strpos( $oldline, "at " ) - 79 ); + $new_time = strtotime( date( "Y-m-d H:i:s", strtotime( substr( $oldline, 3, 23 )." UTC" ))); + // echo "
\$callsign: $callsign at \$dgid: $dgid\n\$old_time: ".date("Y-m-d H:i:s", $old_time ).
+		  // "\n\$new_time: ".date("Y-m-d H:i:s", $new_time )."
\n"; + // $duration = intval(( $new_time - $old_time )) . ".0"; + $duration = intval(( $new_time - $old_time )); + $repeater = substr( $oldline, strpos( $oldline, "at " ) + 3, strpos( $oldline, " ", strpos( $oldline, "at " ) + 3) - strpos( $oldline, "at " ) + 3 ); + $loss = substr( $line, 75, strpos( $line, "%", 75 ) - 74 ); + if( $loss == "0%" ) { + $loss = "-x-"; } - $tmp = []; - $tmp['time'] = $time; - $tmp['callsign'] = $callsign; - $tmp['dgid'] = $dgid; - $tmp['duration'] = $duration; - $tmp['repeater'] = $repeater; - $tmp['loss'] = $loss; - $tmp['ber'] = $ber; - array_unshift( $printLines, $tmp ); - unset( $tmp ); - } // end if clauses - } // end foreach + $ber = substr( $line, 96, strpos( $line, "%", 96 ) - 95 ); + if( $ber == "0.0%" ) $ber = "-x-"; + } else { + continue; + } + // echo "
\$callsign: $callsign at \$dgid: $dgid\n\$old_time: ".date("Y-m-d H:i:s", $old_time ).
+      //   "\n\$new_time: ".date("Y-m-d H:i:s", $new_time )."
\n"; + + // echo "
OLD LINE: $oldline\nLINE: $line\n
\n"; + + $tmp = []; + $tmp['time'] = $time; + $tmp['callsign'] = $callsign; + $tmp['dgid'] = $dgid; + $tmp['duration'] = $duration; + $tmp['repeater'] = $repeater; + $tmp['loss'] = $loss; + $tmp['ber'] = $ber; + array_unshift( $printLines, $tmp ); + unset( $tmp ); + + // Lastly we set $oldline as the actual line + $oldline = $line; + } $c = 0; diff --git a/index.php b/index.php index ae61f0e..da7f77d 100644 --- a/index.php +++ b/index.php @@ -30,7 +30,10 @@ } ?> -
+
\n"; + echo "Uptime: " . getUptime(); + ?>

Dashboard for YSF Hotspot OE7DRT

Dashboard @@ -61,8 +64,8 @@ Callsign DG-ID - Dur(s) Source/Repeater + Dur(s) Loss BER