|
|
@ -20,6 +20,7 @@ const dgwconfig = ini.parse(fs.readFileSync(inifile.config.dgwconfig, 'utf-8'));
|
|
|
|
const app = express();
|
|
|
|
const app = express();
|
|
|
|
const buf = new CircularBuffer(heardqueue);
|
|
|
|
const buf = new CircularBuffer(heardqueue);
|
|
|
|
const linklist = new CircularBuffer(linkqueue);
|
|
|
|
const linklist = new CircularBuffer(linkqueue);
|
|
|
|
|
|
|
|
var repeaterlist = [];
|
|
|
|
|
|
|
|
|
|
|
|
linklist.push({'timestamp':'0000-00-00 00:00:00' , 'protocol': 'none' , 'device':'none',
|
|
|
|
linklist.push({'timestamp':'0000-00-00 00:00:00' , 'protocol': 'none' , 'device':'none',
|
|
|
|
'repeater': 'none', 'reflector': 'none' , 'direction' : '' });
|
|
|
|
'repeater': 'none', 'reflector': 'none' , 'direction' : '' });
|
|
|
@ -47,28 +48,48 @@ app.use(express.static(path.resolve(__dirname, 'client')));
|
|
|
|
const io = socketio(server);
|
|
|
|
const io = socketio(server);
|
|
|
|
|
|
|
|
|
|
|
|
function senddata(dest,data,socket) {
|
|
|
|
function senddata(dest,data,socket) {
|
|
|
|
console.log("Enter Senddata -> " + dest);
|
|
|
|
//console.log("Enter Senddata -> " + dest);
|
|
|
|
socket.emit(dest,data);
|
|
|
|
socket.emit(dest,data);
|
|
|
|
// console.log(dest,JSON.stringify(data));
|
|
|
|
// console.log(dest,JSON.stringify(data));
|
|
|
|
console.log("Leave Senddata -> " + dest);
|
|
|
|
// console.log("Leave Senddata -> " + dest);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function buildrepeaters(){
|
|
|
|
|
|
|
|
repeaterlist = [];
|
|
|
|
|
|
|
|
for (i=1;i < 5;i++) {
|
|
|
|
|
|
|
|
let rptr = eval("dgwconfig.Repeater_"+i);
|
|
|
|
|
|
|
|
if (rptr.enabled) {
|
|
|
|
|
|
|
|
let callsign = dgwconfig.Gateway.callsign;
|
|
|
|
|
|
|
|
if (rptr.callsign !== ""){
|
|
|
|
|
|
|
|
callsign = rptr.callsign;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
callsign += " " + rptr.band;
|
|
|
|
|
|
|
|
repeaterlist.push({'callsign':callsign,'frequency':rptr.frequency,
|
|
|
|
|
|
|
|
'offset':rptr.offset,'type':rptr.type});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(JSON.stringify(repeaterlist));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function updatelinks() {
|
|
|
|
function updatelinks() {
|
|
|
|
console.log("Entering updatelinks");
|
|
|
|
// console.log("Entering updatelinks");
|
|
|
|
const linksregex = /(.*) (.*) (.*) - Type: (.*) Rptr: (.*) Refl: (.*) Dir: (.*)/;
|
|
|
|
const linksregex = /(.*) (.*) (.*) - Type: (.*) Rptr: (.*) Refl: (.*) Dir: (.*)/;
|
|
|
|
const linkfile = fs.readFileSync(links).toString();
|
|
|
|
const linkfile = fs.readFileSync(links).toString();
|
|
|
|
const lines = linkfile.split(/\n|\r\n/);
|
|
|
|
const lines = linkfile.split(/\n|\r\n/);
|
|
|
|
console.log("Queue Size in: " + linklist.size());
|
|
|
|
// console.log("Queue Size in: " + linklist.size());
|
|
|
|
while (linklist.size() > 0) {
|
|
|
|
while (linklist.size() > 0) {
|
|
|
|
linklist.deq();
|
|
|
|
linklist.deq();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
console.log("Queue Size out: " + linklist.size());
|
|
|
|
// console.log("Queue Size out: " + linklist.size());
|
|
|
|
console.log("File Length: " + lines.length);
|
|
|
|
// console.log("File Length: " + lines.length);
|
|
|
|
let i = 0;
|
|
|
|
let i = 0;
|
|
|
|
while (i < lines.length) {
|
|
|
|
while (i < lines.length) {
|
|
|
|
if(lines[i] != "") {
|
|
|
|
if(lines[i] != "") {
|
|
|
|
var mylinks = lines[i].match(linksregex);
|
|
|
|
var mylinks = lines[i].match(linksregex);
|
|
|
|
console.log(JSON.stringify(lines[i]));
|
|
|
|
// console.log(JSON.stringify(lines[i]));
|
|
|
|
var linkrec = {'timestamp':mylinks[1].substr(0,19) , 'protocol':mylinks[2] , 'device':mylinks[4],
|
|
|
|
var linkrec = {'timestamp':mylinks[1].substr(0,19) , 'protocol':mylinks[2] , 'device':mylinks[4],
|
|
|
|
'repeater':mylinks[5] , 'reflector':mylinks[6] , 'direction' : mylinks[7] };
|
|
|
|
'repeater':mylinks[5] , 'reflector':mylinks[6] , 'direction' : mylinks[7] };
|
|
|
|
linklist.push(linkrec);
|
|
|
|
linklist.push(linkrec);
|
|
|
@ -77,17 +98,19 @@ function updatelinks() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// console.log("From updatelinks() " + JSON.stringify(linklist.toarray()));
|
|
|
|
// console.log("From updatelinks() " + JSON.stringify(linklist.toarray()));
|
|
|
|
// senddata("links",linklist.toarray(),io);
|
|
|
|
// senddata("links",linklist.toarray(),io);
|
|
|
|
console.log("Leaving updatelinks");
|
|
|
|
// console.log("Leaving updatelinks");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.on('connection', (socket) => {
|
|
|
|
io.on('connection', (socket) => {
|
|
|
|
console.log('WS New connection');
|
|
|
|
// console.log('WS New connection');
|
|
|
|
|
|
|
|
buildrepeaters();
|
|
|
|
senddata("lastheard",buf.toarray(),socket);
|
|
|
|
senddata("lastheard",buf.toarray(),socket);
|
|
|
|
senddata("links",linklist.toarray(),socket);
|
|
|
|
senddata("links",linklist.toarray(),socket);
|
|
|
|
senddata("title",host + " Dashboard",socket);
|
|
|
|
senddata("title",host + " Dashboard",socket);
|
|
|
|
console.log("leaving connection");
|
|
|
|
senddata("repeaters",repeaterlist,socket);
|
|
|
|
|
|
|
|
// console.log("leaving connection");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// io.on('message', (socket) => {
|
|
|
|
// io.on('message', (socket) => {
|
|
|
@ -95,18 +118,18 @@ io.on('connection', (socket) => {
|
|
|
|
//});
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
fs.watch(headers, (curr, prev)=>{
|
|
|
|
fs.watch(headers, (curr, prev)=>{
|
|
|
|
console.log(headers + ' file changed');
|
|
|
|
// console.log(headers + ' file changed');
|
|
|
|
// console.log("from fs.watch headers " + JSON.stringify(buf.toarray()));
|
|
|
|
// console.log("from fs.watch headers " + JSON.stringify(buf.toarray()));
|
|
|
|
senddata("lastheard",buf.toarray(),io);
|
|
|
|
senddata("lastheard",buf.toarray(),io);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fs.watch(links, (curr, prev)=>{
|
|
|
|
fs.watch(links, (curr, prev)=>{
|
|
|
|
console.log(links + ' file changed');
|
|
|
|
// console.log(links + ' file changed');
|
|
|
|
// console.log("from fs.watch links " + JSON.stringify(linklist.toarray()));
|
|
|
|
// console.log("from fs.watch links " + JSON.stringify(linklist.toarray()));
|
|
|
|
updatelinks();
|
|
|
|
updatelinks();
|
|
|
|
// console.log("from fs.watch links " + JSON.stringify(linklist.toarray()));
|
|
|
|
// console.log("from fs.watch links " + JSON.stringify(linklist.toarray()));
|
|
|
|
senddata("links",linklist.toarray(),io);
|
|
|
|
senddata("links",linklist.toarray(),io);
|
|
|
|
console.log("Leaving links watch");
|
|
|
|
// console.log("Leaving links watch");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const tailheaders = new Tail(headers, {startPos : 'end'}, line => {
|
|
|
|
const tailheaders = new Tail(headers, {startPos : 'end'}, line => {
|
|
|
|