Esempio n. 1
0
            public WaterLevelGroup(
                string name,
                float highAnalogAlarmSetpoint,
                bool enableHighAnalogAlarm,
                float lowAnalogAlarmSetpoint,
                bool enableLowAnalogAlarm,
                IEnumerable <string> floatSwitches,
                IEnumerable <string> waterLevelSensors)
            {
                this.name  = name;
                level      = 0f;
                dataLogger = Factory.GetDataLogger(string.Format("{0}WaterLevel", this.name.RemoveWhitespace()));

                this.highAnalogAlarmSetpoint = highAnalogAlarmSetpoint;
                this.enableHighAnalogAlarm   = enableHighAnalogAlarm;
                if (this.enableHighAnalogAlarm)
                {
                    highAnalogAlarmIndex = Alarm.Subscribe(string.Format("{0} High Water Level (Analog)", this.name));
                }
                Alarm.AddAlarmHandler(highAnalogAlarmIndex, OnHighAlarm);

                this.lowAnalogAlarmSetpoint = lowAnalogAlarmSetpoint;
                this.enableLowAnalogAlarm   = enableLowAnalogAlarm;
                if (this.enableLowAnalogAlarm)
                {
                    lowAnalogAlarmIndex = Alarm.Subscribe(string.Format("{0} Low Water Level (Analog)", this.name));
                }
                Alarm.AddAlarmHandler(lowAnalogAlarmIndex, OnLowAlarm);

                highSwitchAlarmIndex = Alarm.Subscribe(string.Format("{0} High Water Level (Switch)", this.name));
                lowSwitchAlarmIndex  = Alarm.Subscribe(string.Format("{0} Low Water Level (Switch)", this.name));
                Alarm.AddAlarmHandler(highSwitchAlarmIndex, OnHighAlarm);
                Alarm.AddAlarmHandler(lowSwitchAlarmIndex, OnLowAlarm);

                this.floatSwitches = new List <string> (floatSwitches);
                foreach (var floatSwitch in this.floatSwitches)
                {
                    Subscribe(Sensors.FloatSwitches.GetGadgetEventPublisherKey(floatSwitch));
                }

                this.waterLevelSensors = new Dictionary <string, InternalWaterLevelSensorState> ();
                foreach (var waterLevelSensor in waterLevelSensors)
                {
                    this.waterLevelSensors.Add(waterLevelSensor, new InternalWaterLevelSensorState());
                    Subscribe(Sensors.WaterLevelSensors.GetGadgetEventPublisherKey(waterLevelSensor));
                }
            }