add buildTasks function to dido_controller and handle 7 lines with state_of_braker

This commit is contained in:
rasta5man 2024-05-07 16:28:43 +02:00
parent ac2ccc1c61
commit 86c7b3a942
3 changed files with 5940 additions and 5907 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@ exports.title = 'Modbus reader';
exports.version = '2.0.0';
exports.group = 'Worksys';
exports.color = '#2134B0';
exports.output = ["red", "white"];
exports.output = ["red", "white", "yellow"];
exports.click = false;
exports.author = 'Rastislav Kovac';
exports.icon = 'bolt';
@ -24,16 +24,18 @@ const errorHandler = new ErrorToServiceHandler();
const { sendNotification } = require('./helper/notification_reporter');
const DELAY_BETWEEN_DEVICES = 10000;
const instanceSendTo = {
debug: 0,
dido_controller: 1,
tb: 2
};
//to handle NOK and OK sendNotifications s
const numberOfNotResponding = {};
let tbName = null;
exports.install = function(instance) {
class SocketWithClients {
@ -86,7 +88,7 @@ exports.install = function(instance) {
this.socket.on('open', function () {
console.log("socket connected");
obj.getActualStreamAndDevice();
obj.timeoutInterval = timeoutInterval;
obj.timeoutInterval = timeoutInterval - DELAY_BETWEEN_DEVICES; // to make sure readout always runs in timeoutinterval we substract DELAY_BETWEEN_DEVICES
})
};
@ -101,7 +103,7 @@ exports.install = function(instance) {
this.device = dev.device; //em340, twilight_sensor
if(this.indexInDeviceConfig == 0) setTimeout(this.readRegisters, this.timeoutInterval);
else setTimeout(this.readRegisters, 2000);
else setTimeout(this.readRegisters, DELAY_BETWEEN_DEVICES);
}
readRegisters = () => {
@ -139,9 +141,7 @@ exports.install = function(instance) {
obj.error = 0;
obj.index++;
if(obj.index < obj.lengthOfActualDeviceStream) setTimeout(obj.readRegisters, 0);
else obj.setNewStream();
obj.readAnotherRegister();
}).catch (function () {
@ -177,12 +177,16 @@ exports.install = function(instance) {
}))
obj.index++;
if(obj.index < obj.lengthOfActualDeviceStream) setTimeout(obj.readRegisters, 0);
else obj.setNewStream();
obj.readAnotherRegister();
})
};
readAnotherRegister = () => {
if(this.index < this.lengthOfActualDeviceStream) setTimeout(this.readRegisters, 0);
else this.setNewStream();
}
transformResponse = (response, register, deviceAddress) => {
for (let i = 0; i < this.lengthOfActualDeviceStream; i++) {