2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
2021-10-26 09:23:57 +00:00
|
|
|
|
using TBF.Rig.Generic;
|
2014-07-31 15:04:09 +00:00
|
|
|
|
using TBF.Boxes;
|
2020-05-06 07:45:23 +00:00
|
|
|
|
using TBF.Resources;
|
2023-04-18 12:01:23 +00:00
|
|
|
|
using TBF.UI.Calendar;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.Elde.PressureMeter
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2020-05-06 07:45:23 +00:00
|
|
|
|
public class PressureMeter : ComponentBase, GenericDevices.IPressureMeter, GenericDevices.IHasCalendarEvents
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(PressureMeter));
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
readonly PressureMeterCfg pressureMeterCfg;
|
|
|
|
|
|
|
|
|
|
|
|
public readonly ControlBoardDev ControlBoard;
|
|
|
|
|
|
|
2014-09-10 10:05:49 +00:00
|
|
|
|
public readonly int Idx0; /// 0..3
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public readonly byte RS485Address; /// 0..255
|
|
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
|
|
|
|
|
|
public PressureMeter() { }
|
2015-06-29 09:14:33 +00:00
|
|
|
|
|
2016-08-05 12:32:36 +00:00
|
|
|
|
public PressureMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
|
|
|
|
: base(cfg)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2016-08-05 12:32:36 +00:00
|
|
|
|
pressureMeterCfg = cfg as PressureMeterCfg;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
ControlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
|
|
|
|
if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
|
|
|
|
|
|
2016-08-05 12:32:36 +00:00
|
|
|
|
Idx0 = pressureMeterCfg.Idx0;
|
2018-12-18 06:55:13 +00:00
|
|
|
|
RS485Address = pressureMeterCfg.RS485Address;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// Prepare data for SendCalibData() control board component method
|
2014-09-10 10:05:49 +00:00
|
|
|
|
ControlBoard.MeretRS485Address[Idx0] = RS485Address;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2021-09-23 09:46:40 +00:00
|
|
|
|
if (pressureMeterCfg.Protocol == Common.MeretProtocol.Undefined)
|
2018-12-18 06:55:13 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("Metret protocol not defined");
|
|
|
|
|
|
}
|
2021-09-23 09:46:40 +00:00
|
|
|
|
else if (pressureMeterCfg.Protocol == Common.MeretProtocol.Modbus)
|
2018-12-18 06:55:13 +00:00
|
|
|
|
{
|
|
|
|
|
|
ControlBoard.MeretProtocol |= (byte)(1 << Idx0);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-02 08:47:51 +00:00
|
|
|
|
|
2023-04-18 12:01:23 +00:00
|
|
|
|
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
|
2020-05-06 07:45:23 +00:00
|
|
|
|
|
2023-04-18 12:01:23 +00:00
|
|
|
|
DateTime calibDue = pressureMeterCfg.CalibValidDate;
|
|
|
|
|
|
if (calibDue > TBF.UI.Constants.MinDate)
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Five weekly notifications
|
|
|
|
|
|
foreach (var days in new int[] { -35, -28, -21, -14 })
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
|
|
|
|
|
|
calibDue.Date.AddDays(days),
|
|
|
|
|
|
Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
|
|
|
|
|
}
|
2020-05-06 07:45:23 +00:00
|
|
|
|
}
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
/// Five daily warnings
|
|
|
|
|
|
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Weekly reminders (last 5 weeks)
|
|
|
|
|
|
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
|
|
|
|
|
|
calibDue.Date.AddDays(days),
|
|
|
|
|
|
Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Calibration due date
|
|
|
|
|
|
if (calibDue.Date >= DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
|
|
|
|
|
|
Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
2020-05-06 07:45:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
return calEvents;
|
2020-05-06 07:45:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-02 08:47:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the water pressure
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>Pressure in mBar</returns>
|
|
|
|
|
|
public float ReadPressure()
|
|
|
|
|
|
{
|
2022-01-23 18:56:15 +00:00
|
|
|
|
double rawPressure = Common.Units.ConvertFrom(Common.Unit.kPa, ControlBoard.Pressure(Idx0));
|
|
|
|
|
|
double correctedPressure = Config.Entities.MeasurementCorrection.CorrectedValue(rawPressure, Corrections);
|
2019-03-04 08:19:40 +00:00
|
|
|
|
return (float)correctedPressure;
|
2016-08-02 08:47:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Events: PressureDone, Error
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="pressure">Reference to a variable for the pressure in Bar</param>
|
|
|
|
|
|
/// <returns>ReadPressureOp instance reference casted to IOperaton</returns>
|
|
|
|
|
|
public IOperation ReadPressureOp(ref FloatBox pressure)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ReadPressureOp(this, ref pressure);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Events: pressureDone, Error
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="pressure">Reference to a variable for the pressure in Bar</param>
|
|
|
|
|
|
/// <param name="pressureDone">Event returned when measurement done</param>
|
|
|
|
|
|
/// <returns>ReadPressureOp instance reference casted to IOperaton</returns>
|
|
|
|
|
|
public IOperation ReadPressureOp(ref FloatBox pressure, Event pressureDone)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ReadPressureOp(this, ref pressure, pressureDone);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|