/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. Copyright (C) 2011-2015 Michael Möller Copyright (C) 2011 Roland Reinl */ using System; using System.Collections.Generic; using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware.HDD { internal class SmartAttribute { private RawValueConversion rawValueConversion; /// /// Initializes a new instance of the class. /// /// The SMART identifier of the attribute. /// The name of the attribute. public SmartAttribute(byte identifier, string name) : this(identifier, name, null, null, 0, null) { } /// /// Initializes a new instance of the class. /// /// The SMART identifier of the attribute. /// The name of the attribute. /// A delegate for converting the raw byte /// array into a value (or null to use the attribute value). public SmartAttribute(byte identifier, string name, RawValueConversion rawValueConversion) : this(identifier, name, rawValueConversion, null, 0, null) { } /// /// Initializes a new instance of the class. /// /// The SMART identifier of the attribute. /// The name of the attribute. /// A delegate for converting the raw byte /// array into a value (or null to use the attribute value). /// Type of the sensor or null if no sensor is to /// be created. /// If there exists more than one attribute with /// the same sensor channel and type, then a sensor is created only for the /// first attribute. /// The name to be used for the sensor, or null if /// no sensor is created. /// True to hide the sensor initially. /// Description for the parameters of the sensor /// (or null). public SmartAttribute(byte identifier, string name, RawValueConversion rawValueConversion, SensorType? sensorType, int sensorChannel, string sensorName, bool defaultHiddenSensor = false, ParameterDescription[] parameterDescriptions = null) { this.Identifier = identifier; this.Name = name; this.rawValueConversion = rawValueConversion; this.SensorType = sensorType; this.SensorChannel = sensorChannel; this.SensorName = sensorName; this.DefaultHiddenSensor = defaultHiddenSensor; this.ParameterDescriptions = parameterDescriptions; } /// /// Gets the SMART identifier. /// public byte Identifier { get; private set; } public string Name { get; private set; } public SensorType? SensorType { get; private set; } public int SensorChannel { get; private set; } public string SensorName { get; private set; } public bool DefaultHiddenSensor { get; private set; } public ParameterDescription[] ParameterDescriptions { get; private set; } public bool HasRawValueConversion { get { return rawValueConversion != null; } } public float ConvertValue(DriveAttributeValue value, IReadOnlyArray parameters) { if (rawValueConversion == null) { return value.AttrValue; } else { return rawValueConversion(value.RawValue, value.AttrValue, parameters); } } public delegate float RawValueConversion(byte[] rawValue, byte value, IReadOnlyArray parameters); } }