Esempio n. 1
0
        protected sealed override void CreateSensors()
        {
            _sensors = new Dictionary <SmartAttribute, Sensor>();

            if (Smart.IsValid)
            {
                byte[] smartIds = Smart.ReadSmartData().Select(x => x.Id).ToArray();

                // unique attributes by SensorType and SensorChannel.
                IEnumerable <SmartAttribute> smartAttributes = SmartAttributes
                                                               .Where(x => x.SensorType.HasValue && smartIds.Contains(x.Id))
                                                               .GroupBy(x => new { x.SensorType.Value, x.SensorChannel })
                                                               .Select(x => x.First());

                _sensors = smartAttributes.ToDictionary(attribute => attribute,
                                                        attribute => new Sensor(attribute.SensorName,
                                                                                attribute.SensorChannel,
                                                                                attribute.DefaultHiddenSensor,
                                                                                attribute.SensorType.GetValueOrDefault(),
                                                                                this,
                                                                                attribute.ParameterDescriptions,
                                                                                _settings));

                foreach (KeyValuePair <SmartAttribute, Sensor> sensor in _sensors)
                {
                    ActivateSensor(sensor.Value);
                }
            }

            base.CreateSensors();
        }
Esempio n. 2
0
        protected override void UpdateSensors()
        {
            if (Smart.IsValid)
            {
                Kernel32.SMART_ATTRIBUTE[] smartAttributes = Smart.ReadSmartData();

                foreach (KeyValuePair <SmartAttribute, Sensor> keyValuePair in _sensors)
                {
                    SmartAttribute attribute = keyValuePair.Key;
                    foreach (Kernel32.SMART_ATTRIBUTE value in smartAttributes)
                    {
                        if (value.Id == attribute.Id)
                        {
                            Sensor sensor = keyValuePair.Value;
                            sensor.Value = attribute.ConvertValue(value, sensor.Parameters);
                        }
                    }
                }

                UpdateAdditionalSensors(smartAttributes);
            }
        }
Esempio n. 3
0
        protected override void GetReport(StringBuilder r)
        {
            if (Smart.IsValid)
            {
                Kernel32.SMART_ATTRIBUTE[] values     = Smart.ReadSmartData();
                Kernel32.SMART_THRESHOLD[] thresholds = Smart.ReadSmartThresholds();
                if (values.Length > 0)
                {
                    r.AppendFormat(CultureInfo.InvariantCulture,
                                   " {0}{1}{2}{3}{4}{5}{6}{7}",
                                   "Id".PadRight(3),
                                   "Description".PadRight(35),
                                   "Raw Value".PadRight(13),
                                   "Worst".PadRight(6),
                                   "Value".PadRight(6),
                                   "Threshold".PadRight(6),
                                   "Physical".PadRight(8),
                                   Environment.NewLine);

                    foreach (Kernel32.SMART_ATTRIBUTE value in values)
                    {
                        if (value.Id == 0x00)
                        {
                            break;
                        }

                        byte?threshold = null;
                        foreach (Kernel32.SMART_THRESHOLD t in thresholds)
                        {
                            if (t.Id == value.Id)
                            {
                                threshold = t.Threshold;
                            }
                        }

                        string description = "Unknown";
                        float? physical    = null;
                        foreach (SmartAttribute a in SmartAttributes)
                        {
                            if (a.Id == value.Id)
                            {
                                description = a.Name;
                                if (a.HasRawValueConversion | a.SensorType.HasValue)
                                {
                                    physical = a.ConvertValue(value, null);
                                }
                                else
                                {
                                    physical = null;
                                }
                            }
                        }

                        string raw = BitConverter.ToString(value.RawValue);
                        r.AppendFormat(CultureInfo.InvariantCulture,
                                       " {0}{1}{2}{3}{4}{5}{6}{7}",
                                       value.Id.ToString("X2").PadRight(3),
                                       description.PadRight(35),
                                       raw.Replace("-", string.Empty).PadRight(13),
                                       value.WorstValue.ToString(CultureInfo.InvariantCulture).PadRight(6),
                                       value.CurrentValue.ToString(CultureInfo.InvariantCulture).PadRight(6),
                                       (threshold.HasValue
                                         ? threshold.Value.ToString(CultureInfo.InvariantCulture)
                                         : "-").PadRight(6),
                                       (physical.HasValue ? physical.Value.ToString(CultureInfo.InvariantCulture) : "-").PadRight(8),
                                       Environment.NewLine);
                    }

                    r.AppendLine();
                }
            }
        }