Fake accelerometer and handle hasMainSwitch
This commit is contained in:
parent
5233aa38af
commit
d97d90cf95
11 changed files with 3692 additions and 549 deletions
|
|
@ -35,16 +35,16 @@ pins number 11, 12, 13 (we receive 10,11,12 in rsPortReceivedData) are "stykace"
|
|||
When port receives data, it must be exactly 4 bytes long. Second byte is pin, that changed its value, fourth byte is value itself.
|
||||
After that, we set this value to "previousValues[allPins[whichpin]]" variable
|
||||
|
||||
state_of_main_switch - reportovať stav hlavného ističa : 0-> off 1-> on
|
||||
rotary_switch_state - sem by sa mal reportovať stav vstupov manual a auto podľa nasledovnej logiky: Manual = 1 a Auto = 0 -> Manual,
|
||||
state_of_main_switch - reportovat stav hlaveho istica : 0-> off 1-> on
|
||||
rotary_switch_state - sem by sa mal reportovat stav vstupov manual a auto pola nasledovnej logiky: Manual = 1 a Auto = 0 -> Manu
|
||||
Manual = 0 a Auto = 0 -> Off, Manual = 0 a Auto = 1 -> Automatic
|
||||
|
||||
door_condition - pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Open
|
||||
twilight_sensor - hodnotu, ktorú vracia ten analógový vstup (17) treba poslať sem ako float number. Zrejme tu potom pridáme nejaký koeficient prevodu na luxy
|
||||
door_condition - pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Ope
|
||||
twilight_sensor - hodnotu, ktoru vracia ten analogovy vstup (17) treba poslat sem ako float number. Zrejme tu potom pridame nejaky koeficient prevodu na luxy
|
||||
|
||||
Na každú líniu:
|
||||
state_of_breaker - podľa indexu ističa sa reportuje jeho stav, teda istič 1 na líniu 1: 0-> off, 1-> on
|
||||
state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač 1 na líniu 1: 0-> off, 1-> on
|
||||
Na kazdu liniu
|
||||
state_of_breaker - podla indexu istica sa reportuje jeho stav, teda istic na liniu 1: 0-> off, 1-> on
|
||||
state_of_contactor - podla indexu stkaca sa reportuje jeho stav, teda stykac 1 na liniu 1: 0-> off, 1-> on
|
||||
*/
|
||||
|
||||
const { errLogger, logger, monitor } = require('./helper/logger');
|
||||
|
|
@ -70,6 +70,7 @@ let rvoTbName;
|
|||
let GLOBALS; //FLOW global GLOBALS
|
||||
let SETTINGS; // GLOBALS.settings
|
||||
let controller_type;
|
||||
let hasMainSwitch;
|
||||
|
||||
let alarmStatus = "OFF";
|
||||
|
||||
|
|
@ -126,17 +127,17 @@ exports.install = function(instance) {
|
|||
|
||||
//status for calculating Statecodes
|
||||
let deviceStatus = { //key is device name: temperature,....
|
||||
"state_of_main_switch": "Off", //Hlavný istič (po novom druhy dverovy kontakt)
|
||||
"rotary_switch_state": "Off", //Prevádzkový mód
|
||||
"state_of_main_switch": "Off", //Hlavny istic (alebo druhy dverovy kontakt)
|
||||
"rotary_switch_state": "Off", //Prevadzkovy
|
||||
"door_condition": "closed", //Dverový kontakt
|
||||
"em": "OK", //elektromer rvo
|
||||
"temperature": "OK", //templomer
|
||||
"battery": "OK", //Batéria
|
||||
"battery": "OK", //Bateria
|
||||
"power_supply": "OK", //Zdroj
|
||||
"master_node": "OK", //MN - GLOBALS.settings.masterNodeIsResponding
|
||||
"no_voltage": "OK", //GLOBALS.settings.no_voltage - výpadok napätia na fáze
|
||||
"state_of_breaker": {}, //"Off",//Istič
|
||||
"state_of_contactor": {}, //"Off",//Stykač
|
||||
"no_voltage": "OK", //GLOBALS.settings.no_voltage - vypadok napatia na faze
|
||||
"state_of_breaker": {}, //"Off",//Istic
|
||||
"state_of_contactor": {}, //"Off",//Stykac
|
||||
"twilight_sensor": "OK" //lux sensor
|
||||
};
|
||||
|
||||
|
|
@ -149,10 +150,12 @@ exports.install = function(instance) {
|
|||
pinsData = GLOBALS.pinsData;
|
||||
relaysData = GLOBALS.relaysData;
|
||||
|
||||
tbHandler = new DataToTbHandler(SEND_TO.tb)
|
||||
tbHandler = new DataToTbHandler(SEND_TO.tb);
|
||||
tbHandler.setSender(exports.title);
|
||||
|
||||
controller_type = SETTINGS.controller_type //"lm" or "unipi" //logicMachine
|
||||
controller_type = SETTINGS.controller_type; //"lm" or "unipi"
|
||||
hasMainSwitch = SETTINGS.has_main_switch;
|
||||
|
||||
if (controller_type == "") controller_type = "lm";
|
||||
|
||||
console.log(exports.title, "controller type: ", controller_type);
|
||||
|
|
@ -596,27 +599,27 @@ exports.install = function(instance) {
|
|||
|
||||
let bits = [];
|
||||
|
||||
//Hlavný istič - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
|
||||
if (deviceStatus["state_of_main_switch"] == "closed") {
|
||||
//Hlavny istic - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
|
||||
if (deviceStatus["state_of_main_switch"] === "closed" || deviceStatus["state_of_main_switch"] === "Off") {
|
||||
bits.push(0);
|
||||
}
|
||||
else {
|
||||
bits.push(1);
|
||||
}
|
||||
|
||||
//Prevádzkový mód - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
||||
//Prevadzkovy mod - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
||||
if (!SETTINGS.maintenance_mode) {
|
||||
if (deviceStatus["rotary_switch_state"] == "Manual") {
|
||||
if (deviceStatus["rotary_switch_state"] === "Manual") {
|
||||
bits.push(0);
|
||||
bits.push(1);
|
||||
}
|
||||
|
||||
if (deviceStatus["rotary_switch_state"] == "Automatic") {
|
||||
if (deviceStatus["rotary_switch_state"] === "Automatic") {
|
||||
bits.push(0);
|
||||
bits.push(0);
|
||||
}
|
||||
|
||||
if (deviceStatus["rotary_switch_state"] == "Off") {
|
||||
if (deviceStatus["rotary_switch_state"] === "Off") {
|
||||
bits.push(1);
|
||||
bits.push(0);
|
||||
}
|
||||
|
|
@ -626,8 +629,8 @@ exports.install = function(instance) {
|
|||
bits.push(1);
|
||||
}
|
||||
|
||||
//Dverový kontakt
|
||||
if (deviceStatus["door_condition"] == "closed") {
|
||||
//Dverovy kontakt
|
||||
if (deviceStatus["door_condition"] === "closed") {
|
||||
bits.push(0);
|
||||
}
|
||||
else {
|
||||
|
|
@ -635,7 +638,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
//EM
|
||||
if (deviceStatus["em"] == "NOK") {
|
||||
if (deviceStatus["em"] === "NOK") {
|
||||
bits.push(1);
|
||||
}
|
||||
else {
|
||||
|
|
@ -643,7 +646,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
//Teplomer
|
||||
if (deviceStatus["temperature"] == "NOK") {
|
||||
if (deviceStatus["temperature"] === "NOK") {
|
||||
bits.push(1);
|
||||
}
|
||||
else {
|
||||
|
|
@ -651,7 +654,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
//Batéria
|
||||
if (deviceStatus["battery"] == "NOK") {
|
||||
if (deviceStatus["battery"] === "NOK") {
|
||||
bits.push(1);
|
||||
}
|
||||
else {
|
||||
|
|
@ -659,7 +662,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
//Zdroj
|
||||
if (deviceStatus["power_supply"] == "NOK") {
|
||||
if (deviceStatus["power_supply"] === "NOK") {
|
||||
bits.push(1);
|
||||
}
|
||||
else {
|
||||
|
|
@ -667,7 +670,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
//MN
|
||||
if (deviceStatus["master_node"] == "NOK") {
|
||||
if (deviceStatus["master_node"] === "NOK") {
|
||||
bits.push(1);
|
||||
}
|
||||
else {
|
||||
|
|
@ -675,14 +678,14 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
//výpadok napätia na fáze
|
||||
if (deviceStatus["no_voltage"] == "NOK") {
|
||||
if (deviceStatus["no_voltage"] === "NOK") {
|
||||
bits.push(1);
|
||||
}
|
||||
else {
|
||||
bits.push(0);
|
||||
}
|
||||
|
||||
if (deviceStatus["twilight_sensor"] == "NOK") {
|
||||
if (deviceStatus["twilight_sensor"] === "NOK") {
|
||||
bits.push(1);
|
||||
}
|
||||
else {
|
||||
|
|
@ -738,6 +741,26 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
|
||||
function getPins(controllerType, hasMainSwitch) {
|
||||
|
||||
let pins = [];
|
||||
|
||||
if (controllerType === "lm") {
|
||||
pins = [1, 4, 6];
|
||||
if (hasMainSwitch === 1) {
|
||||
pins = [4, 6];
|
||||
}
|
||||
} else if (controllerType === "unipi") {
|
||||
pins = ["input1_01", "input1_04", "input1_05"];
|
||||
if (hasMainSwitch === 1) {
|
||||
pins = ["input1_01", "input1_04"];
|
||||
}
|
||||
}
|
||||
|
||||
return pins;
|
||||
}
|
||||
|
||||
|
||||
function checkRvoStatus() {
|
||||
|
||||
// we check if any of these pins values are 0 --> it means status RVO is "NOK"
|
||||
|
|
@ -746,12 +769,12 @@ exports.install = function(instance) {
|
|||
let status = "OK";
|
||||
|
||||
for (const [key, value] of Object.entries(deviceStatus)) {
|
||||
if (["em", "twilight_sensor", "temperature", "master_node"].includes(key) && value == "NOK") status = "NOK";
|
||||
if (["em", "twilight_sensor", "temperature", "master_node"].includes(key) && value === "NOK") status = "NOK";
|
||||
}
|
||||
|
||||
if (status == "OK") {
|
||||
let pinIndexes = [1, 4, 6];
|
||||
if (controller_type == 'unipi') pinIndexes = ['input1_01', 'input1_04', 'input1_05'];
|
||||
if (status === "OK") {
|
||||
|
||||
let pinIndexes = getPins(controller_type, hasMainSwitch);
|
||||
|
||||
for (const pinIndex of pinIndexes) {
|
||||
if (previousValues[pinIndex] === 0) {
|
||||
|
|
@ -807,8 +830,20 @@ exports.install = function(instance) {
|
|||
let value = "On";
|
||||
if (newPinValue === 0) value = "Off";
|
||||
|
||||
//Prevádzkový mód
|
||||
if (type == "rotary_switch_state") {
|
||||
//Hlavny istic
|
||||
if (type === "state_of_main_switch" && hasMainSwitch) {
|
||||
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) {
|
||||
sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance, "state_of_main_switch");
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
//Prevadzkovy mod
|
||||
else if (type == "rotary_switch_state") {
|
||||
// combination of these two pins required to get result
|
||||
let pin2, pin3;
|
||||
if (pinIndex == 2 || pinIndex == "input1_02") {
|
||||
|
|
@ -860,7 +895,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
}
|
||||
|
||||
//Batéria - pin 5
|
||||
//Bateria - pin 5
|
||||
else if (type === "battery") {
|
||||
if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
|
||||
sendNotification("switchLogic", rvoTbName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
|
||||
|
|
@ -874,9 +909,8 @@ exports.install = function(instance) {
|
|||
}
|
||||
}
|
||||
|
||||
//Dverový kontakt - pin 6
|
||||
//! 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'
|
||||
//Dverovy kontakt - pin 6
|
||||
//! Ak je rvo s dvoma dverovymi kontaktami, ked pride z evoku signal z input1_05, co bol predytm "state_of_main switch" handlujeme ho teraz ako 'door_condition'
|
||||
else if (type == "door_condition" || type === "state_of_main_switch") {
|
||||
newPinValue === 0 ? value = "open" : value = "closed";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue