Exemple #1
0
        /// <summary>
        /// Update current sensor Value with the reading.
        /// </summary>
        /// <param name="timestamp">Time when reading was sampled</param>
        /// <param name="val">Value that was read</param>
        /// <param name="bias">Optional bias to add to value</param>
        public void UpdateValue(DateTime timestamp, float?val, float?bias)
        {
            if (DeviceState == SensorDeviceState.Simulated && GetSimValue != null)
            {
                val = GetSimValue();
            }
            if (DeviceState != SensorDeviceState.Offline && val.HasValue)
            {
                Value = val.Value;
                if (bias.HasValue)
                {
                    Value += bias.Value;
                }

                var fault = new SensorFault();

                if (Value > DangerHi)
                {
                    fault.Type = SensorFaultType.FromDangerHi;
                }
                else if (Value < DangerLo)
                {
                    fault.Type = SensorFaultType.FromDangerLo;
                }
                if (Triggers != null)
                {
                    foreach (var t in Triggers)
                    {
                        if ((t.cmp > 0 && Value > t.val) || (t.cmp < 0 && Value < t.val))
                        {
                            fault.Type = SensorFaultType.FromTrigger;
                            fault.Id   = t.id;
                        }
                    }
                }

                if (FaultState != SensorFaultState.Faulted && fault.Type != SensorFaultType.NoFault)
                {
                    FaultState = SensorFaultState.Faulted;
                    Faulted?.Invoke(this, fault, timestamp);
                }
            }
        }
Exemple #2
0
 public string FaultString(SensorFault fault)
 {
     return(this.ToString() +
            $"\nFaulted State: {FaultState}\nDevice State: {DeviceState}\nSensor Value: {Value}\nFault ID: {fault.Id}\nFault Type: {fault.Type}");
 }