/// <summary> /// Executes an instrument read settings operation. /// </summary> /// <returns>Docking station event</returns> public DockingStationEvent Execute() { Stopwatch stopwatch = Log.TimingBegin("ALARM EVENT DOWNLOAD"); InstrumentAlarmEventsDownloadEvent instrumentAlarmEventsDownloadEvent = new InstrumentAlarmEventsDownloadEvent(this); instrumentAlarmEventsDownloadEvent.DockedInstrument = (ISC.iNet.DS.DomainModel.Instrument)Master.Instance.SwitchService.Instrument.Clone(); instrumentAlarmEventsDownloadEvent.DockingStation = Master.Instance.ControllerWrapper.GetDockingStation(); // Retrieve the events. using (InstrumentController instrumentController = Master.Instance.SwitchService.InstrumentController) { // Open the serial port connection needed to communicate with the instrument. instrumentController.Initialize(); Log.Debug("ALARM EVENTS: Downloading"); instrumentAlarmEventsDownloadEvent.AlarmEvents = instrumentController.GetAlarmEvents(); Log.Debug("ALARM EVENTS: " + instrumentAlarmEventsDownloadEvent.AlarmEvents.Length + " events downloaded."); } // end-using // Need to fill in the instrument serial number on our own. // At the same time, format up details for each alarm event. foreach (AlarmEvent alarmEvent in instrumentAlarmEventsDownloadEvent.AlarmEvents) { alarmEvent.InstrumentSerialNumber = instrumentAlarmEventsDownloadEvent.DockedInstrument.SerialNumber; } Log.TimingEnd("ALARM EVENT DOWNLOAD", stopwatch); return(instrumentAlarmEventsDownloadEvent); // Return the populated event. }
public void ExecuteAlarmEventDownload() { // arrange InstrumentAlarmEventsDownloadAction action = Helper.GetAlarmEventDownloadAction(DeviceType.MX4); InitializeForTest(action); InstrumentAlarmEventsDownloadOperation alarmDownloadOperation = new InstrumentAlarmEventsDownloadOperation(action); InstrumentAlarmEventsDownloadEvent alarmDownloadEvent = (InstrumentAlarmEventsDownloadEvent)alarmDownloadOperation.Execute(); Assert.True(alarmDownloadEvent.AlarmEvents.Length == 0); }
public void GetInstrumentAlarmEventClearActionAsFollowUpActionForInstrumentAlarmEventDownloadToClearErrors() { // arrange InstrumentAlarmEventsDownloadOperation operation = new InstrumentAlarmEventsDownloadOperation(); InstrumentAlarmEventsDownloadEvent dsEvent = new InstrumentAlarmEventsDownloadEvent(operation); dsEvent.Errors.Add(new DockingStationError("Test Error!")); Initialize(); CreateMasterForTest(); // act nextAction = scheduler.GetNextAction(dsEvent); // assert Xunit.Assert.True(nextAction is InstrumentAlarmEventsClearAction); }
public void GetInstrumentAlarmEventClearActionAsFollowUpActionForInstrumentAlarmEventDownloadToClearInstrumentAlarmEvents() { // arrange InstrumentAlarmEventsDownloadOperation operation = new InstrumentAlarmEventsDownloadOperation(); InstrumentAlarmEventsDownloadEvent dsEvent = new InstrumentAlarmEventsDownloadEvent(operation); dsEvent.AlarmEvents = new AlarmEvent[] { new AlarmEvent() }; Initialize(); CreateMasterForTest(); // act nextAction = scheduler.GetNextAction(dsEvent); // assert Xunit.Assert.True(nextAction is InstrumentAlarmEventsClearAction); }
public void ExecuteAlarmEventDownloadAndDownloadAlarmDetailsFromInstrument() { // arrange InstrumentAlarmEventsDownloadAction action = Helper.GetAlarmEventDownloadAction(DeviceType.GBPRO); InitializeForTest(action); DateTime alarmTime = DateTime.Now; instrumentController.Setup(x => x.GetAlarmEvents()) .Returns(new AlarmEvent[1] { new AlarmEvent() { InstrumentSerialNumber = action.Instrument.SerialNumber, AlarmOperatingMode = AlarmOperatingMode.Running, Duration = 10 , AlarmHigh = 23.5, AlarmLow = 19.5, BaseUnitSerialNumber = string.Empty, GasCode = GasCode.O2, IsDocked = true , IsDualSense = false, PeakReading = 20.9, SensorCode = SensorCode.O2, SensorSerialNumber = "TESTSENSOR123" , Site = string.Empty, User = string.Empty, SpeakerVoltage = 10, Ticks = 20, Timestamp = alarmTime, VibratingMotorVoltage = 10 } }); InstrumentAlarmEventsDownloadOperation alarmDownloadOperation = new InstrumentAlarmEventsDownloadOperation(action); InstrumentAlarmEventsDownloadEvent alarmDownloadEvent = (InstrumentAlarmEventsDownloadEvent)alarmDownloadOperation.Execute(); Assert.True(alarmDownloadEvent.AlarmEvents.Length == 1 && alarmDownloadEvent.AlarmEvents[0].InstrumentSerialNumber == action.Instrument.SerialNumber && alarmDownloadEvent.AlarmEvents[0].AlarmOperatingMode == AlarmOperatingMode.Running && alarmDownloadEvent.AlarmEvents[0].Duration == 10 && alarmDownloadEvent.AlarmEvents[0].AlarmHigh == 23.5 && alarmDownloadEvent.AlarmEvents[0].AlarmLow == 19.5 && alarmDownloadEvent.AlarmEvents[0].BaseUnitSerialNumber == string.Empty && alarmDownloadEvent.AlarmEvents[0].GasCode == GasCode.O2 && alarmDownloadEvent.AlarmEvents[0].IsDocked == true && alarmDownloadEvent.AlarmEvents[0].IsDualSense == false && alarmDownloadEvent.AlarmEvents[0].PeakReading == 20.9 && alarmDownloadEvent.AlarmEvents[0].SensorCode == SensorCode.O2 && alarmDownloadEvent.AlarmEvents[0].SensorSerialNumber == "TESTSENSOR123" && alarmDownloadEvent.AlarmEvents[0].Site == string.Empty && alarmDownloadEvent.AlarmEvents[0].User == string.Empty && alarmDownloadEvent.AlarmEvents[0].SpeakerVoltage == 10 && alarmDownloadEvent.AlarmEvents[0].Ticks == 20 && alarmDownloadEvent.AlarmEvents[0].Timestamp == alarmTime && alarmDownloadEvent.AlarmEvents[0].VibratingMotorVoltage == 10); }
/// <summary> /// Determines if some specific action needs to be performed based /// on the event passed to it. (Some events require a specific /// followup action to be executed.) /// </summary> /// <param name="dsEvent"></param> /// <returns></returns> internal DockingStationAction GetFollowupAction(DockingStationEvent dsEvent) { // A SettingsUpdate is ALWAYS followed by a SettingsRead. if (dsEvent is SettingsUpdateEvent) { // If the SettingsUpdate was Scheduled, we want to inject a CylinderPressureReset before the SettingsRead. if (dsEvent.Trigger == TriggerType.Scheduled) { Log.Trace("EventProcessor returning CylinderPressureReset as followup to SettingsUpdate"); CylinderPressureResetAction cylPressureResetAction = new CylinderPressureResetAction(); // These values will be propogated to a followup SettingsRead. cylPressureResetAction.PostUpdate = true; cylPressureResetAction.SettingsRefId = ((SettingsUpdateEvent)dsEvent).DockingStation.RefId; return(cylPressureResetAction); } Log.Trace("EventProcessor returning SettingsRead as followup to SettingsUpdate"); SettingsReadAction settingsReadAction = new SettingsReadAction(); // Set the refId to indicate that this Read is occurring due to an Update that was just performed. settingsReadAction.PostUpdate = true; settingsReadAction.SettingsRefId = ((SettingsUpdateEvent)dsEvent).DockingStation.RefId; // Explicitly set the ChangedSmartCards to all falses so that no smart cards are read. settingsReadAction.ChangedSmartCards = new bool[Configuration.DockingStation.NumGasPorts]; return(settingsReadAction); } if (dsEvent is CylinderPressureResetEvent) { Log.Trace("EventProcessor returning SettingsRead as followup to CylinderPressureReset"); SettingsReadAction settingsReadAction = new SettingsReadAction(); // Copy the PostUpdate and SettingsRefId so it can be determined if the SettingsRead is // being run due to a SettingsUpdate that would have occurred before the CylinderPressureReset. settingsReadAction.PostUpdate = ((CylinderPressureResetEvent)dsEvent).PostUpdate; settingsReadAction.SettingsRefId = ((CylinderPressureResetEvent)dsEvent).SettingsRefId; // Explicitly set the ChangedSmartCards to null so all positions are read similar to startup. settingsReadAction.ChangedSmartCards = null; return(settingsReadAction); } // After downloading datalog, we clear it. if (dsEvent is InstrumentDatalogDownloadEvent) { InstrumentDatalogDownloadEvent datalogEvent = (InstrumentDatalogDownloadEvent)dsEvent; // D2G: Only clear the log if there is something to clear, or corruption was detected. if (datalogEvent.InstrumentSessions.Count > 0 || datalogEvent.Errors.Count > 0) { Log.Trace("EventProcessor returning InstrumentHygieneClearAction as followup to InstrumentHygieneDownloadEvent"); return(new InstrumentDatalogClearAction()); } else { Log.Debug("NO DATALOG TO CLEAR"); return(null); } } // After downloading alarm events, we clear them. if (dsEvent is InstrumentAlarmEventsDownloadEvent) { InstrumentAlarmEventsDownloadEvent alarmsEvent = (InstrumentAlarmEventsDownloadEvent)dsEvent; // D2G: Only clear the log if there is something to clear, or corruption was detected. if (alarmsEvent.AlarmEvents.Length > 0 || alarmsEvent.Errors.Count > 0) { Log.Trace("EventProcessor returning InstrumentAlarmEventsClearAction as followup to InstrumentAlarmEventsDownloadEvent"); return(new InstrumentAlarmEventsClearAction()); } else { Log.Debug("NO ALARM EVENTS TO CLEAR"); return(null); } } // After downloading alarm events, we clear them. if (dsEvent is InstrumentManualOperationsDownloadEvent) { InstrumentManualOperationsDownloadEvent manualOpsEvent = (InstrumentManualOperationsDownloadEvent)dsEvent; // D2G: Only clear the log if there is something to clear, or corruption was detected. if (manualOpsEvent.GasResponses.Count > 0 || manualOpsEvent.Errors.Count > 0) { Log.Trace("EventProcessor returning InstrumentManualOperationsDownloadAction as followup to InstrumentManualOperationsDownloadEvent"); return(new InstrumentManualOperationsClearAction()); } else { Log.Debug("NO MANUAL GAS OPERATIONS TO CLEAR"); return(null); } } if (dsEvent is InstrumentFirmwareUpgradeEvent) { if (((InstrumentFirmwareUpgradeEvent)dsEvent).UpgradeFailure) { Log.Trace("EventProcessor returning NothingAction as followup to InstrumentFirmwareUpgradeEvent due to an upgrade failure"); // Setting this to true will cause the docking station to go // into its UpgradingInstrumentError state. Master.Instance.SwitchService.InstrumentUpgradeError = true; // Return an action just to prevent further processing (there's no use // next letting the scheduler figure out what needs to be done next since // we know we're about to into the UpgradingInstrumentError state.) return(new NothingAction()); } } //Suresh 06-FEB-2012 INS-2622 //Check whether instrument is in critical error. if (dsEvent is InstrumentDiagnosticEvent) { InstrumentDiagnosticEvent diagnosticEvent = (InstrumentDiagnosticEvent)dsEvent; if (diagnosticEvent.InstrumentInCriticalError == true) { Log.Trace("EventProcessor returning NothingAction as followup to InstrumentDiagnosticEvent due to instrument having a critical error"); Master.Instance.SwitchService.Instrument.InstrumentInCriticalError = true; // INS-8446 RHP v7.6 - Set the SwitchService's InstrumentCriticalErrorCode to display the critical error code on LCD Log.Trace("EventProcessor identfied InstrumentDiagnosticEvent having a critical error code of " + diagnosticEvent.InstrumentCriticalErrorCode); Master.Instance.SwitchService.Instrument.InstrumentCriticalErrorCode = diagnosticEvent.InstrumentCriticalErrorCode; return(new NothingAction()); } } return(null); }