blah2/api/server.js

158 lines
3.6 KiB
JavaScript
Raw Normal View History

2023-05-04 11:25:37 +00:00
const express = require('express');
const dgram = require('dgram');
const net = require("net");
2023-05-04 11:25:37 +00:00
2023-12-17 03:47:40 +00:00
var data_map = require('./stash/maxhold.js');
var data_detection = require('./stash/detection.js');
var data_iqdata = require('./stash/iqdata.js');
var data_timing = require('./stash/timing.js');
2023-05-04 11:25:37 +00:00
// constants
const PORT = 3000;
const HOST = '0.0.0.0';
var map = '';
var detection = '';
var timestamp = '';
2023-11-20 12:35:01 +00:00
var timing = '';
2023-12-11 12:11:54 +00:00
var iqdata = '';
2023-05-04 11:25:37 +00:00
var data = '';
var capture = false;
// api server
const app = express();
// header on all requests
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
2023-10-27 05:53:42 +00:00
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
2023-05-04 11:25:37 +00:00
next();
});
app.get('/', (req, res) => {
res.send('Hello World');
});
app.get('/api/map', (req, res) => {
2023-05-04 11:25:37 +00:00
res.send(map);
});
app.get('/api/detection', (req, res) => {
res.send(detection);
});
app.get('/api/timestamp', (req, res) => {
res.send(timestamp);
});
app.get('/api/timing', (req, res) => {
2023-11-20 12:35:01 +00:00
res.send(timing);
});
2023-12-11 12:11:54 +00:00
app.get('/api/iqdata', (req, res) => {
res.send(iqdata);
});
2023-12-12 14:40:52 +00:00
// stash API
app.get('/stash/map', (req, res) => {
res.send(data_map.get_data_map());
});
app.get('/stash/detection', (req, res) => {
res.send(data_detection.get_data_detection());
});
2023-12-12 14:40:52 +00:00
app.get('/stash/iqdata', (req, res) => {
res.send(data_iqdata.get_data_iqdata());
});
2023-12-17 03:47:40 +00:00
app.get('/stash/timing', (req, res) => {
res.send(data_timing.get_data_timing());
});
2023-12-12 14:40:52 +00:00
2023-05-04 11:25:37 +00:00
// read state of capture
app.get('/capture', (req, res) => {
res.send(capture);
});
// toggle state of capture
app.get('/capture/toggle', (req, res) => {
capture = !capture;
res.send('{}');
});
app.listen(PORT, HOST, () => {
console.log(`Running on http://${HOST}:${PORT}`);
});
// tcp listener map
const server_map = net.createServer((socket)=>{
2023-05-04 11:25:37 +00:00
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data = data + msg.toString();
if (data.slice(-1) === "}")
{
map = data;
data = '';
}
});
socket.on("close",()=>{
console.log("Connection closed.");
})
});
server_map.listen(3001);
// tcp listener detection
const server_detection = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data = data + msg.toString();
if (data.slice(-1) === "}")
{
detection = data;
data = '';
}
});
socket.on("close",()=>{
console.log("Connection closed.");
})
});
server_detection.listen(3002);
// tcp listener timestamp
const server_timestamp = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data = data + msg.toString();
timestamp = data;
data = '';
});
socket.on("close",()=>{
console.log("Connection closed.");
})
});
server_timestamp.listen(4000);
2023-11-20 12:35:01 +00:00
// tcp listener timing
const server_timing = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data = data + msg.toString();
if (data.slice(-1) === "}")
{
timing = data;
data = '';
}
});
socket.on("close",()=>{
console.log("Connection closed.");
})
});
server_timing.listen(4001);
2023-12-11 12:11:54 +00:00
// tcp listener iqdata metadata
const server_iqdata = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data = data + msg.toString();
if (data.slice(-1) === "}")
{
iqdata = data;
data = '';
}
});
socket.on("close",()=>{
console.log("Connection closed.");
})
});
server_iqdata.listen(4002);