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