mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
fixed web socket JS
This commit is contained in:
parent
9f9407c3d3
commit
899e07aa9a
4 changed files with 39 additions and 44 deletions
|
@ -177,7 +177,7 @@ function wsConnect(url, protocol) {
|
|||
console.log('Received ' + msgs.length + ' messages with ' + msgs[0].data.length + ' values: ' + msgs[0].timestamp);
|
||||
|
||||
for (var j = 0; j < plotData.length; j++) {
|
||||
// remove old values
|
||||
// remove old
|
||||
while (plotData[j].length > 0 && plotData[j][0][0] < (Date.now() - xPast))
|
||||
plotData[j].shift()
|
||||
}
|
||||
|
@ -186,11 +186,11 @@ function wsConnect(url, protocol) {
|
|||
var msg = msgs[j];
|
||||
|
||||
// add empty arrays for data series
|
||||
while (plotData.length < msg.values)
|
||||
while (plotData.length < msg.length)
|
||||
plotData.push([]);
|
||||
|
||||
// add data to arrays
|
||||
for (var i = 0; i < msg.values; i++)
|
||||
for (var i = 0; i < msg.length; i++)
|
||||
plotData[i].push([msg.timestamp, msg.data[i]]);
|
||||
}
|
||||
};
|
||||
|
@ -240,7 +240,7 @@ function fileStart(e) {
|
|||
var data = [];
|
||||
|
||||
for (var i = 0; i < msgs.length; i++)
|
||||
data.push(msgs[i].ts + offset, msgs[i].values[0]);
|
||||
data.push(msgs[i].ts + offset, msgs[i].data[0]);
|
||||
|
||||
plotData.push(data);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>VILLASnode / WebSocket Mockup</title>
|
||||
<title>VILLASweb Mockup</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<link rel="stylesheet" href="jquery-ui/jquery-ui.theme.css" />
|
||||
<link rel="stylesheet" href="jquery-ui/jquery-ui.structure.css" />
|
||||
|
@ -18,7 +18,7 @@
|
|||
<div id="wrapper">
|
||||
<div id="header">
|
||||
<img class="logo" alt="EONERC" src="logo.svg" />
|
||||
<h1>VILLASnode / WebSocket Mockup</h1>
|
||||
<h1>VILLASweb Mockup</h1>
|
||||
</div>
|
||||
<div id="container">
|
||||
<ul class="node-selector"></ul>
|
||||
|
@ -76,7 +76,7 @@
|
|||
<div id="footer">
|
||||
<div class="left">
|
||||
<p>Copyright 2016: Institute for Automation of Complex Power Systems, </br>EON Energy Research Center, RWTH Aachen University, Germany</p>
|
||||
<p>Authors: <a href="mailto:mgrigul@eonerc.rwth-aachen.de">Markus Grigul</a>, <a href="mailto:stvogel@eonerc.rwth-aachen.de">Steffen Vogel</a></p>
|
||||
<p>Authors: <a href="mailto:stvogel@eonerc.rwth-aachen.de">Steffen Vogel</a>, <a href="mailto:mgrigul@eonerc.rwth-aachen.de">Markus Grigul</a></p>
|
||||
</div>
|
||||
<div class="right">
|
||||
<p><a style="font-size: 1.5em" href="/doc/index.html" style="float: right">Documentation</a></p>
|
||||
|
|
|
@ -12,6 +12,22 @@
|
|||
* @{
|
||||
**********************************************************************************/
|
||||
|
||||
/* Class for parsing and printing a message */
|
||||
function Msg(c, d)
|
||||
{
|
||||
this.sequence = typeof c.sequence === 'undefined' ? 0 : c.sequence;
|
||||
this.length = typeof c.length === 'undefined' ? 0 : c.length;
|
||||
this.endian = typeof c.endian === 'undefined' ? Msg.prototype.ENDIAN_LITTLE : c.endian;
|
||||
this.version = typeof c.version === 'undefined' ? Msg.prototype.VERSION : c.version;
|
||||
this.type = typeof c.type === 'undefined' ? Msg.prototype.TYPE_DATA : c.type;
|
||||
this.timestamp = typeof c.timestamp === 'undefined' ? Date.now() : c.timestamp;
|
||||
|
||||
if (Array.isArray(d)) {
|
||||
this.length = d.length;
|
||||
this.data = d
|
||||
}
|
||||
}
|
||||
|
||||
/* Some constants for the binary protocol */
|
||||
Msg.prototype.VERSION = 1;
|
||||
|
||||
|
@ -25,22 +41,6 @@ Msg.prototype.OFFSET_ENDIAN = 1;
|
|||
Msg.prototype.OFFSET_TYPE = 2;
|
||||
Msg.prototype.OFFSET_VERSION = 4;
|
||||
|
||||
/* Class for parsing and printing a message */
|
||||
function Msg(c, d)
|
||||
{
|
||||
this.sequence = c.sequence || 0;
|
||||
this.length = c.length || 0;
|
||||
this.endian = c.endian || Msg.ENDIAN_LITTLE;
|
||||
this.version = c.version || Msg.VERSION;
|
||||
this.type = c.type || Msg.TYPE_DATA;
|
||||
this.timestamp = c.timestamp || Date.now();
|
||||
|
||||
if (Array.isArray(d)) {
|
||||
this.length = d.length;
|
||||
this.data = d
|
||||
}
|
||||
}
|
||||
|
||||
Msg.bytes = function(len)
|
||||
{
|
||||
return len * 4 + 16;
|
||||
|
@ -49,12 +49,12 @@ Msg.bytes = function(len)
|
|||
Msg.fromArrayBuffer = function(data)
|
||||
{
|
||||
var bits = data.getUint8(0);
|
||||
var endian = (bits >> Msg.OFFSET_ENDIAN) & 0x1 ? 0 : 1;
|
||||
var endian = (bits >> Msg.prototype.OFFSET_ENDIAN) & 0x1 ? 0 : 1;
|
||||
|
||||
var msg = new Msg({
|
||||
endian: (bits >> Msg.OFFSET_ENDIAN) & 0x1,
|
||||
version: (bits >> Msg.OFFSET_VERSION) & 0xF,
|
||||
type: (bits >> Msg.OFFSET_TYPE) & 0x3,
|
||||
endian: (bits >> Msg.prototype.OFFSET_ENDIAN) & 0x1,
|
||||
version: (bits >> Msg.prototype.OFFSET_VERSION) & 0xF,
|
||||
type: (bits >> Msg.prototype.OFFSET_TYPE) & 0x3,
|
||||
length: data.getUint16(0x02, endian),
|
||||
sequence: data.getUint32(0x04, endian),
|
||||
timestamp: data.getUint32(0x08, endian) * 1e3 +
|
||||
|
@ -101,12 +101,12 @@ Msg.prototype.toArrayBuffer = function()
|
|||
view = new DataView(buffer);
|
||||
|
||||
var bits = 0;
|
||||
bits |= (this.endian & 0x1) << Msg.OFFSET_ENDIAN;
|
||||
bits |= (this.version & 0xF) << Msg.OFFSET_VERSION;
|
||||
bits |= (this.type & 0x3) << Msg.OFFSET_TYPE;
|
||||
bits |= (this.endian & 0x1) << Msg.prototype.OFFSET_ENDIAN;
|
||||
bits |= (this.version & 0xF) << Msg.prototype.OFFSET_VERSION;
|
||||
bits |= (this.type & 0x3) << Msg.prototype.OFFSET_TYPE;
|
||||
|
||||
var sec = Math.floor(this.timestamp / 1e3);
|
||||
var nsec = (this.timestamp - sec * 1e3) * 1e3;
|
||||
var nsec = (this.timestamp - sec * 1e3) * 1e6;
|
||||
|
||||
view.setUint8( 0x00, bits, true);
|
||||
view.setUint16(0x02, this.length, true);
|
||||
|
|
|
@ -24,18 +24,17 @@ nodes = {
|
|||
type = "websocket",
|
||||
unit = "MVa",
|
||||
units = [ "V", "A", "Var" ],
|
||||
description = "Das ist ein Test",
|
||||
description = "Demo Channel",
|
||||
#vectorize = 10,
|
||||
source = {
|
||||
simulator = "OP5600",
|
||||
location = "ACS lab"
|
||||
}
|
||||
}
|
||||
|
||||
ws_stats = {
|
||||
type = "websocket",
|
||||
description = "Statistics",
|
||||
@include "websocket-stats.conf" /* This adds a caption to the statistics plot */
|
||||
},
|
||||
series = (
|
||||
{ label = "Random walk" },
|
||||
{ label = "Sine" },
|
||||
{ label = "Rect" }
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -43,9 +42,5 @@ nodes = {
|
|||
############ List of paths ############
|
||||
|
||||
paths = (
|
||||
{
|
||||
in = "ws",
|
||||
out = "ws",
|
||||
# hook = [ "stats_send:ws_stats" ]
|
||||
}
|
||||
{ in = "ws", out = "ws" }
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue