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