/// <summary> /// Create gas endpoints for testing, port 1 contains fresh air and port 2 contains default 4-gas cylinder /// Change gas endpoints as needed for your testing if default configuration is not what you wanted. /// </summary> /// <param name="components"></param> /// <returns></returns> internal static List <GasEndPoint> GetGasEndPointsForTest(List <InstalledComponent> components) { List <GasEndPoint> gasEndPoints = new List <GasEndPoint>(); //Port 1 is fresh air gasEndPoints.Add(GasEndPoint.CreateFreshAir(1)); //Port 2, add 4-gas cylinder Cylinder cyl = new Cylinder("1810-9155", "ISC") { ExpirationDate = DateTime.Today.AddDays(30), Pressure = PressureLevel.Full }; cyl.GasConcentrations.AddRange(new List <GasConcentration>() { new GasConcentration(GasType.Cache[GasCode.CO.ToString()], 100.00), new GasConcentration(GasType.Cache[GasCode.H2S.ToString()], 25.00), new GasConcentration(GasType.Cache[GasCode.Pentane.ToString()], 3521.10), new GasConcentration(GasType.Cache[GasCode.O2.ToString()], 180000.00) }); gasEndPoints.Add(new GasEndPoint(cyl, 2, GasEndPoint.Type.Manual)); return(gasEndPoints); }
/// <summary> /// Return the information from all smart cards that are present. /// </summary> /// <returns>All of the installed cylinders.</returns> static private void ReadChangedCylinders(bool[] changedSmartCards, IList <GasEndPoint> changedGasEndPoints, PortRestrictions port1Restrictions) { const string funcName = "ReadChangedCylinders: "; Log.Assert(changedSmartCards != null, funcName + "changedSmartCards should not be null."); DockingStation dockingStation = Controller.GetDockingStation(); // SGF 8-Nov-2012 INS-2686 changedGasEndPoints.Clear(); for (int i = 0; i < changedSmartCards.Length; i++) { int position = i + 1; Log.Debug(funcName + "POSITION " + position); if (changedSmartCards[position - 1] == false) // No detection of a card insertion, nor a removal? { Log.Debug(string.Format("{0}Position {1} Smart card SKIPPED; No insertion change detected.", funcName, position)); if (position == Controller.FRESH_AIR_GAS_PORT) { GasEndPoint persistedPort1GasEndPoint = new GasEndPointDataAccess().FindByPosition(Controller.FRESH_AIR_GAS_PORT); // If there's nothing known to be installed on port 1, then create a fresh air // cylinder for the port. // This could happen if, while nothing was installed on the port, a SettingsUpdate // just occurred previously where the port setting was changed to allow fresh air. // In that situation, we have to then make the fresh air cylinder. if (persistedPort1GasEndPoint == null) { Log.Debug(string.Format("{0}Position {1}, No persisted cylinder; assuming Fresh Air.", funcName, position)); GasEndPoint freshAirCylinder = GasEndPoint.CreateFreshAir(position); freshAirCylinder.GasChangeType = GasEndPoint.ChangeType.Installed; changedGasEndPoints.Add(freshAirCylinder); } } // SGF 8-Nov-2012 INS-2686 -- begin // Soon, we will check to see if a pressure switch is present, and if so, read the pressure level. // Before we do that, we must check for two scenarios in which it is not necessary or appropriate // to read a pressure switch. // 1. If there is no cylinder attached to the port, there is no reason to check for a pressure switch. // 2. If this is the first port, and we know that the port is drawing fresh air, there is no reason // to check for a pressure switch. This case cannot be handled by case #1, as we define a "logical" // cylinder to represent fresh air. // If we find either scenario for the current port, we skip further processing on this port, and proceed to // the next one. GasEndPoint currentInstalledCylinder = dockingStation.GasEndPoints.Find(ic => ic.Position == position); if (currentInstalledCylinder == null) { Log.Debug(string.Format("{0}Position {1} No cylinder present; do not check for pressure switch.", funcName, position)); continue; } else { bool isFreshAir = currentInstalledCylinder.Cylinder.IsFreshAir; if (isFreshAir) { Log.Debug(string.Format("{0}Position {1} Fresh air; do not check for pressure switch.", funcName, position)); continue; } } // SGF 8-Nov-2012 INS-2686 -- end // SMARTCARD NOT CHANGED (NO INSERT OR REMOVAL DETECTED). // WE NEED TO AT LEAST ALWAYS READ THE PRESSURE SWITCH THEN. if (SmartCardManager.IsPressureSwitchPresent(position)) { GasEndPoint pressureCylinder = new GasEndPoint(); pressureCylinder.Position = position; pressureCylinder.Cylinder.Pressure = ReadPressureLevel(position); pressureCylinder.GasChangeType = GasEndPoint.ChangeType.PressureChanged; Log.Debug(string.Format("{0}Position {1} Pressure Switch reports {2}.", funcName, position, pressureCylinder.Cylinder.Pressure)); changedGasEndPoints.Add(pressureCylinder); } else { Log.Debug(string.Format("{0}Position {1} Pressure Switch not present.", funcName, position)); } continue; } // IF WE MAKE IT TO HERE, THE CARD HAS BEEN EITHER INSERTED OR REMOVED. if (!SmartCardManager.IsCardPresent(position)) // CARD REMOVED? { Log.Debug(string.Format("{0}Position {1} SmartCard not present, Returning CardRemoved", funcName, position)); // Server needs to know specifically that cylinder is missing. // Indicate this with an InstalledCylinder containing an empty Cylinder object. GasEndPoint missingCylinder = new GasEndPoint(); missingCylinder.Position = position; missingCylinder.GasChangeType = GasEndPoint.ChangeType.Uninstalled; changedGasEndPoints.Add(missingCylinder); // If a cylinder is not installed on the fresh air port, then assume fresh air // for the port if (position == Controller.FRESH_AIR_GAS_PORT) { Log.Debug(string.Format("{0}Position {1} is assumed to be Fresh Air.", funcName, position)); GasEndPoint freshAirCylinder = GasEndPoint.CreateFreshAir(position); freshAirCylinder.GasChangeType = GasEndPoint.ChangeType.Installed; changedGasEndPoints.Add(freshAirCylinder); } continue; } // IF WE MAKE IT TO HERE, THE CARD HAS BEEN INSERTED. Cylinder cylinder = SmartCardManager.ReadCard(position); if (cylinder == null) // Couldn't read valid cylinder? Driver error or corrupt card. { Log.Debug(string.Format("{0}Position {1}, ReadCard returned null. SKIPPING cylinder.", funcName, position)); continue; } // Dates read from card will be in 'local' time, but everything we deal with is in UTC. cylinder.ExpirationDate = Configuration.ToUniversalTime(cylinder.ExpirationDate); cylinder.RefillDate = Configuration.ToUniversalTime(cylinder.RefillDate); Thread.Sleep(1000); cylinder.Pressure = ReadPressureLevel(position); GasEndPoint gasEndPoint = new GasEndPoint(cylinder, position, GasEndPoint.Type.iGas); gasEndPoint.GasChangeType = GasEndPoint.ChangeType.Installed; Log.Debug(string.Format("{0}Position {1}, Returning CardInserted. Pressure={2}", funcName, position, cylinder.Pressure)); changedGasEndPoints.Add((GasEndPoint)gasEndPoint.Clone()); } // end-for return; }
private DockingStationAction ExamineGasEndPoints() { // First, for each attached cylinder, make sure it's a valid part number. // We try to not hit the database over and over to do this check // The GasEndPoints.Supported property helps us do that. If it's null, // then we've not checked the cylinder, so we query the database to do so. // We then set it to true or false appropiately. Once all GasEndPoints' Supported // properties are non-null, we don't have to hit the database anymore. // Note that there's no need to check the 'part number' for fresh air. List <GasEndPoint> unverifiedGasEndPoints = Configuration.DockingStation.GasEndPoints.FindAll(g => g.Supported == null && g.Cylinder.PartNumber != FactoryCylinder.FRESH_AIR_PART_NUMBER); if (unverifiedGasEndPoints.Count > 0) { // Next, for every currently installed cylinder, verify that we recognize // the part number. We check because the user may attach a cylinder // that has a new part number not yet known to iNet. FactoryCylinderDataAccess fcDataAccess = new FactoryCylinderDataAccess(); using (DataAccessTransaction trx = new DataAccessTransaction(true)) { foreach (GasEndPoint g in unverifiedGasEndPoints) { g.Supported = fcDataAccess.FindByPartNumber(g.Cylinder.PartNumber, trx) != null; Log.Debug(string.Format("Verified GasEndPoint {0} on port {1}. Supported={2}", g.Cylinder.PartNumber, g.Position, g.Supported)); if (g.Supported == false) // no match found? Must be an unknown part number. { return(CreateUnsupportedCylinderAction(g)); } } } } // At this point, we expect that cylinders have been verified. // We now check to see that each cylinder is supported by checking the // InstalledCylinder.Supported property. List <GasEndPoint> unsupportedGasEndPoints = Configuration.DockingStation.GasEndPoints.FindAll(g => g.Supported != null && g.Supported == false); if (unsupportedGasEndPoints.Count > 0) { GasEndPoint gep = unsupportedGasEndPoints[0]; Log.Debug(string.Format("GasEndPoint {0} on port {1}. Supported={2}", gep.Cylinder.PartNumber, gep.Position, gep.Supported)); return(CreateUnsupportedCylinderAction(gep)); } // Next, verify that the cylinder on port 1 is legal for whatever the // current Fresh/Zero air restriction for that port. GasEndPoint gasEndPoint = Configuration.DockingStation.GasEndPoints.Find(g => g.Position == 1); // Either zero air OR fresh air is allowed? if (Configuration.DockingStation.Port1Restrictions == (PortRestrictions.FreshAir | PortRestrictions.ZeroAir)) { if (gasEndPoint != null && !gasEndPoint.Cylinder.IsFreshAir && !gasEndPoint.Cylinder.IsZeroAir) { Log.Debug(string.Format("Port1Restriction={0}, but cylinder is {1}", Configuration.DockingStation.Port1Restrictions.ToString(), gasEndPoint.Cylinder.PartNumber)); return(CreateUnsupportedCylinderAction(gasEndPoint)); } } // Only fresh air is allowed? It's illegal to have a non-freshAir cylinder is installed. if (Configuration.DockingStation.Port1Restrictions == PortRestrictions.FreshAir) { if (gasEndPoint != null && !gasEndPoint.Cylinder.IsFreshAir) { Log.Debug(string.Format("Port1Restriction is FreshAir, but cylinder is {0}", gasEndPoint.Cylinder.PartNumber)); return(CreateUnsupportedCylinderAction(gasEndPoint)); } } // Only zero air is allowed? It's illegal to have either fresh air or a non-zeroAir // cylinder installed. else if (Configuration.DockingStation.Port1Restrictions == PortRestrictions.ZeroAir) { // It's required that we have a zero-air cylinder on port1. So return // Unsupported gas if there is no cylinder, or if the cylinder is not zero-air. if (gasEndPoint == null) { Log.Debug("Port1Restriction is ZeroAir, but no cylinder is installed"); return(CreateUnsupportedCylinderAction(GasEndPoint.CreateFreshAir(Controller.FRESH_AIR_GAS_PORT))); } if (!gasEndPoint.Cylinder.IsZeroAir) { Log.Debug(string.Format("Port1Restriction is ZeroAir, but cylinder is {0}", gasEndPoint.Cylinder.PartNumber)); return(CreateUnsupportedCylinderAction(gasEndPoint)); } } return(null); }
/// <summary> /// Return the information from all smart cards, manifolds and manual cylinders that are present at start-up. /// </summary> /// <param name="installedCylinders">Information about the cylinders is placed into this passed-in list.</param> static private void ReadInstalledCylinders(List <GasEndPoint> gasEndPoints, PortRestrictions port1Restrictions) { const string funcName = "ReadInstalledCylinders: "; // Get all currently attached manifolds and manually-assigned cylinders. List <GasEndPoint> manGasEndPoints = new GasEndPointDataAccess().FindAll().FindAll(m => m.InstallationType == GasEndPoint.Type.Manifold || m.InstallationType == GasEndPoint.Type.Manual); for (int position = 1; position <= Configuration.DockingStation.NumGasPorts; position++) { Log.Debug(funcName + "POSITION " + position); // iGas cylinders take precendence if (!SmartCardManager.IsCardPresent(position)) { Log.Debug(string.Format("{0}Position {1}, No iGas card detected.", funcName, position)); // Does the port have a manifold or manual cylinder attached? Then make sure we include // that cylinder in the returned list. If no cylinder exists on port 1, then create a // virtual fresh air cylinder. GasEndPoint man = manGasEndPoints.Find(m => m.Position == position); if (man != null) { Log.Debug(string.Format("{0}Position {1} {2} found (\"{3}\", \"{4}\", Pressure {5}).", funcName, position, man.InstallationType == GasEndPoint.Type.Manifold ? "Manifold" : "Manual Cylinder", man.Cylinder.FactoryId, man.Cylinder.PartNumber, man.Cylinder.Pressure)); gasEndPoints.Add(man); } else if (position == Controller.FRESH_AIR_GAS_PORT) { Log.Debug(string.Format("{0}Position {1} is assumed to be Fresh Air.", funcName, position)); GasEndPoint freshAirEndPoint = GasEndPoint.CreateFreshAir(position); freshAirEndPoint.GasChangeType = GasEndPoint.ChangeType.Installed; gasEndPoints.Add(freshAirEndPoint); } continue; } // IF WE MAKE IT TO HERE, THEN WE KNOW WE HAVE AN INSERTED SMART CARD WHICH MEANS iGas IS ATTACHED. Cylinder cylinder = SmartCardManager.ReadCard(position); if (cylinder == null) // Check for a valid cylinder. { Log.Debug(string.Format("{0}Position {1}, ReadCard returned null. SKIPPING cylinder.", funcName, position)); continue; } // Dates read from card will be in 'local' time, but everything we deal with is in UTC. cylinder.ExpirationDate = Configuration.ToUniversalTime(cylinder.ExpirationDate); cylinder.RefillDate = Configuration.ToUniversalTime(cylinder.RefillDate); Thread.Sleep(1000); if (SmartCardManager.IsPressureSwitchPresent(position)) { if (SmartCardManager.CheckPressureSwitch(position)) { cylinder.Pressure = PressureLevel.Full; } else { cylinder.Pressure = PressureLevel.Low; } Log.Debug(string.Format("{0}Position {1} Pressure Switch reports {2}.", funcName, position, cylinder.Pressure)); } else { Log.Debug(string.Format("{0}Position {1} Pressure Switch not detected.", funcName, position)); } GasEndPoint gasEndPoint = new GasEndPoint(cylinder, position, GasEndPoint.Type.iGas); // Add the installed cylinder to the DockingStation (IDS). gasEndPoints.Add(gasEndPoint); } return; }