public virtual void ComponentStateRequestOccurred(ComponentStateRequest <PidState> stateRequest) { if (stateRequest.Location == Location) { PriorState = CurrentState; CurrentState = stateRequest.UpdateState(CurrentState.Clone()); if (!PriorState.IsEngaged && CurrentState.IsEngaged && _publishPidDisengageRequest != null) { foreach (var location in LocationHelper.PidLocations.Where(loc => loc != Location)) { _publishPidDisengageRequest(new ComponentStateRequest <PidState> { Location = location, Updates = (disengageState) => { disengageState.IsEngaged = false; } }); } } //TODO: Determine if this needs to be published at all. _publishPidStateChanged(CreateComponentStateChange()); Refresh(); } }
public void ThermoChangeTriggersSsrRequest() { var Utils = CreateUtils(Location.HLT, new PidState { IsEngaged = true, SetPoint = 140, Temperature = Temperature.RoomTemp }); ComponentStateRequest <SsrState> ssrRequest = null; Utils.MockHub.Setup(hb => hb.Publish <ComponentStateRequest <SsrState> >(It.IsAny <ComponentStateRequest <SsrState> >())) .Callback <ComponentStateRequest <SsrState> >((req) => ssrRequest = req); Utils.Pid.ComponentStateRequestPublisher(Utils.Hub.Publish <ComponentStateRequest <SsrState> >); Utils.Pid.ComponentStateChangeOccurred(new ComponentStateChange <ThermocoupleState> { Location = Location.HLT, CurrentState = new ThermocoupleState { Temperature = Temperature.RoomTemp + 10 } }); Assert.True(ssrRequest != null, "ComponentStateRequest<SsrState> was never published"); var updatedSsrState = ssrRequest.UpdateState(new SsrState()); Assert.True(updatedSsrState.Percentage == 100, "Requested Ssr Percentage was not equal to 100"); // This is no longer needed but lets keep it so we know how to do it next time. //Utils.MockHub.Verify(hb => hb.Publish(It.Is<ComponentStateRequest<SsrState>>(req => req.Location == Location.HLT))); }
static void Main(string[] args) { container = ComponentRegistrator.ComponentRegistry() .RegisterComponentsForSimulation(); var timer = new Timer(2000); timer.Elapsed += RefreshThermocouples; timer.Start(); var pidUpdateRequest = new ComponentStateRequest <PidState> { Location = Location.HLT, Updates = (state) => { state.IsEngaged = true; state.Temperature = Temperature.RoomTemp; state.SetPoint = 140; } }; var hub = container.GetInstance <Hub>(); hub.Publish(pidUpdateRequest); System.Console.ReadLine(); }
public void DisablingPidDisablesSsrs() { var Utils = CreateUtils(Location.HLT, new PidState { IsEngaged = true, SetPoint = Temperature.BoilingTemp, Temperature = Temperature.BoilingTemp }); ComponentStateRequest <SsrState> ssrRequest = null; Utils.MockHub.Setup(hb => hb.Publish <ComponentStateRequest <SsrState> >(It.IsAny <ComponentStateRequest <SsrState> >())) .Callback <ComponentStateRequest <SsrState> >((req) => ssrRequest = req); Utils.Pid.ComponentStateRequestPublisher(Utils.Hub.Publish <ComponentStateRequest <SsrState> >); Utils.Pid.ComponentStateRequestOccurred(new ComponentStateRequest <PidState> { Location = Location.HLT, Updates = (state) => { state.IsEngaged = false; } }); Assert.True(ssrRequest != null, "ComponentStateRequest<SsrState> was never published"); var ssrState = ssrRequest.UpdateState(new SsrState()); Assert.True(ssrState.IsEngaged == false, "Ssr request wasn't to disengage"); }
private void SsrStateRequestOccured(ComponentStateRequest <SsrRequestState> ssrStateRequest) { if (ssrStateRequest.Id == CurrentState.Id && CurrentState.IsDifferent(ssrStateRequest.RequestState)) { var stopIt = ssrStateRequest.RequestState.Percentage == 0 && CurrentState.IsEngaged; var startIt = ssrStateRequest.RequestState.Percentage > 0 && !CurrentState.IsEngaged; if (stopIt || startIt) { PriorState = CurrentState; CurrentState = CurrentState.UpdateRequest(ssrStateRequest.RequestState); CalculateDurations(); } if (startIt) { Start(); } if (stopIt) { Stop(); } if (stopIt || startIt) { SendNotification(); } else { ProposedState = CurrentState.UpdateRequest(ssrStateRequest.RequestState); } } }
public virtual void ComponentStateRequestOccurred(ComponentStateRequest <SsrState> stateRequest) { if (stateRequest.Location == Location) { PriorState = CurrentState; CurrentState = stateRequest.UpdateState(CurrentState.Clone()); var publishChanges = false; if (PriorState.Percentage != CurrentState.Percentage) { CalculateDurations(); publishChanges = true; } if (!PriorState.IsEngaged && CurrentState.IsEngaged) { Start(); publishChanges = true; } if (publishChanges) { _publishSsrStateChanged(CreateComponentStateChange()); } } }
private void PidControllerStateRequestOccured(ComponentStateRequest <PidControllerRequestState> pidControllerStateRequest) { if (pidControllerStateRequest.Id == Id) { Logger.LogInformation($"Pid Request Received: {Id} {pidControllerStateRequest.RequestState.SetPoint} {pidControllerStateRequest.RequestState.IsEngaged}"); if (!CurrentState.IsEngaged && pidControllerStateRequest.RequestState.IsEngaged.HasValue && pidControllerStateRequest.RequestState.IsEngaged.Value) { // PID is getting engaged, disengage the others. var pidsToDisengage = ComponentHelper.PidComponentIds.Where(p => p != CurrentState.Id).ToList(); foreach (var pidToDisengage in pidsToDisengage) { _eventHandler.ComponentStateRequestFiring(new ComponentStateRequest <PidControllerRequestState> { RequestState = new PidControllerRequestState { Id = pidToDisengage, IsEngaged = false } }); } } PriorState = CurrentState; CurrentState = CurrentState.Update(pidControllerStateRequest.RequestState); _eventHandler.ComponentStateChangeFiring(new ComponentStateChange <PidControllerState> { PriorState = PriorState.Clone(), CurrentState = CurrentState.Clone() }); Process(); } }
public override void ComponentStateRequestFiring <T>(ComponentStateRequest <T> componentStateRequest) { componentStateRequest.FromUserName = _applicationConfig.UserName; if (_connection.IsConnected() && _applicationConfig.IsServer() ) { _connection.InvokeAsync("ComponentStateRequestBroadcasted", componentStateRequest.FromUserName, componentStateRequest.GetType().ToString(), componentStateRequest.ToJson()); } base.ComponentStateRequestFiring(componentStateRequest); }
private void PumpStateRequestOccured(ComponentStateRequest <PumpRequestState> pumpRequestState) { bool correctPump = pumpRequestState.Id == CurrentState.Id; if (pumpRequestState.Id == CurrentState.Id && CurrentState.IsDifferent(pumpRequestState.RequestState)) { CurrentState = CurrentState.Update(pumpRequestState.RequestState); if (CurrentState.IsEngaged) { _pin?.Write(GpioPinValue.High); } else { _pin?.Write(GpioPinValue.Low); } Logger.LogInformation($"Pump: {CurrentState.Id} - {CurrentState.IsEngaged}"); _eventHandler.ComponentStateChangeFiring(new ComponentStateChange <PumpState> { CurrentState = CurrentState.Clone() }); } }
public virtual void ComponentStateRequestFiring <T>(ComponentStateRequest <T> componentStateRequest) where T : RequestedComponentState { _eventAggregator.GetEvent <ComponentStateRequestEvent <ComponentStateRequest <T> > >().Publish(componentStateRequest); }