Hardware/HDD/DebugSmart.cs
author moel.mich
Thu, 26 Jul 2012 06:50:56 +0000
changeset 376 df64b56ece65
parent 358 7962499f9cd6
child 406 3890d78140c2
permissions -rw-r--r--
Fixed an error where loading config files from previous versions would crash the application.
     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-2012 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     public IntPtr OpenDrive(int driveNumber) {
   319       if (driveNumber < drives.Length)
   320         return (IntPtr)driveNumber;
   321       else
   322         return InvalidHandle;
   323     }
   324 
   325     public bool EnableSmart(IntPtr handle, int driveNumber) {
   326       if (handle != (IntPtr)driveNumber)
   327         throw new ArgumentOutOfRangeException();
   328 
   329       return true;
   330     }
   331 
   332     public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber) {
   333       if (handle != (IntPtr)driveNumber)
   334         throw new ArgumentOutOfRangeException();
   335 
   336       return drives[driveNumber].DriveAttributeValues;
   337     }
   338 
   339     public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle, 
   340       int driveNumber) 
   341     {
   342       if (handle != (IntPtr)driveNumber)
   343         throw new ArgumentOutOfRangeException();
   344 
   345       return drives[driveNumber].DriveThresholdValues;
   346     }
   347 
   348     public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, 
   349       out string name, out string firmwareRevision) {
   350       if (handle != (IntPtr)driveNumber)
   351         throw new ArgumentOutOfRangeException();
   352 
   353       name = drives[driveNumber].Name;
   354       firmwareRevision = drives[driveNumber].FirmwareVersion;
   355       return true;
   356     }
   357 
   358     public void CloseHandle(IntPtr handle) { }
   359 
   360 
   361     private class Drive {
   362 
   363       public Drive(string name, string firmware, int idBase, string value) {
   364         this.Name = name;
   365         this.FirmwareVersion = firmware;
   366 
   367         string[] lines = value.Split(new[] { '\r', '\n' }, 
   368           StringSplitOptions.RemoveEmptyEntries);
   369 
   370         DriveAttributeValues = new DriveAttributeValue[lines.Length];
   371         List<DriveThresholdValue> thresholds = new List<DriveThresholdValue>();
   372 
   373         for (int i = 0; i < lines.Length; i++) {
   374 
   375           string[] array = lines[i].Split(new[] { ' ' },
   376             StringSplitOptions.RemoveEmptyEntries);
   377 
   378           if (array.Length != 4 && array.Length != 5)
   379             throw new Exception();
   380 
   381           DriveAttributeValue v = new DriveAttributeValue();
   382           v.Identifier = Convert.ToByte(array[0], idBase);
   383 
   384           v.RawValue = new byte[6];
   385           for (int j = 0; j < 6; j++) {
   386             v.RawValue[j] = Convert.ToByte(array[1].Substring(2 * j, 2), 16);
   387           }
   388 
   389           v.WorstValue = Convert.ToByte(array[2], 10);
   390           v.AttrValue = Convert.ToByte(array[3], 10);
   391 
   392           DriveAttributeValues[i] = v;
   393 
   394           if (array.Length == 5) {
   395             DriveThresholdValue t = new DriveThresholdValue();
   396             t.Identifier = v.Identifier;
   397             t.Threshold = Convert.ToByte(array[4], 10);
   398             thresholds.Add(t);
   399           }
   400         }
   401 
   402         DriveThresholdValues = thresholds.ToArray();
   403       }
   404 
   405       public DriveAttributeValue[] DriveAttributeValues { get; private set; }
   406 
   407       public DriveThresholdValue[] DriveThresholdValues { get; private set; }
   408 
   409       public string Name { get; private set; }
   410 
   411       public string FirmwareVersion { get; private set; }
   412     }
   413 
   414     public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
   415 
   416     public string[] GetLogicalDrives(int driveIndex) {
   417       return new string[0];
   418     }
   419   }
   420 
   421 #endif
   422 
   423 }