Пример #1
0
        public void SsrChangeTriggersThermocoupleChangeAfterRefresh()
        {
            var Utils = CreateUtils(Location.HLT, new ThermocoupleState {
                Temperature = Temperature.RoomTemp
            });

            ComponentStateChange <ThermocoupleState> thermocoupleChange = null;

            Utils.MockHub.Setup(hb => hb.Publish <ComponentStateChange <ThermocoupleState> >(It.IsAny <ComponentStateChange <ThermocoupleState> >()))
            .Callback <ComponentStateChange <ThermocoupleState> >((chg) => thermocoupleChange = chg);

            Utils.Thermocouple.ComponentStateChangePublisher(Utils.Hub.Publish <ComponentStateChange <ThermocoupleState> >);

            Utils.Thermocouple.ComponentStateChangeOccurred(new ComponentStateChange <SsrState> {
                Location     = Location.HLT,
                CurrentState = new SsrState {
                    Percentage = 50
                }
            });
            Utils.Thermocouple.Refresh();

            Assert.True(thermocoupleChange != null, "ComponentStateChange<ThermocoupleState> was never published");
            Assert.True(thermocoupleChange.Location == Location.HLT, "Ssr change Location is not HLT");
            Assert.True(thermocoupleChange.CurrentState.Temperature > Temperature.RoomTemp, "Thermocouple temperature didn't raise above RoomTemp");
        }
Пример #2
0
        public void PidRequestTriggersPidChange()
        {
            var Utils = CreateUtils(Location.HLT, new PidState {
                IsEngaged   = true,
                SetPoint    = 140,
                Temperature = Temperature.RoomTemp
            });

            ComponentStateChange <PidState> pidChange = null;

            Utils.MockHub.Setup(hb => hb.Publish <ComponentStateChange <PidState> >(It.IsAny <ComponentStateChange <PidState> >()))
            .Callback <ComponentStateChange <PidState> >((req) => pidChange = req);

            Utils.Pid.ComponentStateChangePublisher(Utils.Hub.Publish <ComponentStateChange <PidState> >);

            Utils.Pid.ComponentStateRequestOccurred(new ComponentStateRequest <PidState> {
                Location = Location.HLT,
                Updates  = (state) => {
                    state.SetPoint = 120;
                }
            });

            Assert.True(pidChange != null, "ComponentStateChange<PidState> was never published");
            Assert.True(pidChange.CurrentState.SetPoint == 120, "Requested Pid SetPoint was not equal to 120");
        }
Пример #3
0
 public void ComponentStateChangeOccurred(ComponentStateChange <SsrState> stateChange)
 {
     if (stateChange.Location == Location)
     {
         double percentage = (double)stateChange.CurrentState.Percentage / 100d;
         TemperatureChange = percentage - COOLING_RATIO;  // Anything below 10% decreases water temperature.
     }
 }
Пример #4
0
 private void ThermometerStateChangeOccured(ComponentStateChange <ThermometerState> thermometerStateChange)
 {
     if (thermometerStateChange.Id == Id)
     {
         PriorState   = CurrentState;
         CurrentState = CurrentState.Update(thermometerStateChange);
         Process();
     }
 }
Пример #5
0
 public virtual void ComponentStateChangeOccurred(ComponentStateChange <ThermocoupleState> stateChange)
 {
     if (stateChange.Location == Location)
     {
         //_logger.LogInformation($"Need to recalculate value for Pid: {Location}");
         PriorState               = CurrentState;
         CurrentState             = CurrentState.Clone();
         CurrentState.Temperature = stateChange.CurrentState.Temperature;
         Refresh();
     }
 }
Пример #6
0
        //*********************************** CACHING ******************************************

        private void ConnectionStateHandler(ComponentStateChange <ConnectionState> connectionStateChange)
        {
            var bfState = new BFState {
                SsrStates           = CurrentComponentStates <SsrState>(),
                ThermometerStates   = CurrentComponentStates <ThermometerState>(),
                PidControllerStates = CurrentComponentStates <PidControllerState>(),
                PumpStates          = CurrentComponentStates <PumpState>(),
            };


            ComponentStateChangeFiring(new ComponentStateChange <BFState> {
                CurrentState = bfState
            });
            Logger.LogInformation($"Send entire buttload: {_applicationConfig.Device}");
        }
Пример #7
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);
            }
        }
        public override void ComponentStateChangeFiring <T>(ComponentStateChange <T> componentStateChange)
        {
            var isApplianceState = typeof(T) != typeof(ThermocoupleState);
            var isServerState    = typeof(T) == typeof(ConnectionState);

            componentStateChange.FromUserName = _applicationConfig.UserName;

            if (_connection.IsConnected()
                &&
                ((isApplianceState && _applicationConfig.IsAppliance()) || (isServerState && _applicationConfig.IsServer()))
                )
            {
                _connection.InvokeAsync("ComponentStateChangeBroadcasted",
                                        componentStateChange.FromUserName,
                                        componentStateChange.GetType().ToString(),
                                        componentStateChange.ToJson());
            }
            base.ComponentStateChangeFiring(componentStateChange);
        }
Пример #9
0
        public override async Task OnConnectedAsync()
        {
            UserHandler.ConnectedIds.Add(Context.ConnectionId);

            var userName = Context.User.Identity.Name;

            if (UserHandler.UserNames.Add(userName))
            {
                var componentStateChange = new ComponentStateChange <ConnectionState> {
                    FromUserName = userName,
                    CurrentState = new ConnectionState {
                        Status = ConnectionStatus.Connected
                    }
                };
                logger.LogInformation($"User connected: {userName} : {UserHandler.UserNames.Count} : {UserHandler.ConnectedIds.Count}");
                await Clients.All.SendAsync("ComponentStateChangeReceived",
                                            userName,
                                            componentStateChange.GetType().ToString(),
                                            componentStateChange.ToJson());
            }
        }
Пример #10
0
        private void BFStateHandler(ComponentStateChange <BFState> bfStateChange)
        {
            var bfState = bfStateChange.CurrentState;

            _componentStateCacheLookup[typeof(SsrState)]           = bfState.SsrStates.ToDictionary(ss => ss.Id, ss => (ComponentState)ss);
            _componentStateCacheLookup[typeof(ThermometerState)]   = bfState.ThermometerStates.ToDictionary(ss => ss.Id, ss => (ComponentState)ss);
            _componentStateCacheLookup[typeof(PidControllerState)] = bfState.PidControllerStates.ToDictionary(ss => ss.Id, ss => (ComponentState)ss);
            _componentStateCacheLookup[typeof(PumpState)]          = bfState.PumpStates.ToDictionary(ss => ss.Id, ss => (ComponentState)ss);

            //foreach (var stateChange in bfState.SsrStates)
            //    ComponentStateChangeFiring(stateChange.ToComponentStateChange());

            //foreach (var stateChange in bfState.ThermometerStates)
            //    ComponentStateChangeFiring(stateChange.ToComponentStateChange());

            //foreach (var stateChange in bfState.PidControllerStates)
            //    ComponentStateChangeFiring(stateChange.ToComponentStateChange());

            //foreach (var stateChange in bfState.PumpStates)
            //    ComponentStateChangeFiring(stateChange.ToComponentStateChange());

            Logger.LogInformation($"Receive entire buttload : {_applicationConfig.Device}");
        }
Пример #11
0
        public void SsrRequestTriggersSsrChange()
        {
            var Utils = CreateUtils(Location.HLT, new SsrState {
                Percentage = 0
            });

            ComponentStateChange <SsrState> ssrChange = null;

            Utils.MockHub.Setup(hb => hb.Publish <ComponentStateChange <SsrState> >(It.IsAny <ComponentStateChange <SsrState> >()))
            .Callback <ComponentStateChange <SsrState> >((chg) => ssrChange = chg);

            Utils.Ssr.ComponentStateChangePublisher(Utils.Hub.Publish <ComponentStateChange <SsrState> >);

            Utils.Ssr.ComponentStateRequestOccurred(new ComponentStateRequest <SsrState> {
                Location = Location.HLT,
                Updates  = (state) => {
                    state.Percentage = 10;
                }
            });

            Assert.True(ssrChange != null, "ComponentStateChange<SsrState> was never published");
            Assert.True(ssrChange.Location == Location.HLT, "Ssr change Location is not HLT");
            Assert.True(ssrChange.CurrentState.Percentage == 10, "Ssr change Percentage was not equal to 10");
        }
Пример #12
0
        public static PidControllerState Update(this PidControllerState pidControllerState, ComponentStateChange <ThermometerState> thermometerStateChange)
        {
            if (pidControllerState == null)
            {
                return(null);
            }
            var clone = pidControllerState.Clone();

            clone.Temperature = thermometerStateChange.CurrentState.Temperature;
            return(clone);
        }
Пример #13
0
 public void ComponentStateChangeOccurred(ComponentStateChange <SsrState> stateChange)
 {
     _logger.LogInformation($"SsrState: {stateChange.Location} {stateChange.CurrentState.IsFiring} {stateChange.CurrentState.Percentage}");
 }
Пример #14
0
 public void ComponentStateChangeOccurred(ComponentStateChange <ThermocoupleState> stateChange)
 {
     _logger.LogInformation($"ThermocoupleState: {stateChange.Location} {stateChange.CurrentState.Temperature.ToString("F2")}");
 }
Пример #15
0
 public void ComponentStateChangeOccurred(ComponentStateChange <PidState> stateChange)
 {
     _logger.LogInformation($"PidState: {stateChange.Location} {stateChange.CurrentState.IsEngaged} {stateChange.CurrentState.SetPoint}");
 }
Пример #16
0
 private void thermometerStateChangeOccured(ComponentStateChange <ThermometerState> thermometerStateChange)
 {
     _thermometerStateLookup[thermometerStateChange.Id] = thermometerStateChange.CurrentState;
 }
Пример #17
0
 public void ComponentStateChangeOccurred(ComponentStateChange <PidState> stateChange)
 {
     //_logger.Debug($"PidStateChangeOccured: {stateChange.Location}");
 }
Пример #18
0
        //*********************************** EVENT HANDLING ******************************************

        public virtual void ComponentStateChangeFiring <T>(ComponentStateChange <T> componentStateChange) where T : ComponentState
        {
            CacheComponentStateChange <T>(componentStateChange);
            _eventAggregator.GetEvent <ComponentStateChangeEvent <ComponentStateChange <T> > >().Publish(componentStateChange);
        }
Пример #19
0
 public void ComponentStateChangeOccurred(ComponentStateChange <ThermocoupleState> stateChange)
 {
     //_logger.Debug($"ThermometerStateChangeOccured: {stateChange.Location}");
 }
Пример #20
0
 private void PidControllerStateChangeOccured(ComponentStateChange <PidControllerState> pidControllerStateChange)
 {
     Logger.LogInformation($"RaspPI: Pid Change: {pidControllerStateChange.CurrentState.SetPoint}");
     SetPoint = (int)pidControllerStateChange.CurrentState.SetPoint;
 }
Пример #21
0
 private void ThermometerStateChangeOccured(ComponentStateChange <ThermometerState> thermometerStateChange)
 {
     Logger.LogInformation($"RaspPI: Thermometer Change: {thermometerStateChange.CurrentState.Temperature}");
     Temperature = thermometerStateChange.CurrentState.Temperature;
 }
Пример #22
0
 private void SsrStateChangeOccured(ComponentStateChange <SsrState> ssrStateChange)
 {
     Logger.LogInformation($"RaspPI: Ssr Change: {ssrStateChange.CurrentState.Percentage}");
     SsrPercentage = ssrStateChange.CurrentState.Percentage;
 }
Пример #23
0
 private void CacheComponentStateChange <T>(ComponentStateChange <T> componentStateChange) where T : ComponentState
 {
     ComponentStateCache <T>()[componentStateChange.Id] = componentStateChange.CurrentState;
 }
Пример #24
0
 private void ssrStateChangeOccured(ComponentStateChange <SsrState> ssrStateChange)
 {
     _ssrStateLookup[ssrStateChange.Id] = ssrStateChange.CurrentState;
 }