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-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
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.TempMeter
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2020-05-06 07:45:23 +00:00
|
|
|
|
public class TempMeter : ComponentBase, GenericDevices.ITempMeter, GenericDevices.IHasCalendarEvents
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TempMeter));
|
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
|
|
|
|
|
2014-12-31 12:46:33 +00:00
|
|
|
|
readonly TempMeterCfg tempMtrCfg;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
public readonly ControlBoardDev ControlBoard;
|
|
|
|
|
|
|
2019-03-13 07:29:30 +00:00
|
|
|
|
public int Idx0 { get { return tempMtrCfg.Idx0; } } /// 0..15
|
2016-12-05 22:22:33 +00:00
|
|
|
|
public double A1 { get { return tempMtrCfg.A1; } }
|
|
|
|
|
|
public double A2 { get { return tempMtrCfg.A2; } }
|
|
|
|
|
|
public double A3 { get { return tempMtrCfg.A3; } }
|
|
|
|
|
|
public double A4 { get { return tempMtrCfg.A4; } }
|
|
|
|
|
|
public double A5 { get { return tempMtrCfg.A5; } }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
|
|
|
|
|
|
public TempMeter() { }
|
2015-06-29 09:14:33 +00:00
|
|
|
|
|
2016-08-05 12:32:36 +00:00
|
|
|
|
public TempMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
: base(cfg)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2016-08-05 12:32:36 +00:00
|
|
|
|
tempMtrCfg = cfg as TempMeterCfg;
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
/// Prepare data for SendCalibData() control board component method
|
2016-12-05 22:22:33 +00:00
|
|
|
|
ControlBoard.TempCalibData[Idx0, 0] = (float)A1;
|
|
|
|
|
|
ControlBoard.TempCalibData[Idx0, 1] = (float)A2;
|
|
|
|
|
|
ControlBoard.TempCalibData[Idx0, 2] = (float)A3;
|
|
|
|
|
|
ControlBoard.TempCalibData[Idx0, 3] = (float)A4;
|
|
|
|
|
|
ControlBoard.TempCalibData[Idx0, 4] = (float)A5;
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-06 07:45:23 +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 = tempMtrCfg.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-10-07 13:33:56 +00:00
|
|
|
|
public double ReadTemperature()
|
2016-07-07 09:02:35 +00:00
|
|
|
|
{
|
2021-09-23 09:46:40 +00:00
|
|
|
|
if (Cfg.DebugLevel == DebugMode.Normal)
|
2016-12-05 22:22:33 +00:00
|
|
|
|
{
|
2022-01-23 18:56:15 +00:00
|
|
|
|
return Config.Entities.MeasurementCorrection.CorrectedValue((double)ControlBoard.Temperature(Idx0), Corrections);
|
2016-12-05 22:22:33 +00:00
|
|
|
|
}
|
2021-09-23 09:46:40 +00:00
|
|
|
|
else if (Cfg.DebugLevel == DebugMode.Simulate)
|
2016-12-05 22:22:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
return tempMtrCfg.DefaultTemperature;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2016-07-07 09:02:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Events: TempDone, Error
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="temp">Reference to a variable for the temperature in Celsius</param>
|
|
|
|
|
|
/// <returns>ReadTempOp instance reference casted to IOperaton</returns>
|
2016-10-07 13:33:56 +00:00
|
|
|
|
public IOperation ReadTempOp(ref DoubleBox temp)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
return new ReadTempOp(this, ref temp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Events: tempDone, Error
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="temp">Reference to a variable for the temperature in Celsius</param>
|
|
|
|
|
|
/// <param name="tempDone">Event returned when measurement done</param>
|
|
|
|
|
|
/// <returns>ReadTempOp instance reference casted to IOperaton</returns>
|
2016-10-07 13:33:56 +00:00
|
|
|
|
public IOperation ReadTempOp(ref DoubleBox temp, Event tempDone)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
return new ReadTempOp(this, ref temp, tempDone);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|