loadRelaysData function removed from rsPort, DataToTbHandler-send data if broker not connected

This commit is contained in:
rasta5man 2024-09-23 17:57:23 +02:00
parent ca39e1266c
commit 1c131d0b63
4 changed files with 19 additions and 47 deletions

View file

@ -275,25 +275,27 @@ function processNodeProfile(node)
return;
}
let profile = nodeObj.profile;
logger.debug("processNodeProfile: start - set profile for ", node, profile);
let nodeProfile;
let nodeProfile = nodeObj.profile;
if(nodeProfile) {
try {
nodeProfile = JSON.parse(profile);
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);
let timestamp = PRIORITY_TYPES.node_cmd;
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", () => {

View file

@ -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);

View file

@ -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);
}

View file

@ -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)