(1) DIverter threshold used, (2) UniCB state display can be enabled / disabled, ver. 3.1.1598

This commit is contained in:
Milan Hanajik
2021-03-19 16:22:50 +01:00
parent 595f0c514e
commit 141b9a7b4c
11 changed files with 80 additions and 55 deletions
+30 -20
View File
@@ -29,23 +29,33 @@ namespace TBF.Rig.Uni.Diverter
public static int DivertersCount { get { return nextIdx; } }
public static GenericDevices.IDiverter[] Diverters;
readonly DiverterCfg diverterCfg;
public SchematicDrawing.IDrawingItem DrawingItem { get { return diverterCfg as SchematicDrawing.IDrawingItem; } }
readonly DiverterCfg divCfg;
public SchematicDrawing.IDrawingItem DrawingItem { get { return divCfg as SchematicDrawing.IDrawingItem; } }
readonly UniCB cBoard;
readonly UInt128 mask; /// derived from bitPosition in the constructor
public int DiverterNr { get { return diverterCfg.DivNr1; } } /// 1-based public diverter number
public int AdcNr { get { return diverterCfg.AdcNr; } }
public int DiverterNr { get { return divCfg.DivNr1; } } /// 1-based public diverter number
public int AdcNr { get { return divCfg.AdcNr; } }
readonly IOperation diverterToTankOp;
readonly IOperation diverterToSinkOp;
public bool State { get { return (cBoard.Route & mask) != 0; } }
public int ThresholdGate { get { return diverterCfg.StartThresholdPct; } }
public int ThresholdLo { get { return diverterCfg.ThresholdLoPct; } }
public int ThresholdHi { get { return diverterCfg.ThresholdHiPct; } }
public int StartThreshold
{
get { return Math.Max(0, Math.Min(1023, Convert.ToInt32(divCfg.AdcValueToSink + (divCfg.AdcValueToTank - divCfg.AdcValueToSink) * (divCfg.StartThresholdPct / 100.0)))); }
}
public int ThresholdLo
{
get { return Math.Max(0, Math.Min(1023, Convert.ToInt32(divCfg.AdcValueToSink + (divCfg.AdcValueToTank - divCfg.AdcValueToSink) * (divCfg.ThresholdLoPct / 100.0)))); }
}
public int ThresholdHi
{
get { return Math.Max(0, Math.Min(1023, Convert.ToInt32(divCfg.AdcValueToSink + (divCfg.AdcValueToTank - divCfg.AdcValueToSink) * (divCfg.ThresholdHiPct / 100.0)))); }
}
FloatBox switchTimeStart;
FloatBox switchTimeEnd;
@@ -68,18 +78,18 @@ namespace TBF.Rig.Uni.Diverter
public Diverter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
diverterCfg = cfg as DiverterCfg;
divCfg = cfg as DiverterCfg;
cBoard = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
if (cBoard == null) throw new Exception("Cannot find " + Name + " parent");
if (cfg.DebugLevel != Config.Entities.DebugMode.Off)
{
if (diverterCfg.BitNr < 0 || diverterCfg.BitNr >= 64) throw new ArgumentOutOfRangeException("position");
this.mask = (((UInt128)1) << diverterCfg.BitNr);
if (divCfg.BitNr < 0 || divCfg.BitNr >= 64) throw new ArgumentOutOfRangeException("position");
this.mask = (((UInt128)1) << divCfg.BitNr);
switchTimeStart = new FloatBox(diverterCfg.DfltSwithTimeStartMs / 1000.0f);
switchTimeEnd = new FloatBox(diverterCfg.DfltSwithTimeEndMs / 1000.0f);
switchTimeStart = new FloatBox(divCfg.DfltSwithTimeStartMs / 1000.0f);
switchTimeEnd = new FloatBox(divCfg.DfltSwithTimeEndMs / 1000.0f);
///// Prepare arguments of SendCalibData()
//if (diverterCfg.AdcNr >= 0 && diverterCfg.AdcNr < cBoard.RegValveCalib.GetLength(0))
@@ -105,7 +115,7 @@ namespace TBF.Rig.Uni.Diverter
///
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = diverterCfg.CalibValidDate;
DateTime calibrationDue = divCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
@@ -141,8 +151,8 @@ namespace TBF.Rig.Uni.Diverter
public void Initialize() { }
public void RunDeviceBefore()
{
Int16 adcValue = cBoard.Data.AnalogInput[diverterCfg.AdcNr];
Handlers.OnAdcChanged(this, new CmdResponseArgs(CfgChangeCmd.GetAdc, diverterCfg.BitNr, adcValue));
Int16 adcValue = cBoard.Data.AnalogInput[divCfg.AdcNr];
Handlers.OnAdcChanged(this, new CmdResponseArgs(CfgChangeCmd.GetAdc, divCfg.BitNr, adcValue));
}
public void RunDeviceAfter() { }
public void StopDevice() { }
@@ -191,20 +201,20 @@ namespace TBF.Rig.Uni.Diverter
}
else if (args.Command == CfgChangeCmd.GetAdc1 || args.Command == CfgChangeCmd.GetAdc2)
{
Int16 adcValue = cBoard.Data.AnalogInput[diverterCfg.AdcNr];
DiverterCfgCtrl.OnCmdResponse(this, new CmdResponseArgs(args.Command, diverterCfg.BitNr, adcValue));
Int16 adcValue = cBoard.Data.AnalogInput[divCfg.AdcNr];
DiverterCfgCtrl.OnCmdResponse(this, new CmdResponseArgs(args.Command, divCfg.BitNr, adcValue));
}
else if (args.Command == CfgChangeCmd.DivToTank)
{
cBoard.SwitchDiverter(true, diverterCfg.DivNr1, true);
cBoard.SwitchDiverter(true, divCfg.DivNr1, true);
}
else if (args.Command == CfgChangeCmd.DivToSink)
{
cBoard.SwitchDiverter(true, diverterCfg.DivNr1, false);
cBoard.SwitchDiverter(true, divCfg.DivNr1, false);
}
else if (args.Command == CfgChangeCmd.ReadDivTransition)
{
cBoard.ReadDiverterTransition(true, diverterCfg.DivNr1);
cBoard.ReadDiverterTransition(true, divCfg.DivNr1);
}
}
};