Hardware/HDD/DebugSmart.cs
author moel.mich
Sun, 01 Jan 2012 10:14:42 +0000
changeset 325 4c31341a4800
parent 324 c6ee430d6995
child 328 f837f9f0973e
permissions -rw-r--r--
Added the hard drive firmware version to the report. This could be important if the SMART attribute layout changes with firmware versions on some drives.
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     5   The contents of this file are subject to the Mozilla Public License Version
     6   1.1 (the "License"); you may not use this file except in compliance with
     7   the License. You may obtain a copy of the License at
     8  
     9   http://www.mozilla.org/MPL/
    10 
    11   Software distributed under the License is distributed on an "AS IS" basis,
    12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    13   for the specific language governing rights and limitations under the License.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    17   The Initial Developer of the Original Code is 
    18   Michael Möller <m.moeller@gmx.ch>.
    19   Portions created by the Initial Developer are Copyright (C) 2011-2012
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23 
    24   Alternatively, the contents of this file may be used under the terms of
    25   either the GNU General Public License Version 2 or later (the "GPL"), or
    26   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    27   in which case the provisions of the GPL or the LGPL are applicable instead
    28   of those above. If you wish to allow use of your version of this file only
    29   under the terms of either the GPL or the LGPL, and not to allow others to
    30   use your version of this file under the terms of the MPL, indicate your
    31   decision by deleting the provisions above and replace them with the notice
    32   and other provisions required by the GPL or the LGPL. If you do not delete
    33   the provisions above, a recipient may use your version of this file under
    34   the terms of any one of the MPL, the GPL or the LGPL.
    35  
    36 */
    37 
    38 using System;
    39 using System.Collections.Generic;
    40 using System.Text;
    41 
    42 namespace OpenHardwareMonitor.Hardware.HDD {
    43 
    44 #if DEBUG
    45 
    46   internal class DebugSmart : ISmart {
    47 
    48     private Drive[] drives = {
    49       new Drive("KINGSTON SNV425S264GB", 16,
    50         @" 01 000000000000 100 100      
    51            02 000000000000 100 100      
    52            03 000000000000 100 100      
    53            05 000000000000 100 100      
    54            07 000000000000 100 100      
    55            08 000000000000 100 100      
    56            09 821E00000000 100 100      
    57            0A 000000000000 100 100      
    58            0C 950200000000 100 100      
    59            A8 000000000000 100 100      
    60            AF 000000000000 100 100      
    61            C0 000000000000 100 100      
    62            C2 290014002B00 100 41       
    63            C5 000000000000 100 100      
    64            F0 000000000000 100 100      
    65            AA 07007B000000 100 100      
    66            AD 0E1E71304919 100 100"),
    67 
    68       new Drive("PLEXTOR  PX-128M2S", 16, 
    69         @" 01 000000000000 100 100 0   
    70            03 000000000000 100 100 0   
    71            04 000000000000 100 100 0   
    72            05 000000000000 100 100 0   
    73            09 250100000000 100 100 0   
    74            0A 000000000000 100 100 0   
    75            0C D10000000000 100 100 0   
    76            B2 000000000000 100 100 0   
    77            BB 000000000000 100 100 0   
    78            BE 000000000000 100 100 0   
    79            C0 000000000000 100 100 0   
    80            C1 000000000000 100 100 0   
    81            C2 000000000000 100 100 0   
    82            C3 000000000000 100 100 0   
    83            C5 000000000000 100 100 0   
    84            C6 000000000000 100 100 0   
    85            C7 000000000000 100 100 0"),
    86 
    87       new Drive("OCZ-VERTEX2", 16, 
    88         @" 01 DADAD5000000 100 106 50
    89            05 000000000000 100 100 3 
    90            09 DF0900004A2F 100 100 0 
    91            0C FC0100000000 100 100 0 
    92            AB 000000000000 0   0   0 
    93            AC 000000000000 0   0   0 
    94            AE 1F0000000000 0   0   0 
    95            B1 000000000000 0   0   0 
    96            B5 000000000000 0   0   0 
    97            B6 000000000000 0   0   0 
    98            BB 000000000000 100 100 0 
    99            C2 010081007F00 129 1   0 
   100            C3 DADAD5000000 100 106 0 
   101            C4 000000000000 100 100 0 
   102            E7 000000000000 100 100 10
   103            E9 800400000000 0   0   0 
   104            EA 000600000000 0   0   0 
   105            F1 000600000000 0   0   0 
   106            F2 801200000000 0   0   0"),
   107       
   108       new Drive("WDC WD5000AADS-00S9B0", 10, 
   109         @" 1   000000000000 200 200         
   110            3   820D00000000 149 150         
   111            4   610800000000 98  98          
   112            5   000000000000 200 200         
   113            7   000000000000 253 100         
   114            9   0F1F00000000 90  90          
   115            10  000000000000 100 100         
   116            11  000000000000 100 100         
   117            12  880200000000 100 100         
   118            192 6B0000000000 200 200         
   119            193 E9CB03000000 118 118         
   120            194 280000000000 94  103         
   121            196 000000000000 200 200         
   122            197 000000000000 200 200         
   123            198 000000000000 200 200         
   124            199 000000000000 200 200         
   125            200 000000000000 200 200         
   126            130 7B0300010002 1   41          
   127            5   000000000000 0   0           
   128            1   000000000000 0   0"),
   129 
   130       new Drive("INTEL SSDSA2M080G2GC", 10, 
   131         @" 3   000000000000 100 100         
   132            4   000000000000 100 100         
   133            5   010000000000 100 100         
   134            9   B10B00000000 100 100         
   135            12  DD0300000000 100 100         
   136            192 480000000000 100 100         
   137            225 89DB00000000 200 200         
   138            226 3D1B00000000 100 100         
   139            227 030000000000 100 100         
   140            228 7F85703C0000 100 100         
   141            232 000000000000 99  99          
   142            233 000000000000 98  98          
   143            184 000000000000 100 100         
   144            1   000000000000 0   0"),
   145 
   146       new Drive("OCZ-VERTEX", 10, 
   147         @" 1   000000000000 0   8   
   148            9   000000000000 30  99  
   149            12  000000000000 0   15  
   150            184 000000000000 0   7   
   151            195 000000000000 0   0   
   152            196 000000000000 0   2   
   153            197 000000000000 0   0   
   154            198 B9ED00000000 214 176 
   155            199 352701000000 143 185 
   156            200 B10500000000 105 55  
   157            201 F40A00000000 238 194 
   158            202 020000000000 137 35  
   159            203 020000000000 125 63  
   160            204 000000000000 0   0   
   161            205 000000000000 19  136 
   162            206 000000000000 22  54  
   163            207 010000000000 113 226 
   164            208 000000000000 49  232 
   165            209 000000000000 0   98  
   166            211 000000000000 0   0   
   167            212 000000000000 0   0   
   168            213 000000000000 0   0"),
   169  
   170       new Drive("INTEL SSDSA2CW120G3", 16,
   171         @"03 000000000000 100 100 0
   172           04 000000000000 100 100 0
   173           05 000000000000 100 100 0
   174           09 830200000000 100 100 0
   175           0C 900100000000 100 100 0
   176           AA 000000000000 100 100 0
   177           AB 000000000000 100 100 0
   178           AC 000000000000 100 100 0
   179           B8 000000000000 100 100 0
   180           BB 000000000000 100 100 0
   181           C0 040000000000 100 100 0
   182           E1 FF4300000000 100 100 0
   183           E2 E57D14000000 100 100 0
   184           E3 000000000000 100 100 0
   185           E4 E39600000000 100 100 0
   186           E8 000000000000 100 100 0
   187           E9 000000000000 100 100 0
   188           F1 FF4300000000 100 100 0
   189           F2 264F00000000 100 100 0")
   190       };
   191 
   192     public IntPtr OpenDrive(int driveNumber) {
   193       if (driveNumber < drives.Length)
   194         return (IntPtr)driveNumber;
   195       else
   196         return InvalidHandle;
   197     }
   198 
   199     public bool EnableSmart(IntPtr handle, int driveNumber) {
   200       if (handle != (IntPtr)driveNumber)
   201         throw new ArgumentOutOfRangeException();
   202 
   203       return true;
   204     }
   205 
   206     public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber) {
   207       if (handle != (IntPtr)driveNumber)
   208         throw new ArgumentOutOfRangeException();
   209 
   210       return drives[driveNumber].DriveAttributeValues;
   211     }
   212 
   213     public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle, 
   214       int driveNumber) 
   215     {
   216       if (handle != (IntPtr)driveNumber)
   217         throw new ArgumentOutOfRangeException();
   218 
   219       return drives[driveNumber].DriveThresholdValues;
   220     }
   221 
   222     public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, 
   223       out string name, out string firmwareRevision) {
   224       if (handle != (IntPtr)driveNumber)
   225         throw new ArgumentOutOfRangeException();
   226 
   227       name = drives[driveNumber].Name;
   228       firmwareRevision = "";
   229       return true;
   230     }
   231 
   232     public void CloseHandle(IntPtr handle) { }
   233 
   234 
   235     private class Drive {
   236 
   237       public Drive(string name, int idBase, string value) {
   238         this.Name = name;
   239 
   240         string[] lines = value.Split(new[] { '\r', '\n' }, 
   241           StringSplitOptions.RemoveEmptyEntries);
   242 
   243         DriveAttributeValues = new DriveAttributeValue[lines.Length];
   244         List<DriveThresholdValue> thresholds = new List<DriveThresholdValue>();
   245 
   246         for (int i = 0; i < lines.Length; i++) {
   247 
   248           string[] array = lines[i].Split(new[] { ' ' },
   249             StringSplitOptions.RemoveEmptyEntries);
   250 
   251           if (array.Length != 4 && array.Length != 5)
   252             throw new Exception();
   253 
   254           DriveAttributeValue v = new DriveAttributeValue();
   255           v.Identifier = Convert.ToByte(array[0], idBase);
   256 
   257           v.RawValue = new byte[6];
   258           for (int j = 0; j < 6; j++) {
   259             v.RawValue[j] = Convert.ToByte(array[1].Substring(2 * j, 2), 16);
   260           }
   261 
   262           v.WorstValue = Convert.ToByte(array[2], 10);
   263           v.AttrValue = Convert.ToByte(array[3], 10);
   264 
   265           DriveAttributeValues[i] = v;
   266 
   267           if (array.Length == 5) {
   268             DriveThresholdValue t = new DriveThresholdValue();
   269             t.Identifier = v.Identifier;
   270             t.Threshold = Convert.ToByte(array[4], 10);
   271             thresholds.Add(t);
   272           }
   273         }
   274 
   275         DriveThresholdValues = thresholds.ToArray();
   276       }
   277 
   278       public DriveAttributeValue[] DriveAttributeValues { get; private set; }
   279 
   280       public DriveThresholdValue[] DriveThresholdValues { get; private set; }
   281 
   282       public string Name { get; private set; }
   283     }
   284 
   285     public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
   286   }
   287 
   288 #endif
   289 
   290 }