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