tbf/TestBenchFramework/BenchControl/Elde/Diverter/Diverter.cs

37 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using log4net;
namespace TBF.BenchControl.Elde.Diverter
{
public class Diverter : ComponentBase, GenericDevices.IDiverter
{
private static readonly ILog log = LogManager.GetLogger(typeof(Diverter));
public override string ToString() { return string.Format("Diverter({0})", Cfg.ToString(1)); }
readonly DiverterCfg diverterCfg;
readonly ControlBoardDev controlBoard;
2014-12-29 23:17:45 +00:00
readonly ulong mask; /// derived from bitPosition in the constructor
public bool State
{
get { return (controlBoard.Route & mask) != 0; }
}
public Diverter(DiverterCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
diverterCfg = cfg;
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
if (cfg.BitPosition < 0 || cfg.BitPosition >= 64) throw new ArgumentOutOfRangeException("position");
2014-12-29 23:17:45 +00:00
this.mask = (((ulong)1) << cfg.BitPosition);
log.Debug(this.ToString());
}
}
}