Hardware/HDD/DebugSmart.cs
author moel.mich
Tue, 14 Feb 2012 23:07:55 +0000
changeset 340 600962f8a298
parent 330 b2c6d350396d
child 344 3145aadca3d2
permissions -rw-r--r--
Added a new sensor type "Factor" for dimensionless values (and similar) that are not to be shown as percent ("Level" type). Changed the write amplification sensor to use the new "Factor" sensor type. Added the temperature SMART attribute for Sandforce SSDs as hidden sensor (as it may show fake results on some hardware).
     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", null, 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", "1.03", 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", "1.25", 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", null, 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", null, 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", null, 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", null, 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      new Drive("CORSAIR CMFSSD-128GBG2D", "VBM19C1Q", 16, 
   192        @"09 100900000000 99  99  0 
   193          0C 560200000000 99  99  0 
   194          AF 000000000000 100 100 10
   195          B0 000000000000 100 100 10
   196          B1 2A0000000000 99  99  17
   197          B2 180000000000 60  60  10
   198          B3 4B0000000000 98  98  10
   199          B4 B50E00000000 98  98  10
   200          B5 000000000000 100 100 10
   201          B6 000000000000 100 100 10
   202          B7 000000000000 100 100 10
   203          BB 000000000000 100 100 0 
   204          C3 000000000000 200 200 0 
   205          C6 000000000000 100 100 0 
   206          C7 810100000000 253 253 0 
   207          E8 240000000000 60  60  10
   208          E9 630594120000 92  92  0"),
   209 
   210       new Drive("Maxtor 6L300R0", null, 10,    
   211         @"3   9E5500000000 183 193         
   212           4   0A0D00000000 252 252         
   213           5   010000000000 253 253         
   214           6   000000000000 253 253         
   215           7   000000000000 252 253         
   216           8   DFA700000000 224 245         
   217           9   CE5700000000 155 155         
   218           10  000000000000 252 253         
   219           11  000000000000 252 253         
   220           12  BA0400000000 250 250         
   221           192 000000000000 253 253         
   222           193 000000000000 253 253         
   223           194 3D0000000000 253 42          
   224           195 5D1F00000000 252 253         
   225           196 000000000000 253 253         
   226           197 010000000000 253 253         
   227           198 000000000000 253 253         
   228           199 030000000000 196 199         
   229           200 000000000000 252 253         
   230           201 000000000000 252 253         
   231           202 000000000000 252 253         
   232           203 000000000000 252 253         
   233           204 000000000000 252 253         
   234           205 000000000000 252 253         
   235           207 000000000000 252 253         
   236           208 000000000000 252 253         
   237           209 EA0000000000 234 234         
   238           210 000000000000 252 253         
   239           211 000000000000 252 253         
   240           212 000000000000 252 253         
   241           130 5B0300010002 1   9           
   242           59  FC3203030100 205 0           
   243           1   000000000000 0   0           
   244           144 000000000000 0   34 "),
   245 
   246         new Drive("M4-CT256M4SSD2", "0309", 16, 
   247           @"01 000000000000 100 100 50     
   248             05 000000000000 100 100 10     
   249             09 AB0100000000 100 100 1      
   250             0C 6E0000000000 100 100 1      
   251             AA 000000000000 100 100 10     
   252             AB 000000000000 100 100 1      
   253             AC 000000000000 100 100 1      
   254             AD 060000000000 100 100 10     
   255             AE 000000000000 100 100 1      
   256             B5 79003D00B700 100 100 1      
   257             B7 000000000000 100 100 1      
   258             B8 000000000000 100 100 50     
   259             BB 000000000000 100 100 1      
   260             BC 000000000000 100 100 1      
   261             BD 5B0000000000 100 100 1      
   262             C2 000000000000 100 100 0      
   263             C3 000000000000 100 100 1      
   264             C4 000000000000 100 100 1      
   265             C5 000000000000 100 100 1      
   266             C6 000000000000 100 100 1      
   267             C7 000000000000 100 100 1      
   268             CA 000000000000 100 100 1      
   269             CE 000000000000 100 100 1 "),
   270 
   271         new Drive("C300-CTFDDAC256MAG", "0007", 16, 
   272           @"01 000000000000 100 100 0  
   273             05 000000000000 100 100 0  
   274             09 4C0A00000000 100 100 0  
   275             0C 0F0100000000 100 100 0  
   276             AA 000000000000 100 100 0  
   277             AB 000000000000 100 100 0  
   278             AC 000000000000 100 100 0  
   279             AD 1B0000000000 100 100 0  
   280             AE 000000000000 100 100 0  
   281             B5 D30357012B05 100 100 0  
   282             B7 000000000000 100 100 0  
   283             B8 000000000000 100 100 0  
   284             BB 000000000000 100 100 0  
   285             BC 000000000000 100 100 0  
   286             BD C60100000000 100 100 0  
   287             C3 000000000000 100 100 0  
   288             C4 000000000000 100 100 0  
   289             C5 000000000000 100 100 0  
   290             C6 000000000000 100 100 0  
   291             C7 000000000000 100 100 0  
   292             CA 000000000000 100 100 0  
   293             CE 000000000000 100 100 0")
   294       };
   295 
   296     public IntPtr OpenDrive(int driveNumber) {
   297       if (driveNumber < drives.Length)
   298         return (IntPtr)driveNumber;
   299       else
   300         return InvalidHandle;
   301     }
   302 
   303     public bool EnableSmart(IntPtr handle, int driveNumber) {
   304       if (handle != (IntPtr)driveNumber)
   305         throw new ArgumentOutOfRangeException();
   306 
   307       return true;
   308     }
   309 
   310     public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber) {
   311       if (handle != (IntPtr)driveNumber)
   312         throw new ArgumentOutOfRangeException();
   313 
   314       return drives[driveNumber].DriveAttributeValues;
   315     }
   316 
   317     public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle, 
   318       int driveNumber) 
   319     {
   320       if (handle != (IntPtr)driveNumber)
   321         throw new ArgumentOutOfRangeException();
   322 
   323       return drives[driveNumber].DriveThresholdValues;
   324     }
   325 
   326     public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, 
   327       out string name, out string firmwareRevision) {
   328       if (handle != (IntPtr)driveNumber)
   329         throw new ArgumentOutOfRangeException();
   330 
   331       name = drives[driveNumber].Name;
   332       firmwareRevision = drives[driveNumber].FirmwareVersion;
   333       return true;
   334     }
   335 
   336     public void CloseHandle(IntPtr handle) { }
   337 
   338 
   339     private class Drive {
   340 
   341       public Drive(string name, string firmware, int idBase, string value) {
   342         this.Name = name;
   343         this.FirmwareVersion = firmware;
   344 
   345         string[] lines = value.Split(new[] { '\r', '\n' }, 
   346           StringSplitOptions.RemoveEmptyEntries);
   347 
   348         DriveAttributeValues = new DriveAttributeValue[lines.Length];
   349         List<DriveThresholdValue> thresholds = new List<DriveThresholdValue>();
   350 
   351         for (int i = 0; i < lines.Length; i++) {
   352 
   353           string[] array = lines[i].Split(new[] { ' ' },
   354             StringSplitOptions.RemoveEmptyEntries);
   355 
   356           if (array.Length != 4 && array.Length != 5)
   357             throw new Exception();
   358 
   359           DriveAttributeValue v = new DriveAttributeValue();
   360           v.Identifier = Convert.ToByte(array[0], idBase);
   361 
   362           v.RawValue = new byte[6];
   363           for (int j = 0; j < 6; j++) {
   364             v.RawValue[j] = Convert.ToByte(array[1].Substring(2 * j, 2), 16);
   365           }
   366 
   367           v.WorstValue = Convert.ToByte(array[2], 10);
   368           v.AttrValue = Convert.ToByte(array[3], 10);
   369 
   370           DriveAttributeValues[i] = v;
   371 
   372           if (array.Length == 5) {
   373             DriveThresholdValue t = new DriveThresholdValue();
   374             t.Identifier = v.Identifier;
   375             t.Threshold = Convert.ToByte(array[4], 10);
   376             thresholds.Add(t);
   377           }
   378         }
   379 
   380         DriveThresholdValues = thresholds.ToArray();
   381       }
   382 
   383       public DriveAttributeValue[] DriveAttributeValues { get; private set; }
   384 
   385       public DriveThresholdValue[] DriveThresholdValues { get; private set; }
   386 
   387       public string Name { get; private set; }
   388 
   389       public string FirmwareVersion { get; private set; }
   390     }
   391 
   392     public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
   393   }
   394 
   395 #endif
   396 
   397 }