Hardware/HDD/SmartAttribute.cs
author moel.mich
Tue, 14 Feb 2012 23:07:55 +0000
changeset 340 600962f8a298
parent 324 c6ee430d6995
child 344 3145aadca3d2
permissions -rw-r--r--
Added a new sensor type "Factor" for dimensionless values (and similar) that are not to be shown as percent ("Level" type). Changed the write amplification sensor to use the new "Factor" sensor type. Added the temperature SMART attribute for Sandforce SSDs as hidden sensor (as it may show fake results on some hardware).
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     5   The contents of this file are subject to the Mozilla Public License Version
     6   1.1 (the "License"); you may not use this file except in compliance with
     7   the License. You may obtain a copy of the License at
     8  
     9   http://www.mozilla.org/MPL/
    10 
    11   Software distributed under the License is distributed on an "AS IS" basis,
    12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    13   for the specific language governing rights and limitations under the License.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    17   The Initial Developer of the Original Code is 
    18   Michael Möller <m.moeller@gmx.ch>.
    19   Portions created by the Initial Developer are Copyright (C) 2011-2012
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23     Roland Reinl <roland-reinl@gmx.de>
    24  
    25   Alternatively, the contents of this file may be used under the terms of
    26   either the GNU General Public License Version 2 or later (the "GPL"), or
    27   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    28   in which case the provisions of the GPL or the LGPL are applicable instead
    29   of those above. If you wish to allow use of your version of this file only
    30   under the terms of either the GPL or the LGPL, and not to allow others to
    31   use your version of this file under the terms of the MPL, indicate your
    32   decision by deleting the provisions above and replace them with the notice
    33   and other provisions required by the GPL or the LGPL. If you do not delete
    34   the provisions above, a recipient may use your version of this file under
    35   the terms of any one of the MPL, the GPL or the LGPL.
    36  
    37 */
    38 
    39 using System;
    40 using System.Collections.Generic;
    41 
    42 namespace OpenHardwareMonitor.Hardware.HDD {
    43   internal class SmartAttribute {
    44 
    45     private RawValueConversion rawValueConversion;
    46 
    47     /// <summary>
    48     /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
    49     /// </summary>
    50     /// <param name="identifier">The SMART identifier of the attribute.</param>
    51     /// <param name="name">The name of the attribute.</param>
    52     public SmartAttribute(byte identifier, string name) : 
    53       this(identifier, name, null, null, 0) { }
    54 
    55     /// <summary>
    56     /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
    57     /// </summary>
    58     /// <param name="identifier">The SMART identifier of the attribute.</param>
    59     /// <param name="name">The name of the attribute.</param>
    60     /// <param name="rawValueConversion">A delegate for converting the raw byte 
    61     /// array into a value (or null to use the attribute value).</param>
    62     public SmartAttribute(byte identifier, string name,
    63       RawValueConversion rawValueConversion) :
    64       this(identifier, name, rawValueConversion, null, 0) { }
    65 
    66     /// <summary>
    67     /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
    68     /// </summary>
    69     /// <param name="identifier">The SMART identifier of the attribute.</param>
    70     /// <param name="name">The name of the attribute.</param>
    71     /// <param name="rawValueConversion">A delegate for converting the raw byte 
    72     /// array into a value (or null to use the attribute value).</param>
    73     /// <param name="sensorType">Type of the sensor or null if no sensor is to 
    74     /// be created.</param>
    75     /// <param name="sensorChannel">If there exists more than one attribute with 
    76     /// the same sensor channel and type, then a sensor is created only for the  
    77     /// first attribute.</param>
    78     /// <param name="defaultHiddenSensor">True to hide the sensor initially.</param>
    79     public SmartAttribute(byte identifier, string name,
    80       RawValueConversion rawValueConversion, SensorType? sensorType, 
    81       int sensorChannel, bool defaultHiddenSensor = false) 
    82     {
    83       this.Identifier = identifier;
    84       this.Name = name;
    85       this.rawValueConversion = rawValueConversion;
    86       this.SensorType = sensorType;
    87       this.SensorChannel = sensorChannel;
    88       this.DefaultHiddenSensor = defaultHiddenSensor;
    89     }
    90 
    91     /// <summary>
    92     /// Gets the SMART identifier.
    93     /// </summary>
    94     public byte Identifier { get; private set; }
    95 
    96     public string Name { get; private set; }
    97 
    98     public SensorType? SensorType { get; private set; }
    99 
   100     public int SensorChannel { get; private set; }
   101 
   102     public bool DefaultHiddenSensor { get; private set; }
   103 
   104     public bool HasRawValueConversion {
   105       get {
   106         return rawValueConversion != null;
   107       }
   108     }
   109 
   110     public float ConvertValue(DriveAttributeValue value) {
   111       if (rawValueConversion == null) {
   112         return value.AttrValue;
   113       } else {
   114         return rawValueConversion(value.RawValue, value.AttrValue);
   115       }
   116     }
   117 
   118     public delegate float RawValueConversion(byte[] rawValue, byte value);
   119   }
   120 }