Trying to fix issues with buffer / allmon not sending correct data

This commit is contained in:
Rob Vella 2020-07-31 17:39:54 -07:00
parent 8d1a71f0e8
commit 2803a10254
7 changed files with 169 additions and 113 deletions

6
app.js
View File

@ -99,7 +99,7 @@ let App = new Vue({
rows.forEach((v) => {
// let match = v.match(/([A-Za-z]+ [0-9]+ [0-9]+\:[0-9]+\:[0-9]+) (rpt|stn)([A-Za-z0-9]+) ?.*? (?:\[(?:via) ([0-9]+))?/);
let match = v.match(/([A-Za-z]+ [0-9]+ [0-9]+\:[0-9]+\:[0-9]+) (rpt|stn)([A-Za-z0-9]+) (KEY|UNKEY)?.*? (?:\[(?:via) ([0-9]+))?/);
let match = v.match(/([A-Za-z]+ [0-9]+ [0-9]+\:[0-9]+\:[0-9]+) (rpt|stn)([A-Za-z0-9]+) (KEY|UNKEY) (?:\[(?:via) ([0-9]+))?/);
if (!match) return;
let type = this.getNodeType(match[2]);
@ -129,10 +129,6 @@ let App = new Vue({
fetchNodeInfo(node, type) {
if (type === 0) return;
// Bind it and recurse, fetch it again
// if (typeof this.nodes[type][node] === "undefined") {
// this.nodes[type][node] = null;
// return this.fetchNodeInfo(node, type);
if (this.nodes[type+node]) {
// Don't even call fetchNode**
return this.nodes[type+node];

View File

@ -9,6 +9,7 @@
}
],
"require": {
"ext-json": "*",
"symfony/var-dumper": "^5.1",
"nesbot/carbon": "^2.37"
},

View File

@ -1,5 +1,7 @@
<?php
$streamFile = __DIR__.'/storage/stream.txt';
$cmd = $_GET['cmd'] ?? null;
$node = intval($_GET['node'] ?? null);
$type = intval($_GET['type'] ?? null);
@ -7,13 +9,13 @@ $type = intval($_GET['type'] ?? null);
header("Cache-Control: max-age=0");
if ($cmd === "log" || $cmd == "logText") {
$irlpData = file_get_contents("http://www3.winsystem.org/monitor/ajax-logtail.php");
$data = file_get_contents(__DIR__."/storage/stream.txt");
// $irlpData = file_get_contents("http://www3.winsystem.org/monitor/ajax-logtail.php");
$data = file_get_contents($streamFile);
// Just output the raw data
if ($cmd === "log") {
echo $irlpData;
echo $data;
// echo $irlpData;
return;
}
} else if ($cmd === "node") {

View File

@ -25,7 +25,7 @@
<thead>
<tr>
<th>Node#</th>
<!-- <th>Via</th>-->
<th>Via</th>
<th>Key</th>
<th>Type</th>
<th>When</th>
@ -35,6 +35,7 @@
<tbody v-cloak>
<tr v-for="row in logs">
<td><lt-node-link :node="row.node" :type="row.type" /></td>
<td>{{ row.via }}</td>
<td>{{ row.key }}</td>
<td>{{ row.typeLabel }}</td>
<td class="when">{{ row.dateTime.format('hh:mm:ss MM/DD/YY') }}</td>

View File

@ -1,94 +0,0 @@
<?php
require 'vendor/autoload.php';
use Carbon\Carbon;
$keyed = [];
// Allstar Hubs & also ignored below
$hubs = [
1200,
1300,
2560,
27084,
2545,
2353
];
// Intentionally ignored stations because they're IRLP
$ignore = array_merge($hubs, [
1001
]);
$buffer = '';
$stream = fopen(getAllMonUri(), "r");
while (!feof($stream)) {
$buffer .= stream_get_contents($stream, 1024);
if (preg_match("/event: nodes\ndata: (.*)\n\n/m", $buffer, $matches)) {
// echo $matches[1]."\n\n######################################\n\n";
parseStreamData($matches[1]);
$buffer = '';
}
}
echo "DIE!!!!\n";
exit;
/**
* @param $json
*/
function parseStreamData($json)
{
global $keyed;
$obj = json_decode($json);
foreach ($obj as $node => $v) {
foreach ($v->remote_nodes as $rn) {
$node = intval($rn->node);
if (isIgnored($node)) continue;
// Capture previous keyed values
$keyedNow = $rn->keyed === "yes";
$keyedBefore = isset($keyed[$node]);
// Set current key state. In PHP null !== isset
$keyed[$node] = $keyedNow ?: null;
if ($keyedBefore !== $keyedNow) {
// Permanently set to Allstar for now
// $nodePrefix = isIrlp($node) ? 'stn' : 'rpt';
$nodePrefix = 'rpt';
$keyedLabel = $keyedNow ? "KEY" : "UNKEY";
$time = Carbon::now();
$timeFormatted = $time->format("M d h:i:s");
// echo "{$node},{$keyedLabel},{$time}\n";
echo "{$timeFormatted} $nodePrefix{$node} {$keyedLabel} tx\n";
}
}
}
}
/**
* @param $node
* @return bool
*/
function isIgnored($node){
global $ignore;
return in_array($node, $ignore);
}
/**
* @return string
*/
function getAllMonUri()
{
global $hubs;
$hubsStr = implode(",", $hubs);
// return "https://allmon.winsystem.org/server.php?nodes=2353";
// return __DIR__ . '/test.stream';
return "https://allmon.winsystem.org/server.php?nodes=" . $hubsStr;
}

160
streamServer.php Normal file
View File

@ -0,0 +1,160 @@
<?php
require 'vendor/autoload.php';
use Carbon\Carbon;
/**
* Init class and let the constructor take care of the rest
*/
new Stream();
echo "DEAD!\n";
class Stream
{
/**
* Allstar Hubs & also ignored below
* @var array
*/
protected $hubs = [
1200,
1300,
2560,
2353,
// Offline 07-31-2020
// 27084,
2545,
];
/**
* Intentionally ignored stations because they're IRLP
* @var array
*/
protected $ignore = [
// 1001
];
/**
* Actively keyed up stations
* @var array
*/
protected $keyed = [];
/**
* @var string
*/
protected $buffer = '';
/**
* @var false|resource
*/
protected $stream;
/**
* @var string
*/
protected $streamOutput = __DIR__.'/storage/stream.txt';
/**
* Streamed constructor.
*/
public function __construct()
{
/**
* Merge together hubs and IRLP so we don't show them in the keyups
*
* Since we're reading a continuous stream from allmon, there's no need for sleep --
* loop and read the stream until it dies.
*
*/
$this->ignore = array_merge($this->hubs, $this->ignore);
$this->stream = fopen($this->getAllMonUri(), "r");
$this->streamLoop();
}
/**
* @return string
*/
public function getAllMonUri()
{
$hubsStr = implode(",", $this->hubs);
// return "https://allmon.winsystem.org/server.php?nodes=2353";
// return __DIR__ . '/test.stream';
return "https://allmon.winsystem.org/server.php?nodes=" . $hubsStr;
return "http://kk9rob/allmon2/server.php?nodes=52003";
}
/**
* Main event loop
*/
public function streamLoop() {
$buffer = '';
while (!feof($this->stream)) {
$buffer .= stream_get_line($this->stream, 2048, "\n\n");
if (false !== strpos($buffer, '}}')) {
$buffer .= "\n\n";
if (preg_match("/event: (.*?)\ndata: (.*)\n\n/m", $buffer, $matches)) {
$buffer = '';
if ($matches[1] !== "nodes") continue;
$this->parseStreamData($matches[2]);
}
}
}
// TODO: Failure condition for feof to restart stream, or let supervisor handle it?
}
/**
* @param $node
* @return bool
*/
protected function isIgnored($node)
{
return in_array($node, $this->ignore);
}
/**
* @param $json
*/
protected function parseStreamData($json)
{
// Debugging -- sometimes allmon doesn't send the proper keyup
// file_put_contents(__DIR__.'/storage/event_nodes.txt', "$json,\n", FILE_APPEND);
$obj = json_decode($json);
foreach ($obj as $node => $v) {
foreach ($v->remote_nodes as $remoteNode) {
$via = intval($node);
$node = intval($remoteNode->node);
if ($this->isIgnored($node)) continue;
// Capture previous keyed values
$keyedNow = $remoteNode->keyed === "yes";
$keyedBefore = isset($this->keyed[$node]);
// Set current key state. In PHP null !== isset
$this->keyed[$node] = $keyedNow ?: null;
if ($keyedBefore !== $keyedNow) {
if (filesize($this->streamOutput) >= 10240) {
file_put_contents($this->streamOutput, '');
}
// Permanently set to Allstar for now
// $nodePrefix = isIrlp($node) ? 'stn' : 'rpt';
$nodePrefix = 'rpt';
$keyedLabel = $keyedNow ? "KEY" : "UNKEY";
$time = Carbon::now();
$timeFormatted = $time->format("M d h:i:s");
// echo "{$node},{$keyedLabel},{$time}\n";
$toWrite = "{$timeFormatted} $nodePrefix{$node} {$keyedLabel} [via {$via}]\n";
file_put_contents($this->streamOutput, $toWrite, FILE_APPEND);
echo $toWrite;
}
}
}
}
}

View File

@ -1,10 +0,0 @@
Jul 30 18:23:23 rpt29600 tx [via 2353]
Jul 30 18:33:11 rpt45073 tx [via 2353]
Jul 30 18:33:24 rpt48697 tx [via 2560]
Jul 30 18:33:33 stn3543 92 packets
Jul 30 18:33:43 rpt28462 tx [via 2560]
Jul 30 18:33:51 rpt28462 tx [via 2560]
Jul 30 18:33:57 rpt28462 tx [via 2560]