From 1c131d0b63d6289602b9859c7a1c02d2069d4954 Mon Sep 17 00:00:00 2001 From: rasta5man Date: Mon, 23 Sep 2024 17:57:23 +0200 Subject: [PATCH] loadRelaysData function removed from rsPort, DataToTbHandler-send data if broker not connected --- flow/cmd_manager.js | 56 +++++++++------------------------- flow/dido_controller.js | 4 +-- flow/helper/DataToTbHandler.js | 4 +-- flow/modbus_reader.js | 2 +- 4 files changed, 19 insertions(+), 47 deletions(-) diff --git a/flow/cmd_manager.js b/flow/cmd_manager.js index 613d1f6..43ffbcf 100644 --- a/flow/cmd_manager.js +++ b/flow/cmd_manager.js @@ -275,17 +275,19 @@ function processNodeProfile(node) return; } - let profile = nodeObj.profile; - logger.debug("processNodeProfile: start - set profile for ", node, profile); - let nodeProfile; - try { - nodeProfile = JSON.parse(profile); - if(Object.keys(nodeProfile).length === 0) throw ("profile is not defined"); - } catch (error) { - logger.debug("Error parsing node profile", error); - } + let nodeProfile = nodeObj.profile; + if(nodeProfile) { + + try { + nodeProfile = JSON.parse(nodeProfile); + if(Object.keys(nodeProfile).length === 0) throw ("profile is not defined"); + } catch (error) { + logger.debug("Error parsing node profile", error); + } + + } logger.debug("processNodeProfile", node, line, nodeObj, nodeProfile); @@ -293,7 +295,7 @@ function processNodeProfile(node) removeTask({type: "set_node_profile", address: node}); - if(nodeProfile === undefined) + if(nodeProfile === "") { //vypneme profil nodu, posleme cmd //Pokiaľ je hodnota rovná 1 – Profil sa zapne, ostatné bity sa nezmenia. @@ -1709,33 +1711,6 @@ exports.install = function(instance) { { tasks[0].timestamp = currentTimestamp + tasks[0].addMinutesToTimestamp * 60000; - //select nespracovane nody - //node:number|tbname:string|line:number|profile:string|processed:boolean|status:boolean - - //buildTasks({processLineProfiles: true, line: line}); - - /* - let keys = Object.keys(nodesData); - for(let i = 0; i < keys.length; i++) - { - let node = keys[i]; - let line = node.line; - - if(node.processed) continue; - - if(relaysData[line] != undefined) - { - let relayStatus = relaysData[line].contactor; - if(relayStatus == 1) - { - //linia je zapnuta - //await loadRelaysData(flowdata.data.line); - } - } - - } - */ - //vsetky linie kt. su zapnute, a spracuju sa nespracovane profily nodov loadRelaysData(); @@ -2143,7 +2118,7 @@ exports.install = function(instance) { let register = params.register; let type = params.type; let tbName = params.tbname; - tbName && (tbName = nodesData[node].tbname); + if(!tbName) return; let values = {}; @@ -2178,7 +2153,7 @@ exports.install = function(instance) { } // console.log("------",node, register, type, itIsNodeCommand, updateStatus, saveToTb, values); - if(saveToTb && Object.keys(values).length > 0 && tbName) + if(saveToTb && Object.keys(values).length > 0) { let dataToTb = { @@ -2318,7 +2293,7 @@ exports.install = function(instance) { logger.debug("CMD manager - rsPort opened sucess"); - loadRelaysData(); + //loadRelaysData(); await runSyncExec(`stty -F /dev/${FLOW.OMS_serial_port} 115200 min 1 time 5 ignbrk -brkint -icrnl -imaxbel -opost -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke`).then(function (status) { instance.send(SEND_TO.debug, "RPC runSyncExec - Promise Resolved:" + status); @@ -2353,7 +2328,6 @@ exports.install = function(instance) { rsPort.close(); }); - //loadRelaysData(); rsPort.open(); instance.on("close", () => { diff --git a/flow/dido_controller.js b/flow/dido_controller.js index 9e61344..1e8010e 100644 --- a/flow/dido_controller.js +++ b/flow/dido_controller.js @@ -235,7 +235,7 @@ exports.install = function(instance) { let responseStatus = await promisifyBuilder(dbStatus.find()); statusData = responseStatus[0]; // {thermometer: 'OK', em: 'OK', twilight_sensor: 'OK'} deviceStatus["temperature"] = statusData.thermometer; - + FLOW.OMS_rvo_tbname = relaysData[0].tbname; if(controller_type === "lm") @@ -1367,7 +1367,6 @@ exports.install = function(instance) { //ak bola predchadzajuci stav off a novy stav je on, budu sa nastavovat nespracovane node profiles //a budu sa odosielat commandy, tie vsak mozu zlyhat, a preto potrebujeme ich spusti trochu neskor - setTimeout(function(){ instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "reload_relays", line: line, time: time, value: value, dataChanged: dataChanged}); }, time); @@ -1439,7 +1438,6 @@ exports.install = function(instance) { } if(value == "Off") values["status"] = "NOK"; - deviceStatus["state_of_breaker"][line] = value; reportLineStatus(line); diff --git a/flow/helper/DataToTbHandler.js b/flow/helper/DataToTbHandler.js index 06dd438..6f532a3 100644 --- a/flow/helper/DataToTbHandler.js +++ b/flow/helper/DataToTbHandler.js @@ -34,7 +34,8 @@ class DataToTbHandler { if(!FLOW.OMS_brokerready) { - return dataToTb; + instance.send(this.index, dataToTb); + return; } let keys = Object.keys(dataToTb); @@ -92,7 +93,6 @@ class DataToTbHandler { //console.log(this.sender + " DATA SEND TO TB ", tbname, this.messageCounter, new Date(ts), dataToTbModified[tbname][0].values, this.instance); //if(this.debug) console.log(this.sender + " DATA SEND TO TB ", this.index, tbname, arrayOfValuesToSend); - instance.send(this.index, dataToTbModified); } diff --git a/flow/modbus_reader.js b/flow/modbus_reader.js index e253bb2..24a9580 100644 --- a/flow/modbus_reader.js +++ b/flow/modbus_reader.js @@ -146,7 +146,7 @@ exports.install = function(instance) { }).catch (function () { - console.log("errors pri citani modbus registra", register, obj.indexInDeviceConfig, tbName, tbAttribute); + //console.log("errors pri citani modbus registra", register, obj.indexInDeviceConfig, tbName, tbAttribute); obj.errors++; if(obj.errors == obj.lengthOfActualDeviceStream)