Hardware/HDD/SmartAttribute.cs
author moel.mich
Mon, 02 Jan 2012 20:45:18 +0000
changeset 329 756af5ee409e
child 340 600962f8a298
permissions -rw-r--r--
Small corrections for AMD family 15h CPUs (based on documentation).
     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
    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     public SmartAttribute(byte identifier, string name,
    79       RawValueConversion rawValueConversion, SensorType? sensorType, 
    80       int sensorChannel) 
    81     {
    82       this.Identifier = identifier;
    83       this.Name = name;
    84       this.rawValueConversion = rawValueConversion;
    85       this.SensorType = sensorType;
    86       this.SensorChannel = sensorChannel;
    87     }
    88 
    89     /// <summary>
    90     /// Gets the SMART identifier.
    91     /// </summary>
    92     public byte Identifier { get; private set; }
    93 
    94     public string Name { get; private set; }
    95 
    96     public SensorType? SensorType { get; private set; }
    97 
    98     public int SensorChannel { get; private set; }
    99 
   100     public bool HasRawValueConversion {
   101       get {
   102         return rawValueConversion != null;
   103       }
   104     }
   105 
   106     public float ConvertValue(DriveAttributeValue value) {
   107       if (rawValueConversion == null) {
   108         return value.AttrValue;
   109       } else {
   110         return rawValueConversion(value.RawValue, value.AttrValue);
   111       }
   112     }
   113 
   114     public delegate float RawValueConversion(byte[] rawValue, byte value);
   115   }
   116 }