/** VILLASnode WebMockup Javascript application. * * @author Steffen Vogel * @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC * @license GNU General Public License (version 3) * * VILLASnode * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . *********************************************************************************/ // global variables var api; var connection; var timer; var plot; var nodes = []; var currentNode; var paused = false; var sequence = 0; var plotData = []; var plotOptions = { xaxis: { mode: 'time' }, legend: { show: true }, selection: { mode: "x" } }; var updateRate = 25; var redrawPlot = true; var xDelta = 5000; var xPast = xDelta * 0.9; var xFuture = xDelta * 0.1; $(document).ready(function() { api = new Api('v1', apiConnected); $('#play').click(function(e, ui) { connection = wsConnect(currentNode); paused = false; }); $('#pause').click(function(e, ui) { connection.close(); paused = true; }); $('#timespan').slider({ min : 100, max : 10000, value : xDelta, slide : function(e, ui) { updatePlotWindow(ui.value); } }); $('#updaterate').slider({ min : 1, max : 100, value : updateRate, slide : function(e, ui) { clearInterval(timer); timer = setInterval(updatePlot, 1000.0 / updateRate); updateRate = ui.value; } }); $('.inputs #slider').slider({ min : 0, max : 10000, slide : sendData }); $('.inputs-checkboxes input').checkboxradio() .each(function(idx, elm) { $(elm).change(sendData); }); timer = setInterval(updatePlot, 1000.0 / updateRate); }); $(window).on('beforeunload', function() { connection.close(); api.close(); }); function sendData() { var slider = $('.inputs #slider'); var checkboxes = $('.inputs-checkboxes input'); var data = [ $(slider).slider('value') / 100, 0 ]; for (var i = 0; i < checkboxes.length; i++) data[1] += (checkboxes[i].checked ? 1 : 0) << i; var msg = new Msg({ timestamp : Date.now(), sequence : sequence++, data : data }); console.log('Sending message', msg); connection.send(msg.toArrayBuffer()); } function apiConnected() { api.request('nodes', {}, function(response) { nodes = response; console.log("Found " + nodes.length + " nodes:",); nodes.forEach(function(node) { console.log(node); if (node.type == 'websocket' && node.name == getParameterByName('node')) currentNode = node; }); if (currentNode === undefined) { nodes.forEach(function(node) { if (node.type == 'websocket') currentNode = node; }); } if (currentNode !== undefined) { updateNodeList(); connection = wsConnect(currentNode); } } ); } function updateNodeList() { $('.node-selector').empty(); nodes.forEach(function(node, index) { if (node.type == 'websocket') { $('.node-selector').append( $('