actual working Senica Rvo code 09/2024
This commit is contained in:
parent
f4ffef94b9
commit
8929cc3a53
7 changed files with 810 additions and 429 deletions
|
|
@ -14,8 +14,8 @@ exports.readme = `
|
|||
This device needs to be configured in dido_controller!!! Double check if it is. In dido_controller we calculate final status and all values with status are pushed to tb.
|
||||
`;
|
||||
|
||||
const modbus = require('jsmodbus')
|
||||
const SerialPort = require('serialport')
|
||||
const modbus = require('jsmodbus');
|
||||
const SerialPort = require('serialport');
|
||||
const { timeoutInterval, deviceConfig } = require("../databases/modbus_config");
|
||||
const { sendNotification } = require('./helper/notification_reporter');
|
||||
|
||||
|
|
@ -30,6 +30,8 @@ const SEND_TO = {
|
|||
//to handle NOK and OK sendNotifications s
|
||||
const numberOfNotResponding = {};
|
||||
let tbName = null;
|
||||
let mainSocket;
|
||||
|
||||
|
||||
exports.install = function(instance) {
|
||||
|
||||
|
|
@ -50,6 +52,10 @@ exports.install = function(instance) {
|
|||
this.lengthOfActualDeviceStream = null;
|
||||
this.device = null;
|
||||
|
||||
// lampSwitchNotification helper variables
|
||||
this.onNotificationSent = false;
|
||||
this.offNotificationSent = false;
|
||||
|
||||
this.startSocket();
|
||||
}
|
||||
|
||||
|
|
@ -215,6 +221,7 @@ exports.install = function(instance) {
|
|||
};
|
||||
|
||||
this.checkNullVoltage(values);
|
||||
this.lampSwitchNotification(values);
|
||||
|
||||
instance.send(SEND_TO.dido_controller, {values: values});
|
||||
|
||||
|
|
@ -243,32 +250,6 @@ exports.install = function(instance) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// sendFinalObjects = (values) =>
|
||||
// {
|
||||
|
||||
// const date = Date.now();
|
||||
// // values["status"] = "OK";
|
||||
|
||||
// const dataToTB = {
|
||||
// [tbName]: [
|
||||
// {
|
||||
// "ts": date,
|
||||
// "values": values
|
||||
// }
|
||||
// ]
|
||||
// };
|
||||
|
||||
// instance.send(SEND_TO.tb, dataToTB);
|
||||
|
||||
// const dataToDiDo = {
|
||||
// values: values
|
||||
// }
|
||||
|
||||
// instance.send(SEND_TO.dido_controller, dataToDiDo);
|
||||
// }
|
||||
|
||||
|
||||
calculateValue = (response, multiplier) =>
|
||||
{
|
||||
let value = 0;
|
||||
|
|
@ -296,7 +277,6 @@ exports.install = function(instance) {
|
|||
return Math.round(value * multiplier * 10) / 10;
|
||||
}
|
||||
|
||||
|
||||
checkNullVoltage = (values) => {
|
||||
|
||||
if(!(values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_2_voltage") || values.hasOwnProperty("Phase_3_voltage"))) return;
|
||||
|
|
@ -313,19 +293,41 @@ exports.install = function(instance) {
|
|||
if(values[singleValue] == 0)
|
||||
{
|
||||
FLOW.OMS_no_voltage.add(phase);
|
||||
sendNotification("modbus_citys: checkNullVoltage", tbName, "no_voltage_on_phase", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase );
|
||||
sendNotification("modbus_reader: checkNullVoltage", tbName, "no_voltage_on_phase", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase );
|
||||
// console.log('no voltage')
|
||||
}
|
||||
else
|
||||
{
|
||||
FLOW.OMS_no_voltage.delete(phase);
|
||||
// console.log('voltage detected')
|
||||
sendNotification("modbus_citys: checkNullVoltage", tbName, "voltage_on_phase_restored", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase);
|
||||
sendNotification("modbus_reader: checkNullVoltage", tbName, "voltage_on_phase_restored", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* function sends notification to slack and to tb, if EM total_power value changes more than 500. This should show, that RVO lamps has been switched on or off
|
||||
*/
|
||||
lampSwitchNotification = (values) => {
|
||||
|
||||
if(!values.hasOwnProperty("total_power")) return;
|
||||
|
||||
const actualTotalPower = values.total_power;
|
||||
if(actualTotalPower > 600 && this.onNotificationSent == false)
|
||||
{
|
||||
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_on", {}, "", SEND_TO.tb, instance);
|
||||
this.onNotificationSent = true;
|
||||
this.offNotificationSent = false;
|
||||
}
|
||||
else if(actualTotalPower <= 600 && this.offNotificationSent == false)
|
||||
{
|
||||
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_off", {}, "", SEND_TO.tb, instance);
|
||||
this.onNotificationSent = false;
|
||||
this.offNotificationSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const isObjectEmpty = (objectName) => {
|
||||
|
|
@ -333,8 +335,14 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const newSocket = new SocketWithClients();
|
||||
|
||||
mainSocket = new SocketWithClients();
|
||||
tbName = FLOW.OMS_rvo_tbname;
|
||||
|
||||
// this notification is to show, that flow (unipi) has been restarted
|
||||
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
|
||||
|
||||
}, 25000);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue