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