Hardware/HDD/DebugSmart.cs
author moel.mich
Mon, 02 Jan 2012 21:17:21 +0000
changeset 330 b2c6d350396d
parent 328 f837f9f0973e
child 338 f580591971ce
permissions -rw-r--r--
Further restricted the identification for Indilinx SSDs to prevent Maxtor HDDs to be identified as Indilinx SSD.
     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 
   247     public IntPtr OpenDrive(int driveNumber) {
   248       if (driveNumber < drives.Length)
   249         return (IntPtr)driveNumber;
   250       else
   251         return InvalidHandle;
   252     }
   253 
   254     public bool EnableSmart(IntPtr handle, int driveNumber) {
   255       if (handle != (IntPtr)driveNumber)
   256         throw new ArgumentOutOfRangeException();
   257 
   258       return true;
   259     }
   260 
   261     public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber) {
   262       if (handle != (IntPtr)driveNumber)
   263         throw new ArgumentOutOfRangeException();
   264 
   265       return drives[driveNumber].DriveAttributeValues;
   266     }
   267 
   268     public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle, 
   269       int driveNumber) 
   270     {
   271       if (handle != (IntPtr)driveNumber)
   272         throw new ArgumentOutOfRangeException();
   273 
   274       return drives[driveNumber].DriveThresholdValues;
   275     }
   276 
   277     public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, 
   278       out string name, out string firmwareRevision) {
   279       if (handle != (IntPtr)driveNumber)
   280         throw new ArgumentOutOfRangeException();
   281 
   282       name = drives[driveNumber].Name;
   283       firmwareRevision = drives[driveNumber].FirmwareVersion;
   284       return true;
   285     }
   286 
   287     public void CloseHandle(IntPtr handle) { }
   288 
   289 
   290     private class Drive {
   291 
   292       public Drive(string name, string firmware, int idBase, string value) {
   293         this.Name = name;
   294         this.FirmwareVersion = firmware;
   295 
   296         string[] lines = value.Split(new[] { '\r', '\n' }, 
   297           StringSplitOptions.RemoveEmptyEntries);
   298 
   299         DriveAttributeValues = new DriveAttributeValue[lines.Length];
   300         List<DriveThresholdValue> thresholds = new List<DriveThresholdValue>();
   301 
   302         for (int i = 0; i < lines.Length; i++) {
   303 
   304           string[] array = lines[i].Split(new[] { ' ' },
   305             StringSplitOptions.RemoveEmptyEntries);
   306 
   307           if (array.Length != 4 && array.Length != 5)
   308             throw new Exception();
   309 
   310           DriveAttributeValue v = new DriveAttributeValue();
   311           v.Identifier = Convert.ToByte(array[0], idBase);
   312 
   313           v.RawValue = new byte[6];
   314           for (int j = 0; j < 6; j++) {
   315             v.RawValue[j] = Convert.ToByte(array[1].Substring(2 * j, 2), 16);
   316           }
   317 
   318           v.WorstValue = Convert.ToByte(array[2], 10);
   319           v.AttrValue = Convert.ToByte(array[3], 10);
   320 
   321           DriveAttributeValues[i] = v;
   322 
   323           if (array.Length == 5) {
   324             DriveThresholdValue t = new DriveThresholdValue();
   325             t.Identifier = v.Identifier;
   326             t.Threshold = Convert.ToByte(array[4], 10);
   327             thresholds.Add(t);
   328           }
   329         }
   330 
   331         DriveThresholdValues = thresholds.ToArray();
   332       }
   333 
   334       public DriveAttributeValue[] DriveAttributeValues { get; private set; }
   335 
   336       public DriveThresholdValue[] DriveThresholdValues { get; private set; }
   337 
   338       public string Name { get; private set; }
   339 
   340       public string FirmwareVersion { get; private set; }
   341     }
   342 
   343     public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
   344   }
   345 
   346 #endif
   347 
   348 }