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@324
|
19 |
Portions created by the Initial Developer are Copyright (C) 2011
|
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@324
|
49 |
new Drive("KINGSTON SNV425S264GB", 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@324
|
68 |
new Drive("PLEXTOR PX-128M2S", 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@324
|
87 |
new Drive("OCZ-VERTEX2", 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@324
|
108 |
new Drive("WDC WD5000AADS-00S9B0", 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@324
|
130 |
new Drive("INTEL SSDSA2M080G2GC", 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@324
|
146 |
new Drive("OCZ-VERTEX", 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@324
|
170 |
new Drive("INTEL SSDSA2CW120G3", 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@324
|
189 |
F2 264F00000000 100 100 0")
|
moel@324
|
190 |
};
|
moel@324
|
191 |
|
moel@324
|
192 |
public IntPtr OpenDrive(int driveNumber) {
|
moel@324
|
193 |
if (driveNumber < drives.Length)
|
moel@324
|
194 |
return (IntPtr)driveNumber;
|
moel@324
|
195 |
else
|
moel@324
|
196 |
return InvalidHandle;
|
moel@324
|
197 |
}
|
moel@324
|
198 |
|
moel@324
|
199 |
public bool EnableSmart(IntPtr handle, int driveNumber) {
|
moel@324
|
200 |
if (handle != (IntPtr)driveNumber)
|
moel@324
|
201 |
throw new ArgumentOutOfRangeException();
|
moel@324
|
202 |
|
moel@324
|
203 |
return true;
|
moel@324
|
204 |
}
|
moel@324
|
205 |
|
moel@324
|
206 |
public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber) {
|
moel@324
|
207 |
if (handle != (IntPtr)driveNumber)
|
moel@324
|
208 |
throw new ArgumentOutOfRangeException();
|
moel@324
|
209 |
|
moel@324
|
210 |
return drives[driveNumber].DriveAttributeValues;
|
moel@324
|
211 |
}
|
moel@324
|
212 |
|
moel@324
|
213 |
public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle,
|
moel@324
|
214 |
int driveNumber)
|
moel@324
|
215 |
{
|
moel@324
|
216 |
if (handle != (IntPtr)driveNumber)
|
moel@324
|
217 |
throw new ArgumentOutOfRangeException();
|
moel@324
|
218 |
|
moel@324
|
219 |
return drives[driveNumber].DriveThresholdValues;
|
moel@324
|
220 |
}
|
moel@324
|
221 |
|
moel@324
|
222 |
public string ReadName(IntPtr handle, int driveNumber) {
|
moel@324
|
223 |
if (handle != (IntPtr)driveNumber)
|
moel@324
|
224 |
throw new ArgumentOutOfRangeException();
|
moel@324
|
225 |
|
moel@324
|
226 |
return drives[driveNumber].Name;
|
moel@324
|
227 |
}
|
moel@324
|
228 |
|
moel@324
|
229 |
public void CloseHandle(IntPtr handle) { }
|
moel@324
|
230 |
|
moel@324
|
231 |
|
moel@324
|
232 |
private class Drive {
|
moel@324
|
233 |
|
moel@324
|
234 |
public Drive(string name, int idBase, string value) {
|
moel@324
|
235 |
this.Name = name;
|
moel@324
|
236 |
|
moel@324
|
237 |
string[] lines = value.Split(new[] { '\r', '\n' },
|
moel@324
|
238 |
StringSplitOptions.RemoveEmptyEntries);
|
moel@324
|
239 |
|
moel@324
|
240 |
DriveAttributeValues = new DriveAttributeValue[lines.Length];
|
moel@324
|
241 |
List<DriveThresholdValue> thresholds = new List<DriveThresholdValue>();
|
moel@324
|
242 |
|
moel@324
|
243 |
for (int i = 0; i < lines.Length; i++) {
|
moel@324
|
244 |
|
moel@324
|
245 |
string[] array = lines[i].Split(new[] { ' ' },
|
moel@324
|
246 |
StringSplitOptions.RemoveEmptyEntries);
|
moel@324
|
247 |
|
moel@324
|
248 |
if (array.Length != 4 && array.Length != 5)
|
moel@324
|
249 |
throw new Exception();
|
moel@324
|
250 |
|
moel@324
|
251 |
DriveAttributeValue v = new DriveAttributeValue();
|
moel@324
|
252 |
v.Identifier = Convert.ToByte(array[0], idBase);
|
moel@324
|
253 |
|
moel@324
|
254 |
v.RawValue = new byte[6];
|
moel@324
|
255 |
for (int j = 0; j < 6; j++) {
|
moel@324
|
256 |
v.RawValue[j] = Convert.ToByte(array[1].Substring(2 * j, 2), 16);
|
moel@324
|
257 |
}
|
moel@324
|
258 |
|
moel@324
|
259 |
v.WorstValue = Convert.ToByte(array[2], 10);
|
moel@324
|
260 |
v.AttrValue = Convert.ToByte(array[3], 10);
|
moel@324
|
261 |
|
moel@324
|
262 |
DriveAttributeValues[i] = v;
|
moel@324
|
263 |
|
moel@324
|
264 |
if (array.Length == 5) {
|
moel@324
|
265 |
DriveThresholdValue t = new DriveThresholdValue();
|
moel@324
|
266 |
t.Identifier = v.Identifier;
|
moel@324
|
267 |
t.Threshold = Convert.ToByte(array[4], 10);
|
moel@324
|
268 |
thresholds.Add(t);
|
moel@324
|
269 |
}
|
moel@324
|
270 |
}
|
moel@324
|
271 |
|
moel@324
|
272 |
DriveThresholdValues = thresholds.ToArray();
|
moel@324
|
273 |
}
|
moel@324
|
274 |
|
moel@324
|
275 |
public DriveAttributeValue[] DriveAttributeValues { get; private set; }
|
moel@324
|
276 |
|
moel@324
|
277 |
public DriveThresholdValue[] DriveThresholdValues { get; private set; }
|
moel@324
|
278 |
|
moel@324
|
279 |
public string Name { get; private set; }
|
moel@324
|
280 |
}
|
moel@324
|
281 |
|
moel@324
|
282 |
public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
|
moel@324
|
283 |
}
|
moel@324
|
284 |
|
moel@324
|
285 |
#endif
|
moel@324
|
286 |
|
moel@324
|
287 |
}
|