2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2020-05-06 07:45:23 +00:00
|
|
|
|
/// Copyright (c) 2013-2020 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;
|
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
|
|
|
|
|
|
|
|
|
|
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
|
|
|
|
|
|
{
|
|
|
|
|
|
DateTime calibrationDue = tempMtrCfg.CalibValidDate;
|
|
|
|
|
|
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
|
|
|
|
|
|
|
|
|
|
|
|
if (calibrationDue > TBF.UI.Constants.MinDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Calibration due date calendar event
|
|
|
|
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
|
|
|
|
|
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Weekly reminders (last 5 weeks)
|
|
|
|
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
|
|
|
|
|
|
false));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (DateTime.Now.Date <= calibrationDue.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Daily reminders (last 5 days)
|
|
|
|
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
|
|
|
|
|
|
true));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return calendarEvents;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-04-10 14:10:44 +00:00
|
|
|
|
return Config.Formulas.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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|