2011-12-31 17:31:04 +00:00
|
|
|
|
/*
|
|
|
|
|
|
2012-05-27 14:23:31 +00:00
|
|
|
|
This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-12-31 17:31:04 +00:00
|
|
|
|
|
2015-12-13 18:11:48 +01:00
|
|
|
|
Copyright (C) 2011-2015 Michael Möller <mmoeller@openhardwaremonitor.org>
|
2012-05-27 14:23:31 +00:00
|
|
|
|
Copyright (C) 2011 Roland Reinl <roland-reinl@gmx.de>
|
|
|
|
|
|
2011-12-31 17:31:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2012-07-25 16:03:36 +00:00
|
|
|
|
using OpenHardwareMonitor.Collections;
|
2011-12-31 17:31:04 +00:00
|
|
|
|
|
|
|
|
|
namespace OpenHardwareMonitor.Hardware.HDD {
|
|
|
|
|
internal class SmartAttribute {
|
|
|
|
|
|
|
|
|
|
private RawValueConversion rawValueConversion;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="SmartAttribute"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="identifier">The SMART identifier of the attribute.</param>
|
|
|
|
|
/// <param name="name">The name of the attribute.</param>
|
|
|
|
|
public SmartAttribute(byte identifier, string name) :
|
2015-12-13 18:11:48 +01:00
|
|
|
|
this(identifier, name, null, null, 0, null) { }
|
2011-12-31 17:31:04 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="SmartAttribute"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="identifier">The SMART identifier of the attribute.</param>
|
|
|
|
|
/// <param name="name">The name of the attribute.</param>
|
|
|
|
|
/// <param name="rawValueConversion">A delegate for converting the raw byte
|
|
|
|
|
/// array into a value (or null to use the attribute value).</param>
|
|
|
|
|
public SmartAttribute(byte identifier, string name,
|
|
|
|
|
RawValueConversion rawValueConversion) :
|
2015-12-13 18:11:48 +01:00
|
|
|
|
this(identifier, name, rawValueConversion, null, 0, null) { }
|
2011-12-31 17:31:04 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="SmartAttribute"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="identifier">The SMART identifier of the attribute.</param>
|
|
|
|
|
/// <param name="name">The name of the attribute.</param>
|
|
|
|
|
/// <param name="rawValueConversion">A delegate for converting the raw byte
|
|
|
|
|
/// array into a value (or null to use the attribute value).</param>
|
|
|
|
|
/// <param name="sensorType">Type of the sensor or null if no sensor is to
|
|
|
|
|
/// be created.</param>
|
|
|
|
|
/// <param name="sensorChannel">If there exists more than one attribute with
|
|
|
|
|
/// the same sensor channel and type, then a sensor is created only for the
|
|
|
|
|
/// first attribute.</param>
|
2015-12-13 18:11:48 +01:00
|
|
|
|
/// <param name="sensorName">The name to be used for the sensor, or null if
|
|
|
|
|
/// no sensor is created.</param>
|
2012-02-14 23:07:55 +00:00
|
|
|
|
/// <param name="defaultHiddenSensor">True to hide the sensor initially.</param>
|
2012-07-25 16:03:36 +00:00
|
|
|
|
/// <param name="parameterDescriptions">Description for the parameters of the sensor
|
|
|
|
|
/// (or null).</param>
|
2011-12-31 17:31:04 +00:00
|
|
|
|
public SmartAttribute(byte identifier, string name,
|
|
|
|
|
RawValueConversion rawValueConversion, SensorType? sensorType,
|
2015-12-13 18:11:48 +01:00
|
|
|
|
int sensorChannel, string sensorName, bool defaultHiddenSensor = false,
|
2012-07-25 16:03:36 +00:00
|
|
|
|
ParameterDescription[] parameterDescriptions = null)
|
2011-12-31 17:31:04 +00:00
|
|
|
|
{
|
|
|
|
|
this.Identifier = identifier;
|
|
|
|
|
this.Name = name;
|
|
|
|
|
this.rawValueConversion = rawValueConversion;
|
|
|
|
|
this.SensorType = sensorType;
|
|
|
|
|
this.SensorChannel = sensorChannel;
|
2015-12-13 18:11:48 +01:00
|
|
|
|
this.SensorName = sensorName;
|
2012-02-14 23:07:55 +00:00
|
|
|
|
this.DefaultHiddenSensor = defaultHiddenSensor;
|
2012-07-25 16:03:36 +00:00
|
|
|
|
this.ParameterDescriptions = parameterDescriptions;
|
2011-12-31 17:31:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the SMART identifier.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Identifier { get; private set; }
|
|
|
|
|
|
|
|
|
|
public string Name { get; private set; }
|
|
|
|
|
|
|
|
|
|
public SensorType? SensorType { get; private set; }
|
|
|
|
|
|
|
|
|
|
public int SensorChannel { get; private set; }
|
|
|
|
|
|
2015-12-13 18:11:48 +01:00
|
|
|
|
public string SensorName { get; private set; }
|
|
|
|
|
|
2012-02-14 23:07:55 +00:00
|
|
|
|
public bool DefaultHiddenSensor { get; private set; }
|
|
|
|
|
|
2012-07-25 16:03:36 +00:00
|
|
|
|
public ParameterDescription[] ParameterDescriptions { get; private set; }
|
|
|
|
|
|
2011-12-31 17:31:04 +00:00
|
|
|
|
public bool HasRawValueConversion {
|
|
|
|
|
get {
|
|
|
|
|
return rawValueConversion != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 16:03:36 +00:00
|
|
|
|
public float ConvertValue(DriveAttributeValue value,
|
|
|
|
|
IReadOnlyArray<IParameter> parameters)
|
|
|
|
|
{
|
2011-12-31 17:31:04 +00:00
|
|
|
|
if (rawValueConversion == null) {
|
|
|
|
|
return value.AttrValue;
|
|
|
|
|
} else {
|
2012-07-25 16:03:36 +00:00
|
|
|
|
return rawValueConversion(value.RawValue, value.AttrValue, parameters);
|
2011-12-31 17:31:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 16:03:36 +00:00
|
|
|
|
public delegate float RawValueConversion(byte[] rawValue, byte value,
|
|
|
|
|
IReadOnlyArray<IParameter> parameters);
|
2011-12-31 17:31:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|