Do not send 'switching profile applied to line' notification; Handle nok,ok,offline node status
This commit is contained in:
parent
c052887a1f
commit
63504df84d
2 changed files with 277 additions and 363 deletions
|
|
@ -1591,17 +1591,25 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO -> status offline for rvo if rotary_switch_state is OFF
|
let contactorStatus = 1;
|
||||||
|
if(relaysData[line] != undefined) contactorStatus = relaysData[line].contactor;
|
||||||
|
|
||||||
|
if (line == 0 || contactorStatus == 0) {
|
||||||
|
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: -> status offline for rvo if rotary_switch_state is OFF, this is source of errors
|
||||||
|
//
|
||||||
// let relayStatus = 1;
|
// let relayStatus = 1;
|
||||||
// if (relaysData[line] != undefined) {
|
// if (relaysData[line] != undefined) {
|
||||||
// relayStatus = relaysData[line].contactor;
|
// relayStatus = relaysData[line].contactor;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// if (line == 0) relayStatus = 0;
|
// if (line == 0) relayStatus = 0;
|
||||||
// if (type == "cmd-terminal") relayStatus = 1;
|
// if (type == "cmd-terminal") relayStatus = 1;
|
||||||
|
|
||||||
//check if rotary_switch_state == "Off"
|
// //check if rotary_switch_state == "Off"
|
||||||
// if (relayStatus == 0) {
|
// if (relayStatus == 0) {
|
||||||
// console.log("------------------------------------relayStatus", relayStatus, line);
|
// console.log("------------------------------------relayStatus", relayStatus, line);
|
||||||
// let values = { "status": "OFFLINE" };
|
// let values = { "status": "OFFLINE" };
|
||||||
|
|
|
||||||
|
|
@ -167,12 +167,10 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
console.log(exports.title, "controller type: ", controller_type);
|
console.log(exports.title, "controller type: ", controller_type);
|
||||||
|
|
||||||
if(controller_type === "lm")
|
if (controller_type === "lm") {
|
||||||
{
|
|
||||||
handleRsPort();
|
handleRsPort();
|
||||||
}
|
}
|
||||||
else if(controller_type === "unipi")
|
else if (controller_type === "unipi") {
|
||||||
{
|
|
||||||
handleWebSocket();
|
handleWebSocket();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -181,32 +179,26 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function initialSetting()
|
function initialSetting() {
|
||||||
{
|
|
||||||
//force turn off relays
|
//force turn off relays
|
||||||
|
|
||||||
let keys = Object.keys(pinsData);
|
let keys = Object.keys(pinsData);
|
||||||
for(let i = 0; i < keys.length; i++)
|
for (let i = 0; i < keys.length; i++) {
|
||||||
{
|
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
let line = pinsData[key].line;
|
let line = pinsData[key].line;
|
||||||
|
|
||||||
if(line != undefined)
|
if (line != undefined) {
|
||||||
{
|
if (relaysData[line] != undefined) {
|
||||||
if(relaysData[line] != undefined)
|
|
||||||
{
|
|
||||||
pinsData[key].tbname = relaysData[line].tbname;
|
pinsData[key].tbname = relaysData[line].tbname;
|
||||||
//relaysData[line].contactor = 0;
|
//relaysData[line].contactor = 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
errLogger.error("CRITICAL!!! undefined relay", relaysData[line], line);
|
errLogger.error("CRITICAL!!! undefined relay", relaysData[line], line);
|
||||||
sendNotification("set port ", rvoTbName, "local_database_is_corrupted", {}, "", SEND_TO.tb, instance);
|
sendNotification("set port ", rvoTbName, "local_database_is_corrupted", {}, "", SEND_TO.tb, instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pinsData[key].type == "state_of_contactor")
|
if (pinsData[key].type == "state_of_contactor") {
|
||||||
{
|
|
||||||
let pin = key - 1;
|
let pin = key - 1;
|
||||||
if (controller_type === "unipi") pin = key;
|
if (controller_type === "unipi") pin = key;
|
||||||
|
|
||||||
|
|
@ -233,8 +225,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleRsPort()
|
function handleRsPort() {
|
||||||
{
|
|
||||||
//TODO build according to pins!!!
|
//TODO build according to pins!!!
|
||||||
//! rsPort to open are the same for lm and unipi and electromer ("/dev/ttymxc0")
|
//! rsPort to open are the same for lm and unipi and electromer ("/dev/ttymxc0")
|
||||||
const setRSPortData = [0xAA, 6, 6, 6, 6, 6, 6, 0, 6, 6, 6, 1, 1, 1, 1, 0, 0, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 15, 15, 15, 15, 15, 15, 0, 15, 15, 15, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0];
|
const setRSPortData = [0xAA, 6, 6, 6, 6, 6, 6, 0, 6, 6, 6, 1, 1, 1, 1, 0, 0, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 15, 15, 15, 15, 15, 15, 0, 15, 15, 15, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0];
|
||||||
|
|
@ -411,16 +402,13 @@ exports.install = function(instance) {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function getPin(line)
|
function getPin(line) {
|
||||||
{
|
|
||||||
//conversionTable
|
//conversionTable
|
||||||
let keys = Object.keys(pinsData);
|
let keys = Object.keys(pinsData);
|
||||||
for(let i = 0; i < keys.length; i++)
|
for (let i = 0; i < keys.length; i++) {
|
||||||
{
|
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
|
|
||||||
if(pinsData[key].type == "state_of_contactor" && pinsData[key].line == line)
|
if (pinsData[key].type == "state_of_contactor" && pinsData[key].line == line) {
|
||||||
{
|
|
||||||
if (rsPort) return key - 1;
|
if (rsPort) return key - 1;
|
||||||
if (ws) return key;
|
if (ws) return key;
|
||||||
}
|
}
|
||||||
|
|
@ -432,8 +420,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function turnAlarm(onOrOff)
|
function turnAlarm(onOrOff) {
|
||||||
{
|
|
||||||
let value = 0;
|
let value = 0;
|
||||||
if (onOrOff == "on") value = 1;
|
if (onOrOff == "on") value = 1;
|
||||||
|
|
||||||
|
|
@ -442,8 +429,7 @@ exports.install = function(instance) {
|
||||||
alarmStatus = "OFF";
|
alarmStatus = "OFF";
|
||||||
if (value == 1) alarmStatus = "ON";
|
if (value == 1) alarmStatus = "ON";
|
||||||
|
|
||||||
if(rsPort)
|
if (rsPort) {
|
||||||
{
|
|
||||||
let arr = [0x55];
|
let arr = [0x55];
|
||||||
arr.push(13);
|
arr.push(13);
|
||||||
arr.push(0);
|
arr.push(0);
|
||||||
|
|
@ -453,8 +439,7 @@ exports.install = function(instance) {
|
||||||
logger.debug(`sirena - ${onOrOff}`);
|
logger.debug(`sirena - ${onOrOff}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(ws)
|
else if (ws) {
|
||||||
{
|
|
||||||
let cmd = { "cmd": "set", "dev": "relay", "circuit": "1_01", "value": value };
|
let cmd = { "cmd": "set", "dev": "relay", "circuit": "1_01", "value": value };
|
||||||
ws.send(JSON.stringify(cmd));
|
ws.send(JSON.stringify(cmd));
|
||||||
logger.debug(`sirena - ${onOrOff}`);
|
logger.debug(`sirena - ${onOrOff}`);
|
||||||
|
|
@ -462,20 +447,17 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function reportLineStatus(line)
|
function reportLineStatus(line) {
|
||||||
{
|
|
||||||
//Tá hodnota by mala fungovať tak že LSB bit číslo je stav ističa (1 - On, 0 - Off) a druhý bit je stav stýkača (1 - true, 0 - false).
|
//Tá hodnota by mala fungovať tak že LSB bit číslo je stav ističa (1 - On, 0 - Off) a druhý bit je stav stýkača (1 - true, 0 - false).
|
||||||
let tbname = relaysData[line].tbname;
|
let tbname = relaysData[line].tbname;
|
||||||
let bits = [];
|
let bits = [];
|
||||||
|
|
||||||
if(deviceStatus["state_of_breaker"][line] == "On")
|
if (deviceStatus["state_of_breaker"][line] == "On") {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else bits.push(1);
|
else bits.push(1);
|
||||||
|
|
||||||
if(deviceStatus["state_of_contactor"][line] == "On")
|
if (deviceStatus["state_of_contactor"][line] == "On") {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else bits.push(1);
|
else bits.push(1);
|
||||||
|
|
@ -490,16 +472,14 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
|
|
||||||
// turn line on or off
|
// turn line on or off
|
||||||
function turnLine(onOrOff, line, pin, force, info)
|
function turnLine(onOrOff, line, pin, force, info) {
|
||||||
{
|
|
||||||
//onOrOff => "on" or "off"
|
//onOrOff => "on" or "off"
|
||||||
let value = 0;
|
let value = 0;
|
||||||
if (onOrOff == "on") value = 1;
|
if (onOrOff == "on") value = 1;
|
||||||
|
|
||||||
if (force == undefined) force = false;
|
if (force == undefined) force = false;
|
||||||
|
|
||||||
if(line == 0)
|
if (line == 0) {
|
||||||
{
|
|
||||||
if (value == 1 && alarmStatus == "ON") turnAlarm("off");
|
if (value == 1 && alarmStatus == "ON") turnAlarm("off");
|
||||||
SETTINGS.maintenance_mode = value ? true : false;
|
SETTINGS.maintenance_mode = value ? true : false;
|
||||||
|
|
||||||
|
|
@ -514,16 +494,13 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
if (pin === undefined) pin = getPin(line);
|
if (pin === undefined) pin = getPin(line);
|
||||||
|
|
||||||
if(pin === undefined)
|
if (pin === undefined) {
|
||||||
{
|
|
||||||
errLogger.error("pin is undefined!", line);
|
errLogger.error("pin is undefined!", line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!force)
|
if (!force) {
|
||||||
{
|
if (relaysData[line].contactor == value) {
|
||||||
if(relaysData[line].contactor == value)
|
|
||||||
{
|
|
||||||
instance.send(SEND_TO.debug, `line is already ${onOrOff} ` + line);
|
instance.send(SEND_TO.debug, `line is already ${onOrOff} ` + line);
|
||||||
logger.debug(`turnLine: line is already ${onOrOff} `, line);
|
logger.debug(`turnLine: line is already ${onOrOff} `, line);
|
||||||
return;
|
return;
|
||||||
|
|
@ -531,34 +508,29 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(!rsPort.isOpen && !ws)
|
// if(!rsPort.isOpen && !ws)
|
||||||
if(!rsPort && !ws)
|
if (!rsPort && !ws) {
|
||||||
{
|
|
||||||
errLogger.error("dido controller - port or websocket is not opened");
|
errLogger.error("dido controller - port or websocket is not opened");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rsPort)
|
if (rsPort) {
|
||||||
{
|
|
||||||
let arr = [0x55];
|
let arr = [0x55];
|
||||||
arr.push(pin);
|
arr.push(pin);
|
||||||
arr.push(0);
|
arr.push(0);
|
||||||
arr.push(value);
|
arr.push(value);
|
||||||
|
|
||||||
rsPort.write(Buffer.from(arr), function(err) {
|
rsPort.write(Buffer.from(arr), function(err) {
|
||||||
if(err === undefined)
|
if (err === undefined) {
|
||||||
{
|
|
||||||
monitor.info(`turnLine ${onOrOff} zapisal do rsPort-u`, line, pin, arr, info);
|
monitor.info(`turnLine ${onOrOff} zapisal do rsPort-u`, line, pin, arr, info);
|
||||||
switchLogic(arr);
|
switchLogic(arr);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
monitor.info(`turnLine ${onOrOff} WRITE error`, err);
|
monitor.info(`turnLine ${onOrOff} WRITE error`, err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(ws)
|
else if (ws) {
|
||||||
{
|
|
||||||
//pin = "relay1_03" or "input1_01" ... we must make just "1_01" with slice method
|
//pin = "relay1_03" or "input1_01" ... we must make just "1_01" with slice method
|
||||||
monitor.info(`turnLine ${onOrOff} - (line, pin, force)`, line, pin, force, info);
|
monitor.info(`turnLine ${onOrOff} - (line, pin, force)`, line, pin, force, info);
|
||||||
let cmd = { "cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": value };
|
let cmd = { "cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": value };
|
||||||
|
|
@ -567,8 +539,8 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//if rvo is 24/7, it has just one switching profile point at 13:00. we do not want to send notification as it repeats every day.
|
//if rvo is 24/7, it has just one switching profile point at 13:00. we do not want to send notification as it repeats every day.
|
||||||
const d = new Date();
|
//const d = new Date();
|
||||||
if(d.getHours() != 13) sendNotification("Dido_controller: ", SETTINGS.rvoTbName, "switching_profile_point_applied_to_line", { line: line, value: onOrOff }, "", SEND_TO.tb, instance);
|
//if(d.getHours() != 13) sendNotification("Dido_controller: ", SETTINGS.rvoTbName, "switching_profile_point_applied_to_line", { line: line, value: onOrOff }, "", SEND_TO.tb, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -587,37 +559,29 @@ exports.install = function(instance) {
|
||||||
instance.send(SEND_TO.debug, flowdata.data);
|
instance.send(SEND_TO.debug, flowdata.data);
|
||||||
|
|
||||||
// we handle nok status from modbus_reader component and thermometer
|
// we handle nok status from modbus_reader component and thermometer
|
||||||
if("status" in flowdata.data)
|
if ("status" in flowdata.data) {
|
||||||
{
|
|
||||||
const status = flowdata.data.status;
|
const status = flowdata.data.status;
|
||||||
if(status == "NOK-twilight_sensor")
|
if (status == "NOK-twilight_sensor") {
|
||||||
{
|
|
||||||
deviceStatus["twilight_sensor"] = "NOK";
|
deviceStatus["twilight_sensor"] = "NOK";
|
||||||
}
|
}
|
||||||
else if(status == "NOK-em340" || status == "NOK-em111")
|
else if (status == "NOK-em340" || status == "NOK-em111") {
|
||||||
{
|
|
||||||
deviceStatus["em"] = "NOK";
|
deviceStatus["em"] = "NOK";
|
||||||
}
|
}
|
||||||
else if(status == "NOK-thermometer")
|
else if (status == "NOK-thermometer") {
|
||||||
{
|
|
||||||
deviceStatus["temperature"] = "NOK";
|
deviceStatus["temperature"] = "NOK";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if("values" in flowdata.data)
|
else if ("values" in flowdata.data) {
|
||||||
{
|
|
||||||
const values = flowdata.data.values;
|
const values = flowdata.data.values;
|
||||||
if(values.hasOwnProperty("twilight_sensor"))
|
if (values.hasOwnProperty("twilight_sensor")) {
|
||||||
{
|
|
||||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "lux_sensor", value: values["twilight_sensor"] });
|
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "lux_sensor", value: values["twilight_sensor"] });
|
||||||
deviceStatus["twilight_sensor"] = "OK"
|
deviceStatus["twilight_sensor"] = "OK"
|
||||||
}
|
}
|
||||||
else if(values.hasOwnProperty("temperature"))
|
else if (values.hasOwnProperty("temperature")) {
|
||||||
{
|
|
||||||
deviceStatus["temperature"] = "OK";
|
deviceStatus["temperature"] = "OK";
|
||||||
}
|
}
|
||||||
// EM
|
// EM
|
||||||
else if(values.hasOwnProperty("total_power") || values.hasOwnProperty("total_energy") || values.hasOwnProperty("power_factor") || values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_1_current"))
|
else if (values.hasOwnProperty("total_power") || values.hasOwnProperty("total_energy") || values.hasOwnProperty("power_factor") || values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_1_current")) {
|
||||||
{
|
|
||||||
deviceStatus["em"] = "OK";
|
deviceStatus["em"] = "OK";
|
||||||
SETTINGS.no_voltage.size > 0 ? deviceStatus["no_voltage"] = "NOK" : deviceStatus["no_voltage"] = "OK";
|
SETTINGS.no_voltage.size > 0 ? deviceStatus["no_voltage"] = "NOK" : deviceStatus["no_voltage"] = "OK";
|
||||||
}
|
}
|
||||||
|
|
@ -659,38 +623,31 @@ exports.install = function(instance) {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function calculateStateCode()
|
function calculateStateCode() {
|
||||||
{
|
|
||||||
|
|
||||||
let bits = [];
|
let bits = [];
|
||||||
|
|
||||||
//Hlavný istič - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
|
//Hlavný istič - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
|
||||||
if(deviceStatus["state_of_main_switch"] == "closed")
|
if (deviceStatus["state_of_main_switch"] == "closed") {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Prevádzkový mód - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
//Prevádzkový mód - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
||||||
if(!SETTINGS.maintenance_mode)
|
if (!SETTINGS.maintenance_mode) {
|
||||||
{
|
if (deviceStatus["rotary_switch_state"] == "Manual") {
|
||||||
if(deviceStatus["rotary_switch_state"] == "Manual")
|
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatus["rotary_switch_state"] == "Automatic")
|
if (deviceStatus["rotary_switch_state"] == "Automatic") {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatus["rotary_switch_state"] == "Off")
|
if (deviceStatus["rotary_switch_state"] == "Off") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
@ -701,87 +658,70 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dverový kontakt
|
//Dverový kontakt
|
||||||
if(deviceStatus["door_condition"] == "closed")
|
if (deviceStatus["door_condition"] == "closed") {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//EM
|
//EM
|
||||||
if(deviceStatus["em"] == "NOK")
|
if (deviceStatus["em"] == "NOK") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Teplomer
|
//Teplomer
|
||||||
if(deviceStatus["temperature"] == "NOK")
|
if (deviceStatus["temperature"] == "NOK") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Batéria
|
//Batéria
|
||||||
if(deviceStatus["battery"] == "NOK")
|
if (deviceStatus["battery"] == "NOK") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Zdroj
|
//Zdroj
|
||||||
if(deviceStatus["power_supply"] == "NOK")
|
if (deviceStatus["power_supply"] == "NOK") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//MN
|
//MN
|
||||||
if(deviceStatus["master_node"] == "NOK")
|
if (deviceStatus["master_node"] == "NOK") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//výpadok napätia na fáze
|
//výpadok napätia na fáze
|
||||||
if(deviceStatus["no_voltage"] == "NOK")
|
if (deviceStatus["no_voltage"] == "NOK") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatus["twilight_sensor"] == "NOK")
|
if (deviceStatus["twilight_sensor"] == "NOK") {
|
||||||
{
|
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// doplnime do 16 bitov (2 byty)
|
// doplnime do 16 bitov (2 byty)
|
||||||
for(let i = bits.length; i < 16; i++)
|
for (let i = bits.length; i < 16; i++) {
|
||||||
{
|
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -839,8 +779,7 @@ exports.install = function(instance) {
|
||||||
if (["em", "twilight_sensor", "temperature"].includes(key) && value == "NOK") status = "NOK";
|
if (["em", "twilight_sensor", "temperature"].includes(key) && value == "NOK") status = "NOK";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(status == "OK")
|
if (status == "OK") {
|
||||||
{
|
|
||||||
let pinIndexes = [1, 4, 6];
|
let pinIndexes = [1, 4, 6];
|
||||||
if (controller_type == 'unipi') pinIndexes = ['input1_01', 'input1_04', 'input1_05'];
|
if (controller_type == 'unipi') pinIndexes = ['input1_01', 'input1_04', 'input1_05'];
|
||||||
|
|
||||||
|
|
@ -871,23 +810,20 @@ exports.install = function(instance) {
|
||||||
let pinIndex, newPinValue, twilight;
|
let pinIndex, newPinValue, twilight;
|
||||||
|
|
||||||
//data from rsPort
|
//data from rsPort
|
||||||
if(args.length == 1)
|
if (args.length == 1) {
|
||||||
{
|
|
||||||
pinIndex = args[0][1] + 1;
|
pinIndex = args[0][1] + 1;
|
||||||
if (pinIndex === 17) pinIndex--;
|
if (pinIndex === 17) pinIndex--;
|
||||||
newPinValue = args[0][3];
|
newPinValue = args[0][3];
|
||||||
twilight = args[0][2];
|
twilight = args[0][2];
|
||||||
}
|
}
|
||||||
//data from websocket
|
//data from websocket
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
pinIndex = args[0];
|
pinIndex = args[0];
|
||||||
newPinValue = args[1];
|
newPinValue = args[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
let obj = pinsData[pinIndex];
|
let obj = pinsData[pinIndex];
|
||||||
if(obj == undefined)
|
if (obj == undefined) {
|
||||||
{
|
|
||||||
previousValues[pinIndex] = newPinValue;
|
previousValues[pinIndex] = newPinValue;
|
||||||
//logger.debug("dido-switchLogic ==> no pinIndex", pinIndex);
|
//logger.debug("dido-switchLogic ==> no pinIndex", pinIndex);
|
||||||
return;
|
return;
|
||||||
|
|
@ -923,28 +859,23 @@ exports.install = function(instance) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//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
|
||||||
let pin2, pin3;
|
let pin2, pin3;
|
||||||
if(pinIndex == 2 || pinIndex == "input1_02")
|
if (pinIndex == 2 || pinIndex == "input1_02") {
|
||||||
{
|
|
||||||
pin2 = newPinValue;
|
pin2 = newPinValue;
|
||||||
pin3 = previousValues[3] || previousValues["input1_03"];
|
pin3 = previousValues[3] || previousValues["input1_03"];
|
||||||
|
|
||||||
if(pin3 == undefined)
|
if (pin3 == undefined) {
|
||||||
{
|
|
||||||
previousValues[pinIndex] = newPinValue;
|
previousValues[pinIndex] = newPinValue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(pinIndex == 3 || pinIndex == "input1_03")
|
else if (pinIndex == 3 || pinIndex == "input1_03") {
|
||||||
{
|
|
||||||
pin3 = newPinValue;
|
pin3 = newPinValue;
|
||||||
pin2 = previousValues[2] || previousValues["input1_02"];
|
pin2 = previousValues[2] || previousValues["input1_02"];
|
||||||
|
|
||||||
if(pin2 == undefined)
|
if (pin2 == undefined) {
|
||||||
{
|
|
||||||
previousValues[pinIndex] = newPinValue;
|
previousValues[pinIndex] = newPinValue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -967,16 +898,13 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Zdroj - pin 4
|
//Zdroj - pin 4
|
||||||
else if (type === "power_supply")
|
else if (type === "power_supply") {
|
||||||
{
|
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) {
|
||||||
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
|
||||||
{
|
|
||||||
sendNotification("switchLogic", rvoTbName, "power_supply_has_disconnected_input", {}, "", SEND_TO.tb, instance, "power_supply");
|
sendNotification("switchLogic", rvoTbName, "power_supply_has_disconnected_input", {}, "", SEND_TO.tb, instance, "power_supply");
|
||||||
|
|
||||||
deviceStatus["power_supply"] = "NOK";
|
deviceStatus["power_supply"] = "NOK";
|
||||||
}
|
}
|
||||||
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
|
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
|
||||||
{
|
|
||||||
sendNotification("switchLogic", rvoTbName, "power_supply_works_correctly", {}, "", SEND_TO.tb, instance, "power_supply");
|
sendNotification("switchLogic", rvoTbName, "power_supply_works_correctly", {}, "", SEND_TO.tb, instance, "power_supply");
|
||||||
|
|
||||||
deviceStatus["power_supply"] = "OK";
|
deviceStatus["power_supply"] = "OK";
|
||||||
|
|
@ -984,16 +912,13 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Batéria - pin 5
|
//Batéria - pin 5
|
||||||
else if (type === "battery")
|
else if (type === "battery") {
|
||||||
{
|
if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
|
||||||
if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
|
|
||||||
{
|
|
||||||
sendNotification("switchLogic", rvoTbName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
|
sendNotification("switchLogic", rvoTbName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
|
||||||
|
|
||||||
deviceStatus["battery"] = "NOK";
|
deviceStatus["battery"] = "NOK";
|
||||||
}
|
}
|
||||||
else if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
else if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) {
|
||||||
{
|
|
||||||
sendNotification("switchLogic", rvoTbName, "battery_level_is_ok", {}, "", SEND_TO.tb, instance, "battery_level");
|
sendNotification("switchLogic", rvoTbName, "battery_level_is_ok", {}, "", SEND_TO.tb, instance, "battery_level");
|
||||||
|
|
||||||
deviceStatus["battery"] = "OK";
|
deviceStatus["battery"] = "OK";
|
||||||
|
|
@ -1003,17 +928,14 @@ exports.install = function(instance) {
|
||||||
//Dverový kontakt - pin 6
|
//Dverový kontakt - pin 6
|
||||||
//! Po novom mame dva dverove kontakty, nie jeden. Druhy je teraz tam, kde bol digital input "state_of_main_switch"
|
//! Po novom mame dva dverove kontakty, nie jeden. Druhy je teraz tam, kde bol digital input "state_of_main_switch"
|
||||||
//! preto ked pride z evoku signal z input1_05, co bol predytm "main switch" handlujeme ho teraz ako 'door_condition'
|
//! preto ked pride z evoku signal z input1_05, co bol predytm "main switch" handlujeme ho teraz ako 'door_condition'
|
||||||
else if(type == "door_condition" || type === "state_of_main_switch")
|
else if (type == "door_condition" || type === "state_of_main_switch") {
|
||||||
{
|
|
||||||
newPinValue === 0 ? value = "open" : value = "closed";
|
newPinValue === 0 ? value = "open" : value = "closed";
|
||||||
|
|
||||||
if (value === "open" && SETTINGS.maintenance_mode)
|
if (value === "open" && SETTINGS.maintenance_mode) {
|
||||||
{
|
|
||||||
sendNotification("switchLogic", rvoTbName, "door_opened", {}, "", SEND_TO.tb, instance, "rvo_door");
|
sendNotification("switchLogic", rvoTbName, "door_opened", {}, "", SEND_TO.tb, instance, "rvo_door");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value === "open" && !SETTINGS.maintenance_mode)
|
if (value === "open" && !SETTINGS.maintenance_mode) {
|
||||||
{
|
|
||||||
sendNotification("switchLogic", rvoTbName, "door_opened_without_permission", {}, "", SEND_TO.tb, instance, "rvo_door");
|
sendNotification("switchLogic", rvoTbName, "door_opened_without_permission", {}, "", SEND_TO.tb, instance, "rvo_door");
|
||||||
|
|
||||||
// zapneme sirenu
|
// zapneme sirenu
|
||||||
|
|
@ -1021,8 +943,7 @@ exports.install = function(instance) {
|
||||||
if (type === "door_condition") turnAlarm("on");
|
if (type === "door_condition") turnAlarm("on");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value === "closed")
|
if (value === "closed") {
|
||||||
{
|
|
||||||
if (alarmStatus == "ON") turnAlarm("off");
|
if (alarmStatus == "ON") turnAlarm("off");
|
||||||
sendNotification("switchLogic", rvoTbName, "door_closed", {}, "", SEND_TO.tb, instance, "rvo_door");
|
sendNotification("switchLogic", rvoTbName, "door_closed", {}, "", SEND_TO.tb, instance, "rvo_door");
|
||||||
}
|
}
|
||||||
|
|
@ -1031,15 +952,13 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//lux sensor
|
//lux sensor
|
||||||
else if(type == "twilight_sensor")
|
else if (type == "twilight_sensor") {
|
||||||
{
|
|
||||||
//! TODO - to show nok status, if lux value is not changing more then 10 times.
|
//! TODO - to show nok status, if lux value is not changing more then 10 times.
|
||||||
//Daylight is far more than 1000. So most of the day, when it is sunshine comes just value 1000. But lux sensor is not NOK.
|
//Daylight is far more than 1000. So most of the day, when it is sunshine comes just value 1000. But lux sensor is not NOK.
|
||||||
//This is not the case in LM. If value from LM is the same 10x, there is 99% possibility, that sensor is NOK.
|
//This is not the case in LM. If value from LM is the same 10x, there is 99% possibility, that sensor is NOK.
|
||||||
value = newPinValue;
|
value = newPinValue;
|
||||||
|
|
||||||
if(controller_type === 'lm')
|
if (controller_type === 'lm') {
|
||||||
{
|
|
||||||
value = parseFloat(newPinValue + (256 * twilight));
|
value = parseFloat(newPinValue + (256 * twilight));
|
||||||
|
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
|
|
@ -1057,31 +976,27 @@ exports.install = function(instance) {
|
||||||
if (twilight_sensor_array.length > 10) {
|
if (twilight_sensor_array.length > 10) {
|
||||||
|
|
||||||
let set = new Set(twilight_sensor_array);
|
let set = new Set(twilight_sensor_array);
|
||||||
if(set.size === 1 && !twilightError)
|
if (set.size === 1 && !twilightError) {
|
||||||
{
|
|
||||||
twilightError = true;
|
twilightError = true;
|
||||||
let value = twilight_sensor_array.shift();
|
let value = twilight_sensor_array.shift();
|
||||||
|
|
||||||
newPinValue = 0;
|
newPinValue = 0;
|
||||||
}
|
}
|
||||||
else if (set.size !== 1 && twilightError)
|
else if (set.size !== 1 && twilightError) {
|
||||||
{
|
|
||||||
//sendNotification("switchLogic", rvoTbName, ERRWEIGHT.NOTICE, "Lux sensor is working again", "", SEND_TO.tb, instance );
|
//sendNotification("switchLogic", rvoTbName, ERRWEIGHT.NOTICE, "Lux sensor is working again", "", SEND_TO.tb, instance );
|
||||||
twilightError = false;
|
twilightError = false;
|
||||||
twilight_sensor_array.shift();
|
twilight_sensor_array.shift();
|
||||||
|
|
||||||
newPinValue = value;
|
newPinValue = value;
|
||||||
}
|
}
|
||||||
else if (set.size === 1 && twilightError)
|
else if (set.size === 1 && twilightError) {
|
||||||
{
|
|
||||||
twilight_sensor_array.shift();
|
twilight_sensor_array.shift();
|
||||||
newPinValue = 0;
|
newPinValue = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let diff = twilight_sensor[twilight_sensor.length - 1].timestamp - twilight_sensor[0].timestamp;
|
let diff = twilight_sensor[twilight_sensor.length - 1].timestamp - twilight_sensor[0].timestamp;
|
||||||
if(diff >= twilight_sensor_interval * 60 * 1000)
|
if (diff >= twilight_sensor_interval * 60 * 1000) {
|
||||||
{
|
|
||||||
const average = twilight_sensor.reduce((acc, c) => acc + c.value, 0) / twilight_sensor.length;
|
const average = twilight_sensor.reduce((acc, c) => acc + c.value, 0) / twilight_sensor.length;
|
||||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "lux_sensor", value: average });
|
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "lux_sensor", value: average });
|
||||||
|
|
||||||
|
|
@ -1093,10 +1008,8 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(type == "state_of_contactor")
|
else if (type == "state_of_contactor") {
|
||||||
{
|
if (!(deviceStatus["state_of_contactor"][line] == value)) {
|
||||||
if(!(deviceStatus["state_of_contactor"][line] == value))
|
|
||||||
{
|
|
||||||
sendNotification("switchLogic", rvoTbName, "state_of_contactor_for_line", { line: line, value: value }, "", SEND_TO.tb, instance);
|
sendNotification("switchLogic", rvoTbName, "state_of_contactor_for_line", { line: line, value: value }, "", SEND_TO.tb, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1145,26 +1058,22 @@ exports.install = function(instance) {
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(type === "state_of_breaker")
|
else if (type === "state_of_breaker") {
|
||||||
{
|
|
||||||
|
|
||||||
let valueChanged = false;
|
let valueChanged = false;
|
||||||
if (newPinValue != previousValues[pinIndex]) valueChanged = true;
|
if (newPinValue != previousValues[pinIndex]) valueChanged = true;
|
||||||
|
|
||||||
if(valueChanged)
|
if (valueChanged) {
|
||||||
{
|
|
||||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line });
|
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line });
|
||||||
|
|
||||||
//mame iba 3 istice. vyreportujeme a ohandlujeme liniu na tom istom istici ako paralelna linia (napr linia 1, paralelna s nou je linia 4, key je string "4")
|
//mame iba 3 istice. vyreportujeme a ohandlujeme liniu na tom istom istici ako paralelna linia (napr linia 1, paralelna s nou je linia 4, key je string "4")
|
||||||
// ak je 7 linii, na 1 istici je linia 1,4,7
|
// ak je 7 linii, na 1 istici je linia 1,4,7
|
||||||
|
|
||||||
if(line == 1)
|
if (line == 1) {
|
||||||
{
|
|
||||||
|
|
||||||
const lineOnSameBraker = [4, 7];
|
const lineOnSameBraker = [4, 7];
|
||||||
|
|
||||||
for (var i = 0; i < lineOnSameBraker.length; i++)
|
for (var i = 0; i < lineOnSameBraker.length; i++) {
|
||||||
{
|
|
||||||
if (!relaysData.hasOwnProperty(lineOnSameBraker[i])) continue;
|
if (!relaysData.hasOwnProperty(lineOnSameBraker[i])) continue;
|
||||||
|
|
||||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "state_of_breaker", value: value, line: lineOnSameBraker[i] });
|
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "state_of_breaker", value: value, line: lineOnSameBraker[i] });
|
||||||
|
|
@ -1180,12 +1089,10 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
const lineOnSameBraker = line + 3 + "";
|
const lineOnSameBraker = line + 3 + "";
|
||||||
|
|
||||||
if(relaysData.hasOwnProperty(lineOnSameBraker))
|
if (relaysData.hasOwnProperty(lineOnSameBraker)) {
|
||||||
{
|
|
||||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line + 3 });
|
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line + 3 });
|
||||||
|
|
||||||
deviceStatus["state_of_breaker"][line + 3] = value;
|
deviceStatus["state_of_breaker"][line + 3] = value;
|
||||||
|
|
@ -1210,8 +1117,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
values[type] = value;
|
values[type] = value;
|
||||||
|
|
||||||
if(type == "rotary_switch_state")
|
if (type == "rotary_switch_state") {
|
||||||
{
|
|
||||||
if (SETTINGS.maintenance_mode) value = "maintenance";
|
if (SETTINGS.maintenance_mode) value = "maintenance";
|
||||||
value = value.toLowerCase();
|
value = value.toLowerCase();
|
||||||
values["power_mode"] = value;
|
values["power_mode"] = value;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue