Beispiel #1
0
        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();
            }
        }
Beispiel #2
0
 private void SendNotification()
 {
     _eventHandler.ComponentStateChangeFiring <SsrState>(new ComponentStateChange <SsrState> {
         CurrentState = CurrentState.Clone(),
         PriorState   = PriorState.Clone()
     });
 }
Beispiel #3
0
        private void ThermocoupleStateChangeOccured(ComponentStateChange <ThermocoupleState> thermocoupleStateChange)
        {
            if (thermocoupleStateChange.Id == Id)
            {
                //var

                var currentState = new ThermometerState {
                    Id          = Id,
                    Temperature = thermocoupleStateChange.CurrentState.Temperature,
                    Timestamp   = thermocoupleStateChange.CurrentState.Timestamp
                };

                // Archive old shit.
                if (CurrentState != null)
                {
                    PreviousStates.Add(currentState);
                    PriorState = CurrentState;
                }

                CurrentState = currentState;

                _eventHandler.ComponentStateChangeFiring <ThermometerState>(new ComponentStateChange <ThermometerState> {
                    CurrentState = CurrentState.Clone(),
                    PriorState   = PriorState.Clone()
                });

                //Logger.Information($"ThermometerChangeOccured[{Id}] : {thermometerChange.Value}");


                // Determin Change - Get all changes at least this old, order by newest, take first
                // TODO: Refactor to use previous state
                //var earliestTimeOfChange = DateTime.Now.AddMilliseconds(-_changeWindowInMillis);
                //var previousChange = ThermometerStates.Where(tc => tc.Timestamp < earliestTimeOfChange).OrderByDescending(tc => tc.Timestamp).FirstOrDefault();

                //if (thermometerStateChange.PriorState != null)
                //    Change = thermometerStateChange.CurrentState.Temperature - thermometerStateChange.PriorState.Temperature;

                // Determine Retention
                // TODO: Move this to a background thread
                var oldestTimeOfChange = DateTime.Now.AddMinutes(-_changeEventRetentionInMins);
                var changesToRemove    = PreviousStates.RemoveAll(tc => tc.Timestamp < oldestTimeOfChange);
            }
        }