Hardware/HDD/DebugSmart.cs
author moel.mich
Mon, 02 Jan 2012 18:44:19 +0000
changeset 328 f837f9f0973e
parent 325 4c31341a4800
child 330 b2c6d350396d
permissions -rw-r--r--
Added SMART support for Samsung SSDs.
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@328
   208
         E9 630594120000 92  92  0")
moel@324
   209
      };
moel@324
   210
moel@324
   211
    public IntPtr OpenDrive(int driveNumber) {
moel@324
   212
      if (driveNumber < drives.Length)
moel@324
   213
        return (IntPtr)driveNumber;
moel@324
   214
      else
moel@324
   215
        return InvalidHandle;
moel@324
   216
    }
moel@324
   217
moel@324
   218
    public bool EnableSmart(IntPtr handle, int driveNumber) {
moel@324
   219
      if (handle != (IntPtr)driveNumber)
moel@324
   220
        throw new ArgumentOutOfRangeException();
moel@324
   221
moel@324
   222
      return true;
moel@324
   223
    }
moel@324
   224
moel@324
   225
    public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber) {
moel@324
   226
      if (handle != (IntPtr)driveNumber)
moel@324
   227
        throw new ArgumentOutOfRangeException();
moel@324
   228
moel@324
   229
      return drives[driveNumber].DriveAttributeValues;
moel@324
   230
    }
moel@324
   231
moel@324
   232
    public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle, 
moel@324
   233
      int driveNumber) 
moel@324
   234
    {
moel@324
   235
      if (handle != (IntPtr)driveNumber)
moel@324
   236
        throw new ArgumentOutOfRangeException();
moel@324
   237
moel@324
   238
      return drives[driveNumber].DriveThresholdValues;
moel@324
   239
    }
moel@324
   240
moel@325
   241
    public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, 
moel@325
   242
      out string name, out string firmwareRevision) {
moel@324
   243
      if (handle != (IntPtr)driveNumber)
moel@324
   244
        throw new ArgumentOutOfRangeException();
moel@324
   245
moel@325
   246
      name = drives[driveNumber].Name;
moel@328
   247
      firmwareRevision = drives[driveNumber].FirmwareVersion;
moel@325
   248
      return true;
moel@324
   249
    }
moel@324
   250
moel@324
   251
    public void CloseHandle(IntPtr handle) { }
moel@324
   252
moel@324
   253
moel@324
   254
    private class Drive {
moel@324
   255
moel@328
   256
      public Drive(string name, string firmware, int idBase, string value) {
moel@324
   257
        this.Name = name;
moel@328
   258
        this.FirmwareVersion = firmware;
moel@324
   259
moel@324
   260
        string[] lines = value.Split(new[] { '\r', '\n' }, 
moel@324
   261
          StringSplitOptions.RemoveEmptyEntries);
moel@324
   262
moel@324
   263
        DriveAttributeValues = new DriveAttributeValue[lines.Length];
moel@324
   264
        List<DriveThresholdValue> thresholds = new List<DriveThresholdValue>();
moel@324
   265
moel@324
   266
        for (int i = 0; i < lines.Length; i++) {
moel@324
   267
moel@324
   268
          string[] array = lines[i].Split(new[] { ' ' },
moel@324
   269
            StringSplitOptions.RemoveEmptyEntries);
moel@324
   270
moel@324
   271
          if (array.Length != 4 && array.Length != 5)
moel@324
   272
            throw new Exception();
moel@324
   273
moel@324
   274
          DriveAttributeValue v = new DriveAttributeValue();
moel@324
   275
          v.Identifier = Convert.ToByte(array[0], idBase);
moel@324
   276
moel@324
   277
          v.RawValue = new byte[6];
moel@324
   278
          for (int j = 0; j < 6; j++) {
moel@324
   279
            v.RawValue[j] = Convert.ToByte(array[1].Substring(2 * j, 2), 16);
moel@324
   280
          }
moel@324
   281
moel@324
   282
          v.WorstValue = Convert.ToByte(array[2], 10);
moel@324
   283
          v.AttrValue = Convert.ToByte(array[3], 10);
moel@324
   284
moel@324
   285
          DriveAttributeValues[i] = v;
moel@324
   286
moel@324
   287
          if (array.Length == 5) {
moel@324
   288
            DriveThresholdValue t = new DriveThresholdValue();
moel@324
   289
            t.Identifier = v.Identifier;
moel@324
   290
            t.Threshold = Convert.ToByte(array[4], 10);
moel@324
   291
            thresholds.Add(t);
moel@324
   292
          }
moel@324
   293
        }
moel@324
   294
moel@324
   295
        DriveThresholdValues = thresholds.ToArray();
moel@324
   296
      }
moel@324
   297
moel@324
   298
      public DriveAttributeValue[] DriveAttributeValues { get; private set; }
moel@324
   299
moel@324
   300
      public DriveThresholdValue[] DriveThresholdValues { get; private set; }
moel@324
   301
moel@324
   302
      public string Name { get; private set; }
moel@328
   303
moel@328
   304
      public string FirmwareVersion { get; private set; }
moel@324
   305
    }
moel@324
   306
moel@324
   307
    public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
moel@324
   308
  }
moel@324
   309
moel@324
   310
#endif
moel@324
   311
moel@324
   312
}