Hardware/HDD/DebugSmart.cs
author moel.mich
Tue, 25 Jun 2013 20:34:29 +0000
changeset 406 3890d78140c2
parent 369 5077ed7ddca8
permissions -rw-r--r--
Added support for new Samsung SSDs (like Samsung SSD 840 PRO).
     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) 2011-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using System;
    12 using System.Collections.Generic;
    13 using System.Text;
    14 
    15 namespace OpenHardwareMonitor.Hardware.HDD {
    16 
    17 #if DEBUG
    18 
    19   internal class DebugSmart : ISmart {
    20 
    21     private Drive[] drives = {
    22       new Drive("KINGSTON SNV425S264GB", null, 16,
    23         @" 01 000000000000 100 100      
    24            02 000000000000 100 100      
    25            03 000000000000 100 100      
    26            05 000000000000 100 100      
    27            07 000000000000 100 100      
    28            08 000000000000 100 100      
    29            09 821E00000000 100 100      
    30            0A 000000000000 100 100      
    31            0C 950200000000 100 100      
    32            A8 000000000000 100 100      
    33            AF 000000000000 100 100      
    34            C0 000000000000 100 100      
    35            C2 290014002B00 100 41       
    36            C5 000000000000 100 100      
    37            F0 000000000000 100 100      
    38            AA 07007B000000 100 100      
    39            AD 0E1E71304919 100 100"),
    40 
    41       new Drive("PLEXTOR  PX-128M2S", "1.03", 16, 
    42         @" 01 000000000000 100 100 0   
    43            03 000000000000 100 100 0   
    44            04 000000000000 100 100 0   
    45            05 000000000000 100 100 0   
    46            09 250100000000 100 100 0   
    47            0A 000000000000 100 100 0   
    48            0C D10000000000 100 100 0   
    49            B2 000000000000 100 100 0   
    50            BB 000000000000 100 100 0   
    51            BE 000000000000 100 100 0   
    52            C0 000000000000 100 100 0   
    53            C1 000000000000 100 100 0   
    54            C2 000000000000 100 100 0   
    55            C3 000000000000 100 100 0   
    56            C5 000000000000 100 100 0   
    57            C6 000000000000 100 100 0   
    58            C7 000000000000 100 100 0"),
    59 
    60       new Drive("OCZ-VERTEX2", "1.25", 16, 
    61         @" 01 DADAD5000000 100 106 50
    62            05 000000000000 100 100 3 
    63            09 DF0900004A2F 100 100 0 
    64            0C FC0100000000 100 100 0 
    65            AB 000000000000 0   0   0 
    66            AC 000000000000 0   0   0 
    67            AE 1F0000000000 0   0   0 
    68            B1 000000000000 0   0   0 
    69            B5 000000000000 0   0   0 
    70            B6 000000000000 0   0   0 
    71            BB 000000000000 100 100 0 
    72            C2 010081007F00 129 1   0 
    73            C3 DADAD5000000 100 106 0 
    74            C4 000000000000 100 100 0 
    75            E7 000000000000 100 100 10
    76            E9 800400000000 0   0   0 
    77            EA 000600000000 0   0   0 
    78            F1 000600000000 0   0   0 
    79            F2 801200000000 0   0   0"),
    80       
    81       new Drive("WDC WD5000AADS-00S9B0", null, 10, 
    82         @" 1   000000000000 200 200         
    83            3   820D00000000 149 150         
    84            4   610800000000 98  98          
    85            5   000000000000 200 200         
    86            7   000000000000 253 100         
    87            9   0F1F00000000 90  90          
    88            10  000000000000 100 100         
    89            11  000000000000 100 100         
    90            12  880200000000 100 100         
    91            192 6B0000000000 200 200         
    92            193 E9CB03000000 118 118         
    93            194 280000000000 94  103         
    94            196 000000000000 200 200         
    95            197 000000000000 200 200         
    96            198 000000000000 200 200         
    97            199 000000000000 200 200         
    98            200 000000000000 200 200         
    99            130 7B0300010002 1   41          
   100            5   000000000000 0   0           
   101            1   000000000000 0   0"),
   102 
   103       new Drive("INTEL SSDSA2M080G2GC", null, 10, 
   104         @" 3   000000000000 100 100         
   105            4   000000000000 100 100         
   106            5   010000000000 100 100         
   107            9   B10B00000000 100 100         
   108            12  DD0300000000 100 100         
   109            192 480000000000 100 100         
   110            225 89DB00000000 200 200         
   111            226 3D1B00000000 100 100         
   112            227 030000000000 100 100         
   113            228 7F85703C0000 100 100         
   114            232 000000000000 99  99          
   115            233 000000000000 98  98          
   116            184 000000000000 100 100         
   117            1   000000000000 0   0"),
   118 
   119       new Drive("OCZ-VERTEX", null, 10, 
   120         @" 1   000000000000 0   8   
   121            9   000000000000 30  99  
   122            12  000000000000 0   15  
   123            184 000000000000 0   7   
   124            195 000000000000 0   0   
   125            196 000000000000 0   2   
   126            197 000000000000 0   0   
   127            198 B9ED00000000 214 176 
   128            199 352701000000 143 185 
   129            200 B10500000000 105 55  
   130            201 F40A00000000 238 194 
   131            202 020000000000 137 35  
   132            203 020000000000 125 63  
   133            204 000000000000 0   0   
   134            205 000000000000 19  136 
   135            206 000000000000 22  54  
   136            207 010000000000 113 226 
   137            208 000000000000 49  232 
   138            209 000000000000 0   98  
   139            211 000000000000 0   0   
   140            212 000000000000 0   0   
   141            213 000000000000 0   0"),
   142  
   143       new Drive("INTEL SSDSA2CW120G3", null, 16,
   144         @"03 000000000000 100 100 0
   145           04 000000000000 100 100 0
   146           05 000000000000 100 100 0
   147           09 830200000000 100 100 0
   148           0C 900100000000 100 100 0
   149           AA 000000000000 100 100 0
   150           AB 000000000000 100 100 0
   151           AC 000000000000 100 100 0
   152           B8 000000000000 100 100 0
   153           BB 000000000000 100 100 0
   154           C0 040000000000 100 100 0
   155           E1 FF4300000000 100 100 0
   156           E2 E57D14000000 100 100 0
   157           E3 000000000000 100 100 0
   158           E4 E39600000000 100 100 0
   159           E8 000000000000 100 100 0
   160           E9 000000000000 100 100 0
   161           F1 FF4300000000 100 100 0
   162           F2 264F00000000 100 100 0"),
   163 
   164      new Drive("CORSAIR CMFSSD-128GBG2D", "VBM19C1Q", 16, 
   165        @"09 100900000000 99  99  0 
   166          0C 560200000000 99  99  0 
   167          AF 000000000000 100 100 10
   168          B0 000000000000 100 100 10
   169          B1 2A0000000000 99  99  17
   170          B2 180000000000 60  60  10
   171          B3 4B0000000000 98  98  10
   172          B4 B50E00000000 98  98  10
   173          B5 000000000000 100 100 10
   174          B6 000000000000 100 100 10
   175          B7 000000000000 100 100 10
   176          BB 000000000000 100 100 0 
   177          C3 000000000000 200 200 0 
   178          C6 000000000000 100 100 0 
   179          C7 810100000000 253 253 0 
   180          E8 240000000000 60  60  10
   181          E9 630594120000 92  92  0"),
   182 
   183       new Drive("Maxtor 6L300R0", null, 10,    
   184         @"3   9E5500000000 183 193         
   185           4   0A0D00000000 252 252         
   186           5   010000000000 253 253         
   187           6   000000000000 253 253         
   188           7   000000000000 252 253         
   189           8   DFA700000000 224 245         
   190           9   CE5700000000 155 155         
   191           10  000000000000 252 253         
   192           11  000000000000 252 253         
   193           12  BA0400000000 250 250         
   194           192 000000000000 253 253         
   195           193 000000000000 253 253         
   196           194 3D0000000000 253 42          
   197           195 5D1F00000000 252 253         
   198           196 000000000000 253 253         
   199           197 010000000000 253 253         
   200           198 000000000000 253 253         
   201           199 030000000000 196 199         
   202           200 000000000000 252 253         
   203           201 000000000000 252 253         
   204           202 000000000000 252 253         
   205           203 000000000000 252 253         
   206           204 000000000000 252 253         
   207           205 000000000000 252 253         
   208           207 000000000000 252 253         
   209           208 000000000000 252 253         
   210           209 EA0000000000 234 234         
   211           210 000000000000 252 253         
   212           211 000000000000 252 253         
   213           212 000000000000 252 253         
   214           130 5B0300010002 1   9           
   215           59  FC3203030100 205 0           
   216           1   000000000000 0   0           
   217           144 000000000000 0   34 "),
   218 
   219         new Drive("M4-CT256M4SSD2", "0309", 16, 
   220           @"01 000000000000 100 100 50     
   221             05 000000000000 100 100 10     
   222             09 AB0100000000 100 100 1      
   223             0C 6E0000000000 100 100 1      
   224             AA 000000000000 100 100 10     
   225             AB 000000000000 100 100 1      
   226             AC 000000000000 100 100 1      
   227             AD 060000000000 100 100 10     
   228             AE 000000000000 100 100 1      
   229             B5 79003D00B700 100 100 1      
   230             B7 000000000000 100 100 1      
   231             B8 000000000000 100 100 50     
   232             BB 000000000000 100 100 1      
   233             BC 000000000000 100 100 1      
   234             BD 5B0000000000 100 100 1      
   235             C2 000000000000 100 100 0      
   236             C3 000000000000 100 100 1      
   237             C4 000000000000 100 100 1      
   238             C5 000000000000 100 100 1      
   239             C6 000000000000 100 100 1      
   240             C7 000000000000 100 100 1      
   241             CA 000000000000 100 100 1      
   242             CE 000000000000 100 100 1 "),
   243 
   244         new Drive("C300-CTFDDAC256MAG", "0007", 16, 
   245           @"01 000000000000 100 100 0  
   246             05 000000000000 100 100 0  
   247             09 4C0A00000000 100 100 0  
   248             0C 0F0100000000 100 100 0  
   249             AA 000000000000 100 100 0  
   250             AB 000000000000 100 100 0  
   251             AC 000000000000 100 100 0  
   252             AD 1B0000000000 100 100 0  
   253             AE 000000000000 100 100 0  
   254             B5 D30357012B05 100 100 0  
   255             B7 000000000000 100 100 0  
   256             B8 000000000000 100 100 0  
   257             BB 000000000000 100 100 0  
   258             BC 000000000000 100 100 0  
   259             BD C60100000000 100 100 0  
   260             C3 000000000000 100 100 0  
   261             C4 000000000000 100 100 0  
   262             C5 000000000000 100 100 0  
   263             C6 000000000000 100 100 0  
   264             C7 000000000000 100 100 0  
   265             CA 000000000000 100 100 0  
   266             CE 000000000000 100 100 0"),
   267 
   268         new Drive("M4-CT064M4SSD2", "0009", 16, 
   269           @"01 000000000000 100 100 50
   270             05 000000000000 100 100 10
   271             09 260000000000 100 100 1 
   272             0C 5A0000000000 100 100 1 
   273             AA 000000000000 100 100 10
   274             AB 000000000000 100 100 1 
   275             AC 000000000000 100 100 1 
   276             AD 010000000000 100 100 10
   277             AE 000000000000 100 100 1 
   278             B5 2B000E003A00 100 100 1 
   279             B7 000000000000 100 100 1 
   280             B8 000000000000 100 100 50
   281             BB 000000000000 100 100 1 
   282             BC 000000000000 100 100 1 
   283             BD 310000000000 100 100 1 
   284             C2 000000000000 100 100 0 
   285             C3 000000000000 100 100 1 
   286             C4 000000000000 100 100 1 
   287             C5 000000000000 100 100 1 
   288             C6 000000000000 100 100 1 
   289             C7 000000000000 100 100 1 
   290             CA 000000000000 100 100 1 
   291             CE 000000000000 100 100 1"),
   292 
   293         new Drive("M4-CT128M4SSD2", "000F", 16, 
   294           @"01 000000000000 100 100 50 
   295             05 000000000000 100 100 10 
   296             09 CA1400000000 100 100 1  
   297             0C A30200000000 100 100 1  
   298             AA 000000000000 100 100 10 
   299             AB 000000000000 100 100 1  
   300             AC 000000000000 100 100 1  
   301             AD 1F0000000000 99  99  10 
   302             AE 140000000000 100 100 1  
   303             B5 12037C028E05 100 100 1  
   304             B7 000000000000 100 100 1  
   305             B8 000000000000 100 100 50 
   306             BB 000000000000 100 100 1  
   307             BC 000000000000 100 100 1  
   308             BD 510000000000 100 100 1  
   309             C2 000000000000 100 100 0  
   310             C3 000000000000 100 100 1  
   311             C4 000000000000 100 100 1  
   312             C5 000000000000 100 100 1  
   313             C6 000000000000 100 100 1  
   314             C7 000000000000 100 100 1  
   315             CA 010000000000 99  99  1  
   316             CE 000000000000 100 100 1 "),
   317 
   318         new Drive("Samsung SSD 840 PRO Series", "DXM05B0Q", 16,
   319           @"05 000000000000 100 100 10 
   320             09 260000000000 99  99  0  
   321             0C 170000000000 99  99  0  
   322             B1 010000000000 99  99  0  
   323             B3 000000000000 100 100 10 
   324             B5 000000000000 100 100 10 
   325             B6 000000000000 100 100 10 
   326             B7 000000000000 100 100 10 
   327             BB 000000000000 100 100 0  
   328             BE 190000000000 60  75  0  
   329             C3 000000000000 200 200 0  
   330             C7 000000000000 100 100 0  
   331             EB 030000000000 99  99  0  
   332             F1 8FF425100000 99  99  0")};
   333 
   334     public IntPtr OpenDrive(int driveNumber) {
   335       if (driveNumber < drives.Length)
   336         return (IntPtr)driveNumber;
   337       else
   338         return InvalidHandle;
   339     }
   340 
   341     public bool EnableSmart(IntPtr handle, int driveNumber) {
   342       if (handle != (IntPtr)driveNumber)
   343         throw new ArgumentOutOfRangeException();
   344 
   345       return true;
   346     }
   347 
   348     public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber) {
   349       if (handle != (IntPtr)driveNumber)
   350         throw new ArgumentOutOfRangeException();
   351 
   352       return drives[driveNumber].DriveAttributeValues;
   353     }
   354 
   355     public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle, 
   356       int driveNumber) 
   357     {
   358       if (handle != (IntPtr)driveNumber)
   359         throw new ArgumentOutOfRangeException();
   360 
   361       return drives[driveNumber].DriveThresholdValues;
   362     }
   363 
   364     public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, 
   365       out string name, out string firmwareRevision) {
   366       if (handle != (IntPtr)driveNumber)
   367         throw new ArgumentOutOfRangeException();
   368 
   369       name = drives[driveNumber].Name;
   370       firmwareRevision = drives[driveNumber].FirmwareVersion;
   371       return true;
   372     }
   373 
   374     public void CloseHandle(IntPtr handle) { }
   375 
   376 
   377     private class Drive {
   378 
   379       public Drive(string name, string firmware, int idBase, string value) {
   380         this.Name = name;
   381         this.FirmwareVersion = firmware;
   382 
   383         string[] lines = value.Split(new[] { '\r', '\n' }, 
   384           StringSplitOptions.RemoveEmptyEntries);
   385 
   386         DriveAttributeValues = new DriveAttributeValue[lines.Length];
   387         List<DriveThresholdValue> thresholds = new List<DriveThresholdValue>();
   388 
   389         for (int i = 0; i < lines.Length; i++) {
   390 
   391           string[] array = lines[i].Split(new[] { ' ' },
   392             StringSplitOptions.RemoveEmptyEntries);
   393 
   394           if (array.Length != 4 && array.Length != 5)
   395             throw new Exception();
   396 
   397           DriveAttributeValue v = new DriveAttributeValue();
   398           v.Identifier = Convert.ToByte(array[0], idBase);
   399 
   400           v.RawValue = new byte[6];
   401           for (int j = 0; j < 6; j++) {
   402             v.RawValue[j] = Convert.ToByte(array[1].Substring(2 * j, 2), 16);
   403           }
   404 
   405           v.WorstValue = Convert.ToByte(array[2], 10);
   406           v.AttrValue = Convert.ToByte(array[3], 10);
   407 
   408           DriveAttributeValues[i] = v;
   409 
   410           if (array.Length == 5) {
   411             DriveThresholdValue t = new DriveThresholdValue();
   412             t.Identifier = v.Identifier;
   413             t.Threshold = Convert.ToByte(array[4], 10);
   414             thresholds.Add(t);
   415           }
   416         }
   417 
   418         DriveThresholdValues = thresholds.ToArray();
   419       }
   420 
   421       public DriveAttributeValue[] DriveAttributeValues { get; private set; }
   422 
   423       public DriveThresholdValue[] DriveThresholdValues { get; private set; }
   424 
   425       public string Name { get; private set; }
   426 
   427       public string FirmwareVersion { get; private set; }
   428     }
   429 
   430     public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
   431 
   432     public string[] GetLogicalDrives(int driveIndex) {
   433       return new string[0];
   434     }
   435   }
   436 
   437 #endif
   438 
   439 }