mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
implement signal auto config functionality based on response from VILLASnode API (to be tested) #224
This commit is contained in:
parent
693eaed8d6
commit
cc156d751b
3 changed files with 135 additions and 12 deletions
|
@ -410,14 +410,18 @@ class Scenario extends React.Component {
|
|||
return;
|
||||
}
|
||||
|
||||
let splitHost = ic.host.split("/")
|
||||
let request = {};
|
||||
request["id"] = this.uuidv4();
|
||||
request["action"] = "config"
|
||||
request["action"] = "nodes"
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'signals/start-autoconfig',
|
||||
data: request,
|
||||
url: ic.apihost
|
||||
url: ic.apihost,
|
||||
socketname: splitHost[splitHost.length -1],
|
||||
token: this.state.sessionToken,
|
||||
configID: componentConfig.id
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -34,19 +34,13 @@ class SignalStore extends ArrayStore{
|
|||
return super.reduce(state, action);
|
||||
|
||||
case 'signals/start-autoconfig':
|
||||
this.dataManager.startAutoConfig(action.data, action.url)
|
||||
this.dataManager.startAutoConfig(action.data, action.url, action.socketname, action.token, action.configID)
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'signals/autoconfig-loaded':
|
||||
console.log("AutoConfig Loaded: ", action.data)
|
||||
// TODO save signal config contained in action.data
|
||||
|
||||
const SIGNAL_AUTOCONF_INFO_NOTIFICATION = {
|
||||
title: 'Signal configuration loaded successfully.',
|
||||
message: '',
|
||||
level: 'info'
|
||||
};
|
||||
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_INFO_NOTIFICATION);
|
||||
this.dataManager.saveSignals(action.data, action.token, action.configID, action.socketname);
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
import RestDataManager from '../common/data-managers/rest-data-manager';
|
||||
import RestAPI from "../common/api/rest-api";
|
||||
import AppDispatcher from "../common/app-dispatcher";
|
||||
import NotificationsDataManager from "../common/data-managers/notifications-data-manager";
|
||||
|
||||
class SignalsDataManager extends RestDataManager{
|
||||
|
||||
|
@ -36,7 +37,7 @@ class SignalsDataManager extends RestDataManager{
|
|||
|
||||
}
|
||||
|
||||
startAutoConfig(data, url){
|
||||
startAutoConfig(data, url, socketname, token, configID){
|
||||
// This function queries the VILLASnode API to obtain the configuration of the VILLASnode located at url
|
||||
// Endpoint: http[s]://server:port/api/v1 (to be generated based on IC host, port 4000)
|
||||
// data contains the request data: { action, id, (request)}
|
||||
|
@ -45,7 +46,10 @@ class SignalsDataManager extends RestDataManager{
|
|||
RestAPI.post(url, data).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'signals/autoconfig-loaded',
|
||||
data: response
|
||||
data: response,
|
||||
token: token,
|
||||
socketname: socketname,
|
||||
configID: configID
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
|
@ -55,6 +59,127 @@ class SignalsDataManager extends RestDataManager{
|
|||
})
|
||||
}
|
||||
|
||||
saveSignals(data, token, configID, socketname){
|
||||
// data.response contains the response from the VILLASnode API, an array of node configurations
|
||||
|
||||
if(!data.hasOwnProperty("response")){
|
||||
const SIGNAL_AUTOCONF_ERROR_NOTIFICATION = {
|
||||
title: 'Failed to load signal config ',
|
||||
message: 'VILLASnode returned no response field.',
|
||||
level: 'error'
|
||||
};
|
||||
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_ERROR_NOTIFICATION);
|
||||
return;
|
||||
}
|
||||
|
||||
let configured = false;
|
||||
let error = false;
|
||||
for(let nodeConfig of data.response){
|
||||
if(!nodeConfig.hasOwnProperty("name")){
|
||||
console.warn("Could not parse the following node config because it lacks a name parameter:", nodeConfig);
|
||||
} else if(nodeConfig.name === socketname){
|
||||
if(configured){
|
||||
const SIGNAL_AUTOCONF_WARNING_NOTIFICATION = {
|
||||
title: 'There might be a problem with the signal auto-config',
|
||||
message: 'VILLASnode returned multiple node configurations for the websocket ' + socketname + '. This is a problem of the VILLASnode.',
|
||||
level: 'warning'
|
||||
};
|
||||
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_WARNING_NOTIFICATION);
|
||||
continue;
|
||||
}
|
||||
// signals are not yet configured:
|
||||
console.log("Adding signals of websocket: ", nodeConfig);
|
||||
let index_in = 1
|
||||
let index_out = 1
|
||||
|
||||
if(!nodeConfig.in.hasOwnProperty("signals")){
|
||||
const SIGNAL_AUTOCONF_ERROR_NOTIFICATION = {
|
||||
title: 'Failed to load in signal config ',
|
||||
message: 'No field for in signals contained in response.',
|
||||
level: 'error'
|
||||
};
|
||||
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_ERROR_NOTIFICATION);
|
||||
error = true;
|
||||
} else{
|
||||
|
||||
// add all in signals
|
||||
for(let inSig of nodeConfig.in.signals) {
|
||||
console.log("adding input signal:", inSig);
|
||||
|
||||
if (inSig.enabled) {
|
||||
let newSignal = {
|
||||
configID: configID,
|
||||
direction: 'in',
|
||||
name: inSig.hasOwnProperty("name") ? inSig.name : "in_" + String(index_in),
|
||||
unit: inSig.hasOwnProperty("unit") ? inSig.unit : '-',
|
||||
index: index_in,
|
||||
scalingFactor: 1.0
|
||||
};
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'signals/start-add',
|
||||
data: newSignal,
|
||||
token: token
|
||||
});
|
||||
|
||||
index_in++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!nodeConfig.out.hasOwnProperty("signals")){
|
||||
const SIGNAL_AUTOCONF_ERROR_NOTIFICATION = {
|
||||
title: 'Failed to load out signal config ',
|
||||
message: 'No field for out signals contained in response.',
|
||||
level: 'error'
|
||||
};
|
||||
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_ERROR_NOTIFICATION);
|
||||
error=true;
|
||||
}else {
|
||||
|
||||
// add all out signals
|
||||
|
||||
for (let outSig of nodeConfig.out.signals) {
|
||||
console.log("adding output signal:", outSig);
|
||||
|
||||
if (outSig.enabled) {
|
||||
let newSignal = {
|
||||
configID: configID,
|
||||
direction: 'out',
|
||||
name: outSig.hasOwnProperty("name") ? outSig.name : "out_" + String(index_out),
|
||||
unit: outSig.hasOwnProperty("unit") ? outSig.unit : '-',
|
||||
index: index_out,
|
||||
scalingFactor: 1.0
|
||||
};
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'signals/start-add',
|
||||
data: newSignal,
|
||||
token: token
|
||||
});
|
||||
|
||||
index_out++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Configured", index_in-1, "input signals and", index_out-1, "output signals");
|
||||
configured=true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!error) {
|
||||
const SIGNAL_AUTOCONF_INFO_NOTIFICATION = {
|
||||
title: 'Signal configuration loaded successfully.',
|
||||
message: '',
|
||||
level: 'info'
|
||||
};
|
||||
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_INFO_NOTIFICATION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default new SignalsDataManager()
|
||||
|
|
Loading…
Add table
Reference in a new issue