Exemplo n.º 1
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        //现实变热遮罩
        if (temperatureState != TemperatureState.Hot)
        {
            if (elementValue > hotThreshold)
            {
                ShowHotMask();
                temperatureState = TemperatureState.Hot;
            }
        }
        if (temperatureState != TemperatureState.Cold)
        {
            if (elementValue < coldThreshold)
            {
                ShowColdMask();
                temperatureState = TemperatureState.Cold;
            }
        }
        if (temperatureState != TemperatureState.Normal)
        {
            if (elementValue > coldThreshold * .8f && elementValue < hotThreshold * .8f)
            {
                HideMask();
                temperatureState = TemperatureState.Normal;
            }
        }

        //根据温度更改遮罩颜色
        float alpha;

        switch (temperatureState)
        {
        case TemperatureState.Hot:
            alpha = (elementValue - hotThreshold) / (100 - hotThreshold) * maxHotAlpha;
            ChangeAlpha(ref hotMask, alpha);
            if (elementValue > 95)
            {
                hotParticle.Play();
                if (!hurting)
                {
                    iElememtPlayer.GetHurt();
                    hurting = true;
                }
            }
            if (elementValue < 80)
            {
                hotParticle.Stop();
                hurting = false;
            }
            break;

        case TemperatureState.Cold:
            alpha = (Mathf.Abs(elementValue) - Mathf.Abs(coldThreshold)) / (100 + coldThreshold) * maxColdAlpha;
            ChangeAlpha(ref coldMask, alpha);
            break;
        }
    }
Exemplo n.º 2
0
 public HeatingModule(TemperatureState temperatureState, BiscuitCounterState biscuitCounterState, MachineModulesSynchronizers synchronizers, IMessageIOProvider message) : base(message)
 {
     this.temperatureState        = temperatureState;
     this.biscuitCounterState     = biscuitCounterState;
     this.reachMaxTempEvent       = synchronizers.reachMaxTempEvent;
     this.reachMinTempEvent       = synchronizers.reachMinTempEvent;
     this.lineIsEmptyEvent        = synchronizers.lineIsEmptyEvent;
     this.cancellationTokenSource = synchronizers.cancellationTokenSource;
     heatingThread = new Thread(ThreadStartDelagate)
     {
         Name = Name
     };
 }
Exemplo n.º 3
0
 public OvenModule(
     HeatingModule heatingModule,
     ThermometerModule thermometerModule,
     TemperatureState temperatureState,
     IMessageIOProvider message,
     MachineModulesSynchronizers synchronizers) : base(message)
 {
     this.temperatureState        = temperatureState;
     this.heatingModule           = heatingModule;
     this.thermometerModule       = thermometerModule;
     this.ovenIsReadyEvent        = synchronizers.ovenIsReadyEvent;
     this.lineIsEmptyEvent        = synchronizers.lineIsEmptyEvent;
     this.cancellationTokenSource = synchronizers.cancellationTokenSource;
     ovenThread = new Thread(ThreadStartDelagate)
     {
         Name = Name
     };
 }
 void HighTemperatureIndicatorLeave(object sender, IndicatorLeaveEventArgs e)
 {
     temperature = TemperatureState.Low;
     UpdateWeatherState();
 }
 void HighTemperatureIndicatorEnter(object sender, IndicatorEnterEventArgs e)
 {
     temperature = TemperatureState.High;
     UpdateWeatherState();
 }
Exemplo n.º 6
0
        public void Monitor(EngineRoomServiceDB erdb, List <Message> messages, bool returnEventsOnly)
        {
            if (!Enabled)
            {
                return;
            }

            EngineRoomServiceDB.LogEventType let = EngineRoomServiceDB.LogEventType.INFO;
            String  desc = null;
            Message msg  = null;

            //see if engine is Running (and log)
            bool running = Running; // record to test change of state

            Running = RPM.AverageRPM > IS_RUNNING_RPM_THRESHOLD;
            bool isEvent = running != Running;

            //Running or not
            if (isEvent) //log
            {
                if (Running)
                {
                    erdb.LogEvent(EngineRoomServiceDB.LogEventType.ON, ID, String.Format("Current RPM = {0}", RPM.RPM));
                    LastOn = erdb.GetLatestEvent(EngineRoomServiceDB.LogEventType.ON, ID).GetDateTime("created");
                }
                else
                {
                    desc = LastOn == default(DateTime) ? "N/A" : String.Format("Running for {0}", (DateTime.Now - LastOn).ToString("c"));
                    erdb.LogEvent(EngineRoomServiceDB.LogEventType.OFF, ID, desc);
                    LastOff = erdb.GetLatestEvent(EngineRoomServiceDB.LogEventType.OFF, ID).GetDateTime("created");
                }
            }

            if (isEvent || !returnEventsOnly)
            {
                EngineRoomMessageSchema schema = new EngineRoomMessageSchema(new Message(MessageType.DATA));
                schema.AddEngine(this);
                messages.Add(schema.Message);
            }


            //some useful durations...
            long secsSinceLastOn  = LastOn == default(DateTime) ? -1 : (long)DateTime.Now.Subtract(LastOn).TotalSeconds;
            long secsSinceLastOff = LastOff == default(DateTime) ? -1 : (long)DateTime.Now.Subtract(LastOff).TotalSeconds;

            //Oil State
            OilState oilState = StateOfOil;

            if (Running && RPM.RPM > 100 && secsSinceLastOn > 30)
            {
                oilState = OilSensor.IsOn ? OilState.NO_PRESSURE : OilState.OK_ENGINE_ON;
            }
            else if (!Running && RPM.RPM == 0 && secsSinceLastOff > 30)
            {
                oilState = OilSensor.IsOff ? OilState.SENSOR_FAULT : OilState.OK_ENGINE_OFF;
            }

            msg        = null;
            isEvent    = oilState != StateOfOil;
            StateOfOil = oilState;
            String rpmDesc = String.Format("RPM (instant/average) = {0}/{1}", RPM.RPM, RPM.AverageRPM);

            switch (StateOfOil)
            {
            case OilState.NO_PRESSURE:
                let  = EngineRoomServiceDB.LogEventType.WARNING;
                desc = String.Format("Engine {0} Oil sensor {1} gives {2} ... {3}", Running ? "running for " + secsSinceLastOn : "off for " + secsSinceLastOff, OilSensor.State, StateOfOil, rpmDesc);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(OilSensor.ID, BBAlarmsService.AlarmState.SEVERE, desc);
                break;

            case OilState.SENSOR_FAULT:
                let  = EngineRoomServiceDB.LogEventType.WARNING;
                desc = String.Format("Engine {0} Oil sensor {1} gives {2} ... {3}", Running ? "running for " + secsSinceLastOn : "off for " + secsSinceLastOff, OilSensor.State, StateOfOil, rpmDesc);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(OilSensor.ID, BBAlarmsService.AlarmState.MODERATE, desc);
                break;

            case OilState.OK_ENGINE_OFF:
            case OilState.OK_ENGINE_ON:
                let  = EngineRoomServiceDB.LogEventType.INFO;
                desc = String.Format("Engine {0} Oil sensor {1} gives {2}... {3}", Running ? "running for " + secsSinceLastOn : "off for " + secsSinceLastOff, OilSensor.State, StateOfOil, rpmDesc);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(OilSensor.ID, BBAlarmsService.AlarmState.OFF, desc);
                break;
            }

            if (msg != null && (isEvent || !returnEventsOnly))
            {
                messages.Add(msg);
                if (isEvent)
                {
                    erdb.LogEvent(let, OilSensor.ID, desc);
                }
            }


            //Temp state
            TemperatureState tempState = StateOfTemperature; //keep a record

            if (!Running || (TempSensor.AverageTemperature <= TemperatureThresholds[TemperatureState.OK]))
            {
                StateOfTemperature = TemperatureState.OK;
            }
            else if (TempSensor.AverageTemperature <= TemperatureThresholds[TemperatureState.HOT])
            {
                StateOfTemperature = TemperatureState.HOT;
            }
            else
            {
                StateOfTemperature = TemperatureState.TOO_HOT;
            }

            msg     = null;
            isEvent = tempState != StateOfTemperature;
            switch (StateOfTemperature)
            {
            case TemperatureState.TOO_HOT:
                let  = EngineRoomServiceDB.LogEventType.WARNING;
                desc = String.Format("Temp sensor: {0} {1}", TempSensor.AverageTemperature, StateOfTemperature);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(TempSensor.ID, BBAlarmsService.AlarmState.CRITICAL, desc);
                break;

            case TemperatureState.HOT:
                let  = EngineRoomServiceDB.LogEventType.WARNING;
                desc = String.Format("Temp sensor: {0} {1}", TempSensor.AverageTemperature, StateOfTemperature);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(TempSensor.ID, BBAlarmsService.AlarmState.SEVERE, desc);
                break;

            case TemperatureState.OK:
                let  = EngineRoomServiceDB.LogEventType.INFO;
                desc = String.Format("Temp sensor: {0} {1}", TempSensor.AverageTemperature, StateOfTemperature);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(TempSensor.ID, BBAlarmsService.AlarmState.OFF, desc);
                break;
            }
            if (msg != null && (isEvent || !returnEventsOnly))
            {
                messages.Add(msg);
                if (isEvent)
                {
                    erdb.LogEvent(let, TempSensor.ID, desc);
                }
            }

            //RPM state
            RPMState rpmState = StateOfRPM;

            if (!Running)
            {
                StateOfRPM = RPMState.OFF;
            }
            else if (secsSinceLastOn > 10)
            {
                if (RPM.AverageRPM < RPMThresholds[RPMState.SLOW])
                {
                    StateOfRPM = RPMState.SLOW;
                }
                else if (RPM.AverageRPM < RPMThresholds[RPMState.NORMAL])
                {
                    StateOfRPM = RPMState.NORMAL;
                }
                else if (RPM.AverageRPM < RPMThresholds[RPMState.FAST])
                {
                    StateOfRPM = RPMState.FAST;
                }
                else
                {
                    StateOfRPM = RPMState.TOO_FAST;
                }
            }

            msg     = null;
            isEvent = rpmState != StateOfRPM;
            switch (StateOfRPM)
            {
            case RPMState.OFF:
            case RPMState.SLOW:
            case RPMState.NORMAL:
                let  = EngineRoomServiceDB.LogEventType.INFO;
                desc = String.Format("RPM (Instant/Average): {0}/{1} gives state {2}", RPM.RPM, RPM.AverageRPM, StateOfRPM);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(RPM.ID, BBAlarmsService.AlarmState.OFF, desc);
                break;

            case RPMState.FAST:
                let  = EngineRoomServiceDB.LogEventType.WARNING;
                desc = String.Format("RPM (Instant/Average): {0}/{1} gives state {2}", RPM.RPM, RPM.AverageRPM, StateOfRPM);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(RPM.ID, BBAlarmsService.AlarmState.MODERATE, desc);
                break;

            case RPMState.TOO_FAST:
                let  = EngineRoomServiceDB.LogEventType.WARNING;
                desc = String.Format("RPM (Instant/Average): {0}/{1} gives state {2}", RPM.RPM, RPM.AverageRPM, StateOfRPM);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(RPM.ID, BBAlarmsService.AlarmState.SEVERE, desc);
                break;
            }
            if (msg != null && (isEvent || !returnEventsOnly))
            {
                messages.Add(msg);
                if (isEvent)
                {
                    erdb.LogEvent(let, RPM.ID, desc);
                }
            }
        }