Hardware/HDD/SmartAttribute.cs
changeset 324 c6ee430d6995
child 340 600962f8a298
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Hardware/HDD/SmartAttribute.cs	Sat Dec 31 17:31:04 2011 +0000
     1.3 @@ -0,0 +1,116 @@
     1.4 +/*
     1.5 +  
     1.6 +  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     1.7 +
     1.8 +  The contents of this file are subject to the Mozilla Public License Version
     1.9 +  1.1 (the "License"); you may not use this file except in compliance with
    1.10 +  the License. You may obtain a copy of the License at
    1.11 + 
    1.12 +  http://www.mozilla.org/MPL/
    1.13 +
    1.14 +  Software distributed under the License is distributed on an "AS IS" basis,
    1.15 +  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    1.16 +  for the specific language governing rights and limitations under the License.
    1.17 +
    1.18 +  The Original Code is the Open Hardware Monitor code.
    1.19 +
    1.20 +  The Initial Developer of the Original Code is 
    1.21 +  Michael Möller <m.moeller@gmx.ch>.
    1.22 +  Portions created by the Initial Developer are Copyright (C) 2011
    1.23 +  the Initial Developer. All Rights Reserved.
    1.24 +
    1.25 +  Contributor(s):
    1.26 +    Roland Reinl <roland-reinl@gmx.de>
    1.27 + 
    1.28 +  Alternatively, the contents of this file may be used under the terms of
    1.29 +  either the GNU General Public License Version 2 or later (the "GPL"), or
    1.30 +  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    1.31 +  in which case the provisions of the GPL or the LGPL are applicable instead
    1.32 +  of those above. If you wish to allow use of your version of this file only
    1.33 +  under the terms of either the GPL or the LGPL, and not to allow others to
    1.34 +  use your version of this file under the terms of the MPL, indicate your
    1.35 +  decision by deleting the provisions above and replace them with the notice
    1.36 +  and other provisions required by the GPL or the LGPL. If you do not delete
    1.37 +  the provisions above, a recipient may use your version of this file under
    1.38 +  the terms of any one of the MPL, the GPL or the LGPL.
    1.39 + 
    1.40 +*/
    1.41 +
    1.42 +using System;
    1.43 +using System.Collections.Generic;
    1.44 +
    1.45 +namespace OpenHardwareMonitor.Hardware.HDD {
    1.46 +  internal class SmartAttribute {
    1.47 +
    1.48 +    private RawValueConversion rawValueConversion;
    1.49 +
    1.50 +    /// <summary>
    1.51 +    /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
    1.52 +    /// </summary>
    1.53 +    /// <param name="identifier">The SMART identifier of the attribute.</param>
    1.54 +    /// <param name="name">The name of the attribute.</param>
    1.55 +    public SmartAttribute(byte identifier, string name) : 
    1.56 +      this(identifier, name, null, null, 0) { }
    1.57 +
    1.58 +    /// <summary>
    1.59 +    /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
    1.60 +    /// </summary>
    1.61 +    /// <param name="identifier">The SMART identifier of the attribute.</param>
    1.62 +    /// <param name="name">The name of the attribute.</param>
    1.63 +    /// <param name="rawValueConversion">A delegate for converting the raw byte 
    1.64 +    /// array into a value (or null to use the attribute value).</param>
    1.65 +    public SmartAttribute(byte identifier, string name,
    1.66 +      RawValueConversion rawValueConversion) :
    1.67 +      this(identifier, name, rawValueConversion, null, 0) { }
    1.68 +
    1.69 +    /// <summary>
    1.70 +    /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
    1.71 +    /// </summary>
    1.72 +    /// <param name="identifier">The SMART identifier of the attribute.</param>
    1.73 +    /// <param name="name">The name of the attribute.</param>
    1.74 +    /// <param name="rawValueConversion">A delegate for converting the raw byte 
    1.75 +    /// array into a value (or null to use the attribute value).</param>
    1.76 +    /// <param name="sensorType">Type of the sensor or null if no sensor is to 
    1.77 +    /// be created.</param>
    1.78 +    /// <param name="sensorChannel">If there exists more than one attribute with 
    1.79 +    /// the same sensor channel and type, then a sensor is created only for the  
    1.80 +    /// first attribute.</param>
    1.81 +    public SmartAttribute(byte identifier, string name,
    1.82 +      RawValueConversion rawValueConversion, SensorType? sensorType, 
    1.83 +      int sensorChannel) 
    1.84 +    {
    1.85 +      this.Identifier = identifier;
    1.86 +      this.Name = name;
    1.87 +      this.rawValueConversion = rawValueConversion;
    1.88 +      this.SensorType = sensorType;
    1.89 +      this.SensorChannel = sensorChannel;
    1.90 +    }
    1.91 +
    1.92 +    /// <summary>
    1.93 +    /// Gets the SMART identifier.
    1.94 +    /// </summary>
    1.95 +    public byte Identifier { get; private set; }
    1.96 +
    1.97 +    public string Name { get; private set; }
    1.98 +
    1.99 +    public SensorType? SensorType { get; private set; }
   1.100 +
   1.101 +    public int SensorChannel { get; private set; }
   1.102 +
   1.103 +    public bool HasRawValueConversion {
   1.104 +      get {
   1.105 +        return rawValueConversion != null;
   1.106 +      }
   1.107 +    }
   1.108 +
   1.109 +    public float ConvertValue(DriveAttributeValue value) {
   1.110 +      if (rawValueConversion == null) {
   1.111 +        return value.AttrValue;
   1.112 +      } else {
   1.113 +        return rawValueConversion(value.RawValue, value.AttrValue);
   1.114 +      }
   1.115 +    }
   1.116 +
   1.117 +    public delegate float RawValueConversion(byte[] rawValue, byte value);
   1.118 +  }
   1.119 +}