Hardware/HDD/SSDSandforce.cs
author moel.mich
Mon, 23 Jul 2012 21:54:35 +0000
changeset 370 8e4dedc41924
parent 343 46b6b567f14f
child 374 ea86cea126bc
permissions -rw-r--r--
Added a RAM hardware and sensor, fixed Issue 115.
     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) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	Copyright (C) 2010 Paul Werelds
     9 	
    10 */
    11 
    12 namespace OpenHardwareMonitor.Hardware.HDD {
    13   using System.Collections.Generic;
    14 
    15   [NamePrefix(""), RequireSmart(0xAB), RequireSmart(0xB1)]
    16   internal class SSDSandforce : AbstractHarddrive {
    17 
    18     private static readonly IEnumerable<SmartAttribute> smartAttributes =
    19       new List<SmartAttribute> {
    20       new SmartAttribute(0x01, SmartNames.RawReadErrorRate),
    21       new SmartAttribute(0x05, SmartNames.RetiredBlockCount, RawToInt),
    22       new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt),
    23       new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt),
    24       new SmartAttribute(0xAB, SmartNames.ProgramFailCount, RawToInt),
    25       new SmartAttribute(0xAC, SmartNames.EraseFailCount, RawToInt),
    26       new SmartAttribute(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt),
    27       new SmartAttribute(0xB1, SmartNames.WearRangeDelta, RawToInt),
    28       new SmartAttribute(0xB5, SmartNames.AlternativeProgramFailCount, RawToInt),
    29       new SmartAttribute(0xB6, SmartNames.AlternativeEraseFailCount, RawToInt),
    30       new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt),
    31       new SmartAttribute(0xC2, SmartNames.Temperature, (byte[] raw, byte value) 
    32         => { return value; }, SensorType.Temperature, 0, true), 
    33       new SmartAttribute(0xC3, SmartNames.UnrecoverableEcc), 
    34       new SmartAttribute(0xC4, SmartNames.ReallocationEventCount, RawToInt),
    35       new SmartAttribute(0xE7, SmartNames.RemainingLife, null, 
    36         SensorType.Level, 0),
    37       new SmartAttribute(0xE9, SmartNames.ControllerWritesToNAND, RawToInt,
    38         SensorType.Data, 0),
    39       new SmartAttribute(0xEA, SmartNames.HostWritesToController, RawToInt, 
    40         SensorType.Data, 1),
    41       new SmartAttribute(0xF1, SmartNames.HostWrites, RawToInt, 
    42         SensorType.Data, 1),
    43       new SmartAttribute(0xF2, SmartNames.HostReads, RawToInt, 
    44         SensorType.Data, 2)
    45     };
    46 
    47     private Sensor writeAmplification;
    48 
    49     public SSDSandforce(ISmart smart, string name, string firmwareRevision, 
    50       int index, ISettings settings) 
    51       : base(smart, name, firmwareRevision,  index, smartAttributes, settings) 
    52     {
    53       this.writeAmplification = new Sensor("Write Amplification", 1, 
    54         SensorType.Factor, this, settings);    
    55     }
    56 
    57     public override void UpdateAdditionalSensors(DriveAttributeValue[] values) {
    58       float? controllerWritesToNAND = null;
    59       float? hostWritesToController = null;
    60       foreach (DriveAttributeValue value in values) {
    61         if (value.Identifier == 0xE9)
    62           controllerWritesToNAND = RawToInt(value.RawValue, value.AttrValue);
    63 
    64         if (value.Identifier == 0xEA)
    65           hostWritesToController = RawToInt(value.RawValue, value.AttrValue);
    66       }
    67       if (controllerWritesToNAND.HasValue && hostWritesToController.HasValue) {
    68         if (hostWritesToController.Value > 0)
    69           writeAmplification.Value =
    70             controllerWritesToNAND.Value / hostWritesToController.Value;
    71         else
    72           writeAmplification.Value = 0;
    73         ActivateSensor(writeAmplification);
    74       }
    75     }
    76   }
    77 }