version 2025-01-21; offline node status, do not turn lines on startup if not needed
This commit is contained in:
parent
4c59ccd095
commit
73a2620add
3 changed files with 164 additions and 251 deletions
|
|
@ -275,9 +275,6 @@ exports.install = function(instance) {
|
||||||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
let params = getParams(PRIORITY_TYPES.node_cmd);
|
||||||
params.type = "set_node_profile";
|
params.type = "set_node_profile";
|
||||||
params.address = node;
|
params.address = node;
|
||||||
params.byte1 = 0;
|
|
||||||
params.byte2 = 0;
|
|
||||||
params.byte3 = 0;
|
|
||||||
params.byte4 = 96;
|
params.byte4 = 96;
|
||||||
params.recipient = 1;
|
params.recipient = 1;
|
||||||
params.register = 8;
|
params.register = 8;
|
||||||
|
|
@ -297,9 +294,6 @@ exports.install = function(instance) {
|
||||||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
let params = getParams(PRIORITY_TYPES.node_cmd);
|
||||||
params.type = "set_node_profile";
|
params.type = "set_node_profile";
|
||||||
params.address = node;
|
params.address = node;
|
||||||
params.byte1 = 0;
|
|
||||||
params.byte2 = 0;
|
|
||||||
params.byte3 = 0;
|
|
||||||
params.byte4 = 96;
|
params.byte4 = 96;
|
||||||
params.recipient = 1;
|
params.recipient = 1;
|
||||||
params.register = 8;
|
params.register = 8;
|
||||||
|
|
@ -345,8 +339,6 @@ exports.install = function(instance) {
|
||||||
params.address = node;
|
params.address = node;
|
||||||
params.byte1 = parseInt(t[0]);//hh
|
params.byte1 = parseInt(t[0]);//hh
|
||||||
params.byte2 = parseInt(t[1]);//mm
|
params.byte2 = parseInt(t[1]);//mm
|
||||||
params.byte3 = 0;//ss
|
|
||||||
params.byte4 = 0;//
|
|
||||||
params.recipient = 1;
|
params.recipient = 1;
|
||||||
params.register = register;
|
params.register = register;
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
@ -362,9 +354,6 @@ exports.install = function(instance) {
|
||||||
params = getParams(PRIORITY_TYPES.node_cmd);
|
params = getParams(PRIORITY_TYPES.node_cmd);
|
||||||
params.type = "set_node_profile";
|
params.type = "set_node_profile";
|
||||||
params.address = node;
|
params.address = node;
|
||||||
params.byte1 = 0;
|
|
||||||
params.byte2 = 0;
|
|
||||||
params.byte3 = 0;//ss
|
|
||||||
params.byte4 = parseInt(dim_value) + 128;//
|
params.byte4 = parseInt(dim_value) + 128;//
|
||||||
params.recipient = 1;
|
params.recipient = 1;
|
||||||
params.register = register;
|
params.register = register;
|
||||||
|
|
@ -653,28 +642,18 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
logger.debug("--->reportOnlineNodeStatus for line", line);
|
logger.debug("--->reportOnlineNodeStatus for line", line);
|
||||||
|
|
||||||
|
const d = new Date();
|
||||||
|
|
||||||
//run broadcast //Actual time
|
//run broadcast //Actual time
|
||||||
let params = {};
|
let params = getParams();
|
||||||
|
|
||||||
var d = new Date();
|
|
||||||
let hours = d.getHours();
|
|
||||||
let minutes = d.getMinutes();
|
|
||||||
let seconds = d.getSeconds();
|
|
||||||
|
|
||||||
let time = d.getTime(); // time in ms
|
|
||||||
|
|
||||||
params.address = 0xffffffff;//Broadcast
|
params.address = 0xffffffff;//Broadcast
|
||||||
params.byte1 = hours;//h
|
params.byte1 = d.getHours();
|
||||||
params.byte2 = minutes;//m
|
params.byte2 = d.getMinutes();
|
||||||
params.byte3 = seconds;//s
|
|
||||||
params.byte4 = 0;
|
|
||||||
params.recipient = 2;//2 broadcast, address = 0
|
params.recipient = 2;//2 broadcast, address = 0
|
||||||
params.register = 87;//Actual time
|
params.register = 87;//Actual time
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
//other values
|
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = d.getTime() + 30000;
|
||||||
params.addMinutesToTimestamp = 0;
|
params.addMinutesToTimestamp = 0;
|
||||||
params.info = "run broadcast: Actual time";
|
params.info = "run broadcast: Actual time";
|
||||||
|
|
||||||
|
|
@ -684,42 +663,31 @@ exports.install = function(instance) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
//Po zapnutí línie - spraviť hromadný refresh stavu práve zapnutých svietidiel
|
//Po zapnutí línie - spraviť hromadný refresh stavu práve zapnutých svietidiel
|
||||||
|
|
||||||
|
let time = Date.now();
|
||||||
|
|
||||||
for (let k in nodesData) {
|
for (let k in nodesData) {
|
||||||
|
|
||||||
//potrebujem nody k danej linii
|
//potrebujem nody k danej linii
|
||||||
if (line == nodesData[k].line || line == undefined) {
|
if (line == nodesData[k].line || line == undefined) {
|
||||||
|
|
||||||
let tbname = nodesData[k].tbname;
|
let tbname = nodesData[k].tbname;
|
||||||
let node = nodesData[k].node;
|
let node = nodesData[k].node;
|
||||||
let status = "NOK";
|
let status = "NOK";
|
||||||
|
|
||||||
// if status of node was "OK" before switching it off, we set the node's time_of_last_communication on time, it was switched on again and send OK status to tb.
|
// if status of node was "OK" before switching it off, we set the node's time_of_last_communication on time, it was switched on again and send OK status to tb.
|
||||||
if (nodesData[k].status) {
|
if (nodesData[k].node_status_before_offline == true || nodesData[k].status === true) {
|
||||||
status = "OK";
|
status = "OK";
|
||||||
nodesData[k].time_of_last_communication = time;
|
nodesData[k].time_of_last_communication = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateNodeStatus(k, status === "OK" ? true : false);
|
||||||
|
if (nodesData[k].hasOwnProperty("node_status_before_offline")) delete nodesData[k].node_status_before_offline;
|
||||||
sendTelemetry({ status: status }, tbname, time);
|
sendTelemetry({ status: status }, tbname, time);
|
||||||
|
|
||||||
//vyreportovanie dimmingu, prud, vykon - current, input power pre liniu pre vsetky nody
|
//vyreportovanie dimming, current, input power pre liniu pre vsetky nody
|
||||||
|
//Prud
|
||||||
{
|
{
|
||||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
let params = getParams();
|
||||||
|
|
||||||
params.type = "cmd";
|
|
||||||
params.tbname = tbname;
|
|
||||||
params.address = node;
|
|
||||||
params.register = 1;//dimming
|
|
||||||
params.recipient = 1;//slave
|
|
||||||
params.rw = 0;//read
|
|
||||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
|
||||||
params.info = 'read dimming';
|
|
||||||
//params.debug = true;
|
|
||||||
|
|
||||||
tasks.push(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Prúd
|
|
||||||
{
|
|
||||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
|
||||||
|
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
params.tbname = tbname;
|
params.tbname = tbname;
|
||||||
|
|
@ -727,16 +695,16 @@ exports.install = function(instance) {
|
||||||
params.register = 75;//prud
|
params.register = 75;//prud
|
||||||
params.recipient = 1;//slave
|
params.recipient = 1;//slave
|
||||||
params.rw = 0;//read
|
params.rw = 0;//read
|
||||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
params.timestamp = time + 3000;
|
||||||
params.info = 'read current';
|
params.info = 'read current';
|
||||||
//params.debug = true;
|
//params.debug = true;
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
//výkon
|
//vykon
|
||||||
{
|
{
|
||||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
let params = getParams();
|
||||||
|
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
params.tbname = tbname;
|
params.tbname = tbname;
|
||||||
|
|
@ -744,14 +712,32 @@ exports.install = function(instance) {
|
||||||
params.register = 76;//výkon
|
params.register = 76;//výkon
|
||||||
params.recipient = 1;//slave
|
params.recipient = 1;//slave
|
||||||
params.rw = 0;//read
|
params.rw = 0;//read
|
||||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
params.timestamp = time + 3100;
|
||||||
params.info = 'read power';
|
params.info = 'read power';
|
||||||
//params.debug = true;
|
//params.debug = true;
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
}
|
}
|
||||||
|
//dimming
|
||||||
|
{
|
||||||
|
let params = getParams();
|
||||||
|
|
||||||
|
params.type = "cmd";
|
||||||
|
params.tbname = tbname;
|
||||||
|
params.address = node;
|
||||||
|
params.register = 1;//dimming
|
||||||
|
params.recipient = 1;//slave
|
||||||
|
params.rw = 0;//read
|
||||||
|
params.timestamp = time + 3200;
|
||||||
|
params.info = 'read dimming';
|
||||||
|
//params.debug = true;
|
||||||
|
|
||||||
|
tasks.push(params);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}, sec * 1000);
|
}, sec * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -775,17 +761,12 @@ exports.install = function(instance) {
|
||||||
if (line == nodesData[node].line || line == undefined) {
|
if (line == nodesData[node].line || line == undefined) {
|
||||||
|
|
||||||
let tbname = nodesData[node].tbname;
|
let tbname = nodesData[node].tbname;
|
||||||
const dataToTb = {
|
let nodeStatus = nodesData[node].status;
|
||||||
[tbname]: [
|
|
||||||
{
|
|
||||||
"ts": date,
|
|
||||||
"values": values
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
//NOTE: we can not use sendTelemetry function, as it modifies input data (values object)
|
nodesData[node].node_status_before_offline = nodeStatus === true ? true : false;
|
||||||
instance.send(SEND_TO.tb, dataToTb);
|
nodesData[node].status = "OFFLINE";
|
||||||
|
|
||||||
|
sendTelemetry({ ...values }, tbname, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, (index + 1) * 300);
|
}, (index + 1) * 300);
|
||||||
|
|
@ -801,7 +782,7 @@ exports.install = function(instance) {
|
||||||
info: info
|
info: info
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.debug("linia", line, obj);
|
//logger.debug("linia", line, obj);
|
||||||
instance.send(SEND_TO.dido_controller, obj);
|
instance.send(SEND_TO.dido_controller, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -884,14 +865,16 @@ exports.install = function(instance) {
|
||||||
processLine = params.line;
|
processLine = params.line;
|
||||||
}
|
}
|
||||||
|
|
||||||
//load profiles pre vsetky linie:
|
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
|
|
||||||
if (processLineProfiles) {
|
|
||||||
//process line profiles
|
//process line profiles
|
||||||
|
if (processLineProfiles) {
|
||||||
|
|
||||||
let keys = Object.keys(relaysData);
|
let keys = Object.keys(relaysData);
|
||||||
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
let line = parseInt(keys[i]); //line is turned off by default
|
|
||||||
|
let line = parseInt(keys[i]);
|
||||||
let profilestr = relaysData[line].profile;
|
let profilestr = relaysData[line].profile;
|
||||||
|
|
||||||
if (processLine != undefined) {
|
if (processLine != undefined) {
|
||||||
|
|
@ -994,13 +977,12 @@ exports.install = function(instance) {
|
||||||
start_time.setDate(start_time.getDate() + 1);
|
start_time.setDate(start_time.getDate() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let params = getParams(PRIORITY_TYPES.relay_profile);
|
let params = getParams();
|
||||||
params.type = "relay";
|
params.type = "relay";
|
||||||
params.line = parseInt(line);
|
params.line = parseInt(line);
|
||||||
params.value = time_points[t].value;
|
params.value = time_points[t].value;
|
||||||
params.tbname = relaysData[line].tbname;
|
params.tbname = relaysData[line].tbname;
|
||||||
params.timestamp = start_time.getTime();
|
params.timestamp = start_time.getTime();
|
||||||
|
|
||||||
params.addMinutesToTimestamp = 0;
|
params.addMinutesToTimestamp = 0;
|
||||||
|
|
||||||
// it timepoints are not calculated (dawn, dusk, lux_timepoint), but static points in line profile, we just repeat the task every day
|
// it timepoints are not calculated (dawn, dusk, lux_timepoint), but static points in line profile, we just repeat the task every day
|
||||||
|
|
@ -1028,13 +1010,13 @@ exports.install = function(instance) {
|
||||||
monitor.info("-->time_points final", line, time_points);
|
monitor.info("-->time_points final", line, time_points);
|
||||||
|
|
||||||
//ensure to turn on/off according to calculated currentValue
|
//ensure to turn on/off according to calculated currentValue
|
||||||
let params = getParams(PRIORITY_TYPES.terminal);
|
let params = getParams();
|
||||||
params.type = "relay";
|
params.type = "relay";
|
||||||
params.line = parseInt(line);
|
params.line = parseInt(line);
|
||||||
params.tbname = relaysData[line].tbname;
|
params.tbname = relaysData[line].tbname;
|
||||||
params.value = currentValue;
|
params.value = currentValue;
|
||||||
|
|
||||||
params.timestamp = PRIORITY_TYPES.terminal;
|
params.timestamp = i;
|
||||||
params.addMinutesToTimestamp = 0;
|
params.addMinutesToTimestamp = 0;
|
||||||
params.debug = true;
|
params.debug = true;
|
||||||
|
|
||||||
|
|
@ -1050,12 +1032,14 @@ exports.install = function(instance) {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (profilestr !== "") {
|
if (profilestr !== "") {
|
||||||
//errLogger.error(profilestr, error);
|
//errLogger.error(profilestr, error);
|
||||||
|
console.log(`Cmd_manager: Unable to process line profile ${line}. Error: `, error);
|
||||||
errorHandler.sendMessageToService(profilestr + "-" + error, 0, "js_error");
|
errorHandler.sendMessageToService(profilestr + "-" + error, 0, "js_error");
|
||||||
|
} else {
|
||||||
|
turnLine("off", line, "No line profile. Switching it off on startup");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//logger.debug("tasks:");
|
//logger.debug("tasks:");
|
||||||
//logger.debug(tasks);
|
//logger.debug(tasks);
|
||||||
}
|
}
|
||||||
|
|
@ -1065,60 +1049,44 @@ exports.install = function(instance) {
|
||||||
//Time of dusk, Time of dawn, Actual Time
|
//Time of dusk, Time of dawn, Actual Time
|
||||||
|
|
||||||
if (processBroadcast) {
|
if (processBroadcast) {
|
||||||
let addMinutesToTimestamp = 5;
|
|
||||||
|
let d = new Date();
|
||||||
|
let time = d.getTime();
|
||||||
|
let sunCalcResult = calculateDuskDawn();
|
||||||
|
|
||||||
{
|
{
|
||||||
//run broadcast Time of dusk
|
//run broadcast Time of dusk
|
||||||
addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dusk
|
let params = getParams();
|
||||||
|
|
||||||
let params = getParams(PRIORITY_TYPES.node_broadcast);
|
|
||||||
|
|
||||||
let sunCalcResult = calculateDuskDawn();
|
|
||||||
let dusk_hours = sunCalcResult["dusk_hours"];
|
|
||||||
let dusk_minutes = sunCalcResult["dusk_minutes"];
|
|
||||||
|
|
||||||
params.address = 0xffffffff;//broadcast
|
params.address = 0xffffffff;//broadcast
|
||||||
params.byte1 = dusk_hours;//h
|
params.byte1 = sunCalcResult["dusk_hours"];
|
||||||
params.byte2 = dusk_minutes;//m
|
params.byte2 = sunCalcResult["dusk_minutes"];
|
||||||
params.byte3 = 0;//s
|
|
||||||
params.byte4 = 0;
|
|
||||||
params.recipient = 2;//2 broadcast,
|
params.recipient = 2;//2 broadcast,
|
||||||
params.register = 6;//Time of dusk - Reg 6
|
params.register = 6;//Time of dusk - Reg 6
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
//other values
|
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = time + 60000;
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dusk
|
||||||
params.info = "Broadcast-duskTime";
|
params.info = "Broadcast-duskTime";
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
//run broadcast Time of dawn
|
//run broadcast Time of dawn
|
||||||
addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dawn
|
let params = getParams();
|
||||||
|
|
||||||
let params = getParams(PRIORITY_TYPES.node_broadcast);
|
|
||||||
|
|
||||||
let sunCalcResult = calculateDuskDawn();
|
|
||||||
let dawn_hours = sunCalcResult["dawn_hours"];
|
|
||||||
let dawn_minutes = sunCalcResult["dawn_minutes"];
|
|
||||||
|
|
||||||
params.address = 0xffffffff;//broadcast
|
params.address = 0xffffffff;//broadcast
|
||||||
params.byte1 = dawn_hours;//h
|
params.byte1 = sunCalcResult["dawn_hours"];
|
||||||
params.byte2 = dawn_minutes;//m
|
params.byte2 = sunCalcResult["dawn_minutes"];
|
||||||
params.byte3 = 0;//s
|
|
||||||
params.byte4 = 0;
|
|
||||||
params.recipient = 2; //2 broadcast
|
params.recipient = 2; //2 broadcast
|
||||||
params.register = 7;//Time of dawn - Reg 6
|
params.register = 7;//Time of dawn - Reg 6
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
//other values
|
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = time + 60001;
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dawn
|
||||||
params.info = "Broadcast-dawnTime";
|
params.info = "Broadcast-dawnTime";
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
|
|
@ -1126,28 +1094,18 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
{
|
{
|
||||||
//run broadcast Actual time
|
//run broadcast Actual time
|
||||||
addMinutesToTimestamp = 5;
|
let params = getParams();
|
||||||
|
|
||||||
let params = getParams(PRIORITY_TYPES.node_broadcast);
|
|
||||||
|
|
||||||
var d = new Date();
|
|
||||||
let hours = d.getHours();
|
|
||||||
let minutes = d.getMinutes();
|
|
||||||
let seconds = d.getSeconds();
|
|
||||||
|
|
||||||
params.address = 0xffffffff;//broadcast
|
params.address = 0xffffffff;//broadcast
|
||||||
params.byte1 = hours;//h
|
params.byte1 = d.getHours();
|
||||||
params.byte2 = minutes;//m
|
params.byte2 = d.getMinutes();
|
||||||
params.byte3 = seconds;//s
|
|
||||||
params.byte4 = 0;
|
|
||||||
params.recipient = 2; //2 broadcast
|
params.recipient = 2; //2 broadcast
|
||||||
params.register = 87;//Actual time
|
params.register = 87;//Actual time
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
//other values
|
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = time + 60002;
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = 5;
|
||||||
params.info = "run broadcast: Actual time";
|
params.info = "run broadcast: Actual time";
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
|
|
@ -1158,6 +1116,9 @@ exports.install = function(instance) {
|
||||||
//process nodes & tasks
|
//process nodes & tasks
|
||||||
//reportovanie pre platformu
|
//reportovanie pre platformu
|
||||||
if (processNodes) {
|
if (processNodes) {
|
||||||
|
|
||||||
|
let time = Date.now();
|
||||||
|
|
||||||
for (let k in nodesData) {
|
for (let k in nodesData) {
|
||||||
let address = parseInt(k);
|
let address = parseInt(k);
|
||||||
let tbname = nodesData[k].tbname;
|
let tbname = nodesData[k].tbname;
|
||||||
|
|
@ -1167,37 +1128,24 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//listOfCommands - READ
|
//listOfCommands - READ
|
||||||
for (let i = 0; i < listOfCommands.length; i++) {
|
for (let i = 0; i < listOfCommands.length; i++) {
|
||||||
|
|
||||||
register = listOfCommands[i];
|
register = listOfCommands[i];
|
||||||
|
|
||||||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
|
||||||
|
|
||||||
//core rpc values
|
|
||||||
params.address = address;
|
|
||||||
params.byte1 = 0;
|
|
||||||
params.byte2 = 0;
|
|
||||||
params.byte3 = 0;
|
|
||||||
params.byte4 = 0;
|
|
||||||
params.recipient = 1;
|
|
||||||
params.register = register;
|
|
||||||
params.rw = 0;
|
|
||||||
|
|
||||||
let addMinutesToTimestamp = priorities[register];
|
let addMinutesToTimestamp = priorities[register];
|
||||||
|
|
||||||
let timestampStart = PRIORITY_TYPES.node_cmd; //run imediatelly in function runTasks
|
let params = getParams();
|
||||||
if (addMinutesToTimestamp > 1) {
|
|
||||||
timestampStart = timestampStart + addMinutesToTimestamp * 60000;
|
|
||||||
}
|
|
||||||
|
|
||||||
//other values
|
params.address = address;
|
||||||
|
params.recipient = 1;
|
||||||
|
params.register = register;
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
params.tbname = tbname;
|
params.tbname = tbname;
|
||||||
params.timestamp = timestampStart;
|
params.timestamp = time + 5000 + i * 500 + addMinutesToTimestamp * 1000; //to make slight time difference
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||||
params.info = "generated cmd - buildTasks (node)";
|
params.info = "generated cmd - buildTasks (node)";
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1206,12 +1154,9 @@ exports.install = function(instance) {
|
||||||
if (!init) return;
|
if (!init) return;
|
||||||
|
|
||||||
|
|
||||||
//Priebežne (raz za cca 5 minút) je potrebné vyčítať z Master nodu verziu jeho FW.
|
//Master node FW version
|
||||||
//Jedná sa o register 10. Rovnaká interpretácia ako pri FW verzii nodu.
|
|
||||||
//Adresa mastera je 0. V prípade že kedykoľvek nastane situácia že Master Node neodpovedá (napríklad pri vyčítaní telemetrie z nodu nevráti žiadne dáta),
|
|
||||||
//tak treba vyreportovať string "NOK".
|
|
||||||
{
|
{
|
||||||
let params = getParams(PRIORITY_TYPES.fw_detection);
|
let params = getParams();
|
||||||
params.type = "cmd-master";
|
params.type = "cmd-master";
|
||||||
params.register = 4;
|
params.register = 4;
|
||||||
params.address = 0;
|
params.address = 0;
|
||||||
|
|
@ -1220,7 +1165,6 @@ exports.install = function(instance) {
|
||||||
params.tbname = SETTINGS.rvoTbName;
|
params.tbname = SETTINGS.rvoTbName;
|
||||||
params.info = "Master node FW verzia";
|
params.info = "Master node FW verzia";
|
||||||
//params.debug = true;
|
//params.debug = true;
|
||||||
|
|
||||||
//this will set SETTINGS.masterNodeIsResponding
|
//this will set SETTINGS.masterNodeIsResponding
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
|
|
@ -1228,7 +1172,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//kazdu hodinu skontrolovat nastavenie profilov
|
//kazdu hodinu skontrolovat nastavenie profilov
|
||||||
{
|
{
|
||||||
let params = getParams(PRIORITY_TYPES.fw_detection);
|
let params = getParams();
|
||||||
params.type = "process_profiles";
|
params.type = "process_profiles";
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = Date.now() + 60000;
|
||||||
params.addMinutesToTimestamp = 60;//60 = every hour
|
params.addMinutesToTimestamp = 60;//60 = every hour
|
||||||
|
|
@ -1336,7 +1280,12 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let data = null;
|
let data = null;
|
||||||
|
|
||||||
if (newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication > now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION) return;
|
if (nodeCurrentStatus === "OFFLINE") {
|
||||||
|
data = { status: newStatus };
|
||||||
|
nodeDbStatusModify(node, data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication > now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION) return;
|
||||||
else if (newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication < now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION) {
|
else if (newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication < now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION) {
|
||||||
data = { time_of_last_communication: now };
|
data = { time_of_last_communication: now };
|
||||||
nodeDbStatusModify(node, data);
|
nodeDbStatusModify(node, data);
|
||||||
|
|
@ -1476,7 +1425,7 @@ exports.install = function(instance) {
|
||||||
if (type == "process_profiles") {
|
if (type == "process_profiles") {
|
||||||
tasks[0].timestamp = currentTimestamp + tasks[0].addMinutesToTimestamp * 60000;
|
tasks[0].timestamp = currentTimestamp + tasks[0].addMinutesToTimestamp * 60000;
|
||||||
|
|
||||||
//vsetky linie kt. su zapnute, a spracuju sa nespracovane profily nodov
|
//na vsetky zapnutych liniach sa spracuju nespracovane profily nodov
|
||||||
loadRelaysData();
|
loadRelaysData();
|
||||||
|
|
||||||
interval = setInterval(runTasks, SHORT_INTERVAL);
|
interval = setInterval(runTasks, SHORT_INTERVAL);
|
||||||
|
|
@ -1517,7 +1466,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
turnLine(onOrOff, params.line, info);
|
turnLine(onOrOff, params.line, info);
|
||||||
|
|
||||||
interval = setInterval(runTasks, SHORT_INTERVAL);
|
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1554,7 +1503,6 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
const register = params.register;
|
const register = params.register;
|
||||||
|
|
||||||
//high_priority
|
|
||||||
if (!SETTINGS.masterNodeIsResponding) {
|
if (!SETTINGS.masterNodeIsResponding) {
|
||||||
//ak neodpoveda, nebudeme vykonavat ziadne commands, okrem cmd-terminal, a fw version
|
//ak neodpoveda, nebudeme vykonavat ziadne commands, okrem cmd-terminal, a fw version
|
||||||
errorHandler.sendMessageToService("Master node is not responding");
|
errorHandler.sendMessageToService("Master node is not responding");
|
||||||
|
|
@ -1609,8 +1557,6 @@ exports.install = function(instance) {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
params.byte1 = d.getHours();//h
|
params.byte1 = d.getHours();//h
|
||||||
params.byte2 = d.getMinutes();//m
|
params.byte2 = d.getMinutes();//m
|
||||||
params.byte3 = 0;//s
|
|
||||||
params.byte4 = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//SET DUSK/DAWN FOR BROADCAST
|
//SET DUSK/DAWN FOR BROADCAST
|
||||||
|
|
@ -1621,8 +1567,6 @@ exports.install = function(instance) {
|
||||||
let sunCalcResult = calculateDuskDawn();
|
let sunCalcResult = calculateDuskDawn();
|
||||||
params.byte1 = sunCalcResult["dusk_hours"];//h
|
params.byte1 = sunCalcResult["dusk_hours"];//h
|
||||||
params.byte2 = sunCalcResult["dusk_minutes"];//m
|
params.byte2 = sunCalcResult["dusk_minutes"];//m
|
||||||
params.byte3 = 0;//s
|
|
||||||
params.byte4 = 0;
|
|
||||||
|
|
||||||
//TODO astrohodiny
|
//TODO astrohodiny
|
||||||
let dusk = "Time of dusk: " + sunCalcResult["dusk"];
|
let dusk = "Time of dusk: " + sunCalcResult["dusk"];
|
||||||
|
|
@ -1635,8 +1579,6 @@ exports.install = function(instance) {
|
||||||
let sunCalcResult = calculateDuskDawn();
|
let sunCalcResult = calculateDuskDawn();
|
||||||
params.byte1 = sunCalcResult["dawn_hours"];//h
|
params.byte1 = sunCalcResult["dawn_hours"];//h
|
||||||
params.byte2 = sunCalcResult["dawn_minutes"];//m
|
params.byte2 = sunCalcResult["dawn_minutes"];//m
|
||||||
params.byte3 = 0;//s
|
|
||||||
params.byte4 = 0;
|
|
||||||
|
|
||||||
//TODO astrohodiny
|
//TODO astrohodiny
|
||||||
let dawn = "Time of dawn: " + sunCalcResult["dawn"];
|
let dawn = "Time of dawn: " + sunCalcResult["dawn"];
|
||||||
|
|
@ -1752,7 +1694,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
terminalCommandResponse(params, "ERROR", data)
|
terminalCommandResponse(params, "ERROR", data);
|
||||||
handleNokResponseOnRsPort("handleNOK else block", params, itIsNodeCommand, saveToTb);
|
handleNokResponseOnRsPort("handleNOK else block", params, itIsNodeCommand, saveToTb);
|
||||||
|
|
||||||
if (params.hasOwnProperty("debug")) {
|
if (params.hasOwnProperty("debug")) {
|
||||||
|
|
@ -1805,9 +1747,9 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let values = {};
|
let values = {};
|
||||||
|
|
||||||
// console.log(message);
|
|
||||||
let updateStatus = updateNodeStatus(node, false);
|
let updateStatus = updateNodeStatus(node, false);
|
||||||
|
|
||||||
|
console.log("cmd_man: handleNokRsPort: ", node, register, message);
|
||||||
//master node
|
//master node
|
||||||
if (node == 0) {
|
if (node == 0) {
|
||||||
sendNotification("CMD Manager: process cmd", SETTINGS.rvoTbName, "master_node_is_not_responding", {}, "", SEND_TO.tb, instance, "rvo_status");
|
sendNotification("CMD Manager: process cmd", SETTINGS.rvoTbName, "master_node_is_not_responding", {}, "", SEND_TO.tb, instance, "rvo_status");
|
||||||
|
|
@ -1917,8 +1859,12 @@ exports.install = function(instance) {
|
||||||
let nodeObj = nodesData_clone[key];
|
let nodeObj = nodesData_clone[key];
|
||||||
if (nodeObj.tbname == undefined) continue;
|
if (nodeObj.tbname == undefined) continue;
|
||||||
|
|
||||||
if (nodeObj.status) number_of_ok_luminaires++;
|
if (nodeObj.status === "OFFLINE") {
|
||||||
|
nodeObj.node_status_before_offline === true ? number_of_ok_luminaires++ : number_of_nok_luminaires++;
|
||||||
|
}
|
||||||
|
else if (nodeObj.status == true) number_of_ok_luminaires++;
|
||||||
else number_of_nok_luminaires++;
|
else number_of_nok_luminaires++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const values = {
|
const values = {
|
||||||
|
|
@ -2376,16 +2322,11 @@ exports.install = function(instance) {
|
||||||
relaysData[line].profile = profile;
|
relaysData[line].profile = profile;
|
||||||
|
|
||||||
loadRelaysData(line)
|
loadRelaysData(line)
|
||||||
|
|
||||||
//TODO build tasks by mala bezat az ked je vsetko loadRelaysData
|
|
||||||
//spracovane, pravdepodobne treba spravit promisy
|
|
||||||
logger.debug("loadRelaysData DONE for line", line);
|
logger.debug("loadRelaysData DONE for line", line);
|
||||||
console.log("zacina buildTasks po loadRelaysData.........")
|
|
||||||
|
|
||||||
buildTasks({ processLineProfiles: true, line: line });
|
buildTasks({ processLineProfiles: true, line: line });
|
||||||
|
|
||||||
sendNotification("CMD manager - set profile from worksys", tbname, "switching_profile_was_processed_for_line", { line: line }, profile, SEND_TO.tb, instance);
|
sendNotification("CMD manager - set profile from worksys", tbname, "switching_profile_was_processed_for_line", { line: line }, profile, SEND_TO.tb, instance);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ exports.install = async function(instance) {
|
||||||
if (dbs.nodesData.hasOwnProperty("0")) delete dbs.nodesData["0"];
|
if (dbs.nodesData.hasOwnProperty("0")) delete dbs.nodesData["0"];
|
||||||
|
|
||||||
dbs.settings = {
|
dbs.settings = {
|
||||||
edge_fw_version : "2025-01-13", //rok-mesiac-den
|
edge_fw_version: "2025-01-21", //rok-mesiac-den
|
||||||
language: responseSettings[0]["lang"],
|
language: responseSettings[0]["lang"],
|
||||||
rvo_name: responseSettings[0]["rvo_name"],
|
rvo_name: responseSettings[0]["rvo_name"],
|
||||||
project_id: responseSettings[0]["project_id"],
|
project_id: responseSettings[0]["project_id"],
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač
|
||||||
const { errLogger, logger, monitor } = require('./helper/logger');
|
const { errLogger, logger, monitor } = require('./helper/logger');
|
||||||
const SerialPort = require('serialport');
|
const SerialPort = require('serialport');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
//const { exec } = require('child_process');
|
|
||||||
const { runSyncExec } = require('./helper/serialport_helper');
|
const { runSyncExec } = require('./helper/serialport_helper');
|
||||||
const { bytesToInt, resizeArray } = require('./helper/utils');
|
const { bytesToInt, resizeArray } = require('./helper/utils');
|
||||||
const { sendNotification } = require('./helper/notification_reporter');
|
const { sendNotification } = require('./helper/notification_reporter');
|
||||||
|
|
@ -71,7 +70,6 @@ let rvoTbName;
|
||||||
let GLOBALS; //FLOW global GLOBALS
|
let GLOBALS; //FLOW global GLOBALS
|
||||||
let SETTINGS; // GLOBALS.settings
|
let SETTINGS; // GLOBALS.settings
|
||||||
let controller_type;
|
let controller_type;
|
||||||
let contactorSwitchCounter = 0; //how many times line contactor switched ?
|
|
||||||
|
|
||||||
let alarmStatus = "OFF";
|
let alarmStatus = "OFF";
|
||||||
|
|
||||||
|
|
@ -128,7 +126,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//status for calculating Statecodes
|
//status for calculating Statecodes
|
||||||
let deviceStatus = { //key is device name: temperature,....
|
let deviceStatus = { //key is device name: temperature,....
|
||||||
"state_of_main_switch": "Off", //Hlavný istič
|
"state_of_main_switch": "Off", //Hlavný istič (po novom druhy dverovy kontakt)
|
||||||
"rotary_switch_state": "Off", //Prevádzkový mód
|
"rotary_switch_state": "Off", //Prevádzkový mód
|
||||||
"door_condition": "closed", //Dverový kontakt
|
"door_condition": "closed", //Dverový kontakt
|
||||||
"em": "OK", //elektromer rvo
|
"em": "OK", //elektromer rvo
|
||||||
|
|
@ -203,13 +201,10 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
sendTelemetry(values, rvoTbName);
|
sendTelemetry(values, rvoTbName);
|
||||||
|
|
||||||
let time = 5 * 1000;
|
|
||||||
setTimeout(function() {
|
|
||||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "buildTasks" });
|
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "buildTasks" });
|
||||||
|
|
||||||
sendNotification("rsPort.open()", rvoTbName, "flow_start", {}, "", SEND_TO.tb, instance);
|
sendNotification("rsPort.open()", rvoTbName, "flow_start", {}, "", SEND_TO.tb, instance);
|
||||||
monitor.info("-->FLOW bol spustený", rvoTbName, SETTINGS.edge_fw_version);
|
monitor.info("-->FLOW bol spustený", rvoTbName, SETTINGS.edge_fw_version);
|
||||||
}, time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -309,6 +304,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
initialSetting();
|
initialSetting();
|
||||||
|
|
||||||
|
setTimeout(function() { ws.send(JSON.stringify({ cmd: "all" })) }, 5000);
|
||||||
// we request dev info about neuron device from evok to keep websocket connection alive
|
// we request dev info about neuron device from evok to keep websocket connection alive
|
||||||
// for some reason this request returns no data, but connection keeps alive
|
// for some reason this request returns no data, but connection keeps alive
|
||||||
startRequests = setInterval(() => {
|
startRequests = setInterval(() => {
|
||||||
|
|
@ -580,7 +576,7 @@ exports.install = function(instance) {
|
||||||
// we expect array as flowdata.data
|
// we expect array as flowdata.data
|
||||||
instance.on("1", flowdata => {
|
instance.on("1", flowdata => {
|
||||||
|
|
||||||
console.log(flowdata.data);
|
//console.log(flowdata.data);
|
||||||
|
|
||||||
if (!flowdata.data instanceof Object) return;
|
if (!flowdata.data instanceof Object) return;
|
||||||
|
|
||||||
|
|
@ -589,10 +585,6 @@ exports.install = function(instance) {
|
||||||
let force = obj.force;
|
let force = obj.force;
|
||||||
let info = obj.info;
|
let info = obj.info;
|
||||||
|
|
||||||
//how many times did the lines switched ? if all lines (except line 0) has switched, we request data from evok:
|
|
||||||
contactorSwitchCounter++;
|
|
||||||
if(contactorSwitchCounter == Object.keys(relaysData).length-1 && ws) setTimeout(function(){ws.send(JSON.stringify({cmd:"all"}))},5000);
|
|
||||||
|
|
||||||
if (obj.command == "on") turnLine("on", line, undefined, force, info);
|
if (obj.command == "on") turnLine("on", line, undefined, force, info);
|
||||||
else if (obj.command == "off") turnLine("off", line, undefined, force, info);
|
else if (obj.command == "off") turnLine("off", line, undefined, force, info);
|
||||||
else if (obj.command == "turnOnAlarm") turnAlarm("on");
|
else if (obj.command == "turnOnAlarm") turnAlarm("on");
|
||||||
|
|
@ -815,26 +807,6 @@ exports.install = function(instance) {
|
||||||
let value = "On";
|
let value = "On";
|
||||||
if (newPinValue === 0) value = "Off";
|
if (newPinValue === 0) value = "Off";
|
||||||
|
|
||||||
//Hlavný istič
|
|
||||||
//! po novom uz 'state of main switch' nemame. Namiesto neho je 'door_condition', kedze mame dvoje dveri
|
|
||||||
//! takze ked pride z evoku signal pre 'input1_05', handlujeme ho ako 'door_condition'
|
|
||||||
// if(type === "!!!state_of_main_switch")
|
|
||||||
// {
|
|
||||||
// if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
|
||||||
// {
|
|
||||||
// sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
|
|
||||||
// values["status"] = "NOK";
|
|
||||||
|
|
||||||
// deviceStatus["state_of_main_switch"] = "Off";
|
|
||||||
// }
|
|
||||||
// else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
|
|
||||||
// {
|
|
||||||
// sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_on", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
|
|
||||||
|
|
||||||
// deviceStatus["state_of_main_switch"] = "On";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//Prevádzkový mód
|
//Prevádzkový mód
|
||||||
if (type == "rotary_switch_state") {
|
if (type == "rotary_switch_state") {
|
||||||
// combination of these two pins required to get result
|
// combination of these two pins required to get result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue