Hardware/HDD/SmartAttribute.cs
author moel.mich
Sat, 07 Sep 2013 08:07:11 +0000
changeset 423 47f5dcaf8e9f
parent 344 3145aadca3d2
permissions -rw-r--r--
Fixed an issue with the Nuvoton NCT6791D (hardware monitor i/o space lock wasn't disabled before attempting to read data).
moel@324
     1
/*
moel@324
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@324
     6
 
moel@344
     7
  Copyright (C) 2011-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
  Copyright (C) 2011 Roland Reinl <roland-reinl@gmx.de>
moel@344
     9
	
moel@324
    10
*/
moel@324
    11
moel@324
    12
using System;
moel@324
    13
using System.Collections.Generic;
moel@374
    14
using OpenHardwareMonitor.Collections;
moel@324
    15
moel@324
    16
namespace OpenHardwareMonitor.Hardware.HDD {
moel@324
    17
  internal class SmartAttribute {
moel@324
    18
moel@324
    19
    private RawValueConversion rawValueConversion;
moel@324
    20
moel@324
    21
    /// <summary>
moel@324
    22
    /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
moel@324
    23
    /// </summary>
moel@324
    24
    /// <param name="identifier">The SMART identifier of the attribute.</param>
moel@324
    25
    /// <param name="name">The name of the attribute.</param>
moel@324
    26
    public SmartAttribute(byte identifier, string name) : 
moel@324
    27
      this(identifier, name, null, null, 0) { }
moel@324
    28
moel@324
    29
    /// <summary>
moel@324
    30
    /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
moel@324
    31
    /// </summary>
moel@324
    32
    /// <param name="identifier">The SMART identifier of the attribute.</param>
moel@324
    33
    /// <param name="name">The name of the attribute.</param>
moel@324
    34
    /// <param name="rawValueConversion">A delegate for converting the raw byte 
moel@324
    35
    /// array into a value (or null to use the attribute value).</param>
moel@324
    36
    public SmartAttribute(byte identifier, string name,
moel@324
    37
      RawValueConversion rawValueConversion) :
moel@324
    38
      this(identifier, name, rawValueConversion, null, 0) { }
moel@324
    39
moel@324
    40
    /// <summary>
moel@324
    41
    /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
moel@324
    42
    /// </summary>
moel@324
    43
    /// <param name="identifier">The SMART identifier of the attribute.</param>
moel@324
    44
    /// <param name="name">The name of the attribute.</param>
moel@324
    45
    /// <param name="rawValueConversion">A delegate for converting the raw byte 
moel@324
    46
    /// array into a value (or null to use the attribute value).</param>
moel@324
    47
    /// <param name="sensorType">Type of the sensor or null if no sensor is to 
moel@324
    48
    /// be created.</param>
moel@324
    49
    /// <param name="sensorChannel">If there exists more than one attribute with 
moel@324
    50
    /// the same sensor channel and type, then a sensor is created only for the  
moel@324
    51
    /// first attribute.</param>
moel@340
    52
    /// <param name="defaultHiddenSensor">True to hide the sensor initially.</param>
moel@374
    53
    /// <param name="parameterDescriptions">Description for the parameters of the sensor 
moel@374
    54
    /// (or null).</param>
moel@324
    55
    public SmartAttribute(byte identifier, string name,
moel@324
    56
      RawValueConversion rawValueConversion, SensorType? sensorType, 
moel@374
    57
      int sensorChannel, bool defaultHiddenSensor = false,
moel@374
    58
      ParameterDescription[] parameterDescriptions = null) 
moel@324
    59
    {
moel@324
    60
      this.Identifier = identifier;
moel@324
    61
      this.Name = name;
moel@324
    62
      this.rawValueConversion = rawValueConversion;
moel@324
    63
      this.SensorType = sensorType;
moel@324
    64
      this.SensorChannel = sensorChannel;
moel@340
    65
      this.DefaultHiddenSensor = defaultHiddenSensor;
moel@374
    66
      this.ParameterDescriptions = parameterDescriptions;
moel@324
    67
    }
moel@324
    68
moel@324
    69
    /// <summary>
moel@324
    70
    /// Gets the SMART identifier.
moel@324
    71
    /// </summary>
moel@324
    72
    public byte Identifier { get; private set; }
moel@324
    73
moel@324
    74
    public string Name { get; private set; }
moel@324
    75
moel@324
    76
    public SensorType? SensorType { get; private set; }
moel@324
    77
moel@324
    78
    public int SensorChannel { get; private set; }
moel@324
    79
moel@340
    80
    public bool DefaultHiddenSensor { get; private set; }
moel@340
    81
moel@374
    82
    public ParameterDescription[] ParameterDescriptions { get; private set; }
moel@374
    83
moel@324
    84
    public bool HasRawValueConversion {
moel@324
    85
      get {
moel@324
    86
        return rawValueConversion != null;
moel@324
    87
      }
moel@324
    88
    }
moel@324
    89
moel@374
    90
    public float ConvertValue(DriveAttributeValue value, 
moel@374
    91
      IReadOnlyArray<IParameter> parameters) 
moel@374
    92
    {
moel@324
    93
      if (rawValueConversion == null) {
moel@324
    94
        return value.AttrValue;
moel@324
    95
      } else {
moel@374
    96
        return rawValueConversion(value.RawValue, value.AttrValue, parameters);
moel@324
    97
      }
moel@324
    98
    }
moel@324
    99
moel@374
   100
    public delegate float RawValueConversion(byte[] rawValue, byte value,
moel@374
   101
      IReadOnlyArray<IParameter> parameters);
moel@324
   102
  }
moel@324
   103
}