Added support for saving and restoring the sensor history for the last 24h. The sensor history is now saved in a reduced format (duplicate values are removed, gaps are marked with a NAN sensor value.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2011
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
41 using System.Management;
44 namespace OpenHardwareMonitor.Hardware.Mainboard {
46 internal class SMBIOS {
48 private readonly byte[] raw;
49 private readonly Structure[] table;
51 private readonly Version version;
52 private readonly BIOSInformation biosInformation;
53 private readonly BaseBoardInformation baseBoardInformation;
55 private static string ReadSysFS(string path) {
57 if (File.Exists(path)) {
58 using (StreamReader reader = new StreamReader(path))
59 return reader.ReadLine();
69 int p = (int)Environment.OSVersion.Platform;
70 if ((p == 4) || (p == 128)) {
74 string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
75 string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
76 string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
77 this.baseBoardInformation = new BaseBoardInformation(
78 boardVendor, boardName, boardVersion, null);
80 string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
81 string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
82 this.biosInformation = new BIOSInformation(biosVendor, biosVersion);
85 List<Structure> structureList = new List<Structure>();
88 byte majorVersion = 0;
89 byte minorVersion = 0;
91 ManagementObjectCollection collection;
92 using (ManagementObjectSearcher searcher =
93 new ManagementObjectSearcher("root\\WMI",
94 "SELECT * FROM MSSMBios_RawSMBiosTables")) {
95 collection = searcher.Get();
98 foreach (ManagementObject mo in collection) {
99 raw = (byte[])mo["SMBiosData"];
100 majorVersion = (byte)mo["SmbiosMajorVersion"];
101 minorVersion = (byte)mo["SmbiosMinorVersion"];
106 if (majorVersion > 0 || minorVersion > 0)
107 version = new Version(majorVersion, minorVersion);
109 if (raw != null && raw.Length > 0) {
111 byte type = raw[offset];
112 while (offset + 4 < raw.Length && type != 127) {
115 int length = raw[offset + 1];
116 ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);
118 if (offset + length > raw.Length)
120 byte[] data = new byte[length];
121 Array.Copy(raw, offset, data, 0, length);
124 List<string> stringsList = new List<string>();
125 if (offset < raw.Length && raw[offset] == 0)
128 while (offset < raw.Length && raw[offset] != 0) {
129 StringBuilder sb = new StringBuilder();
130 while (offset < raw.Length && raw[offset] != 0) {
131 sb.Append((char)raw[offset]); offset++;
134 stringsList.Add(sb.ToString());
139 this.biosInformation = new BIOSInformation(
140 type, handle, data, stringsList.ToArray());
141 structureList.Add(this.biosInformation); break;
142 case 0x02: this.baseBoardInformation = new BaseBoardInformation(
143 type, handle, data, stringsList.ToArray());
144 structureList.Add(this.baseBoardInformation); break;
145 default: structureList.Add(new Structure(
146 type, handle, data, stringsList.ToArray())); break;
151 table = structureList.ToArray();
155 public string GetReport() {
156 StringBuilder r = new StringBuilder();
158 if (version != null) {
159 r.Append("SMBIOS Version: "); r.AppendLine(version.ToString(2));
164 r.Append("BIOS Vendor: "); r.AppendLine(BIOS.Vendor);
165 r.Append("BIOS Version: "); r.AppendLine(BIOS.Version);
170 r.Append("Mainboard Manufacturer: ");
171 r.AppendLine(Board.ManufacturerName);
172 r.Append("Mainboard Name: ");
173 r.AppendLine(Board.ProductName);
174 r.Append("Mainboard Version: ");
175 r.AppendLine(Board.Version);
180 string base64 = Convert.ToBase64String(raw);
181 r.AppendLine("SMBIOS Table");
184 for (int i = 0; i < Math.Ceiling(base64.Length / 64.0); i++) {
186 for (int j = 0; j < 0x40; j++) {
187 int index = (i << 6) | j;
188 if (index < base64.Length) {
189 r.Append(base64[index]);
200 public BIOSInformation BIOS {
201 get { return biosInformation; }
204 public BaseBoardInformation Board {
205 get { return baseBoardInformation; }
208 public class Structure {
209 private readonly byte type;
210 private readonly ushort handle;
212 private readonly byte[] data;
213 private readonly string[] strings;
215 protected string GetString(int offset) {
216 if (offset < data.Length && data[offset] > 0 &&
217 data[offset] <= strings.Length)
218 return strings[data[offset] - 1];
223 public Structure(byte type, ushort handle, byte[] data, string[] strings)
226 this.handle = handle;
228 this.strings = strings;
231 public byte Type { get { return type; } }
233 public ushort Handle { get { return handle; } }
236 public class BIOSInformation : Structure {
238 private readonly string vendor;
239 private readonly string version;
241 public BIOSInformation(string vendor, string version)
242 : base (0x00, 0, null, null)
244 this.vendor = vendor;
245 this.version = version;
248 public BIOSInformation(byte type, ushort handle, byte[] data,
250 : base(type, handle, data, strings)
252 this.vendor = GetString(0x04);
253 this.version = GetString(0x05);
256 public string Vendor { get { return vendor; } }
258 public string Version { get { return version; } }
261 public class BaseBoardInformation : Structure {
263 private readonly string manufacturerName;
264 private readonly string productName;
265 private readonly string version;
266 private readonly string serialNumber;
267 private readonly Manufacturer manufacturer;
268 private readonly Model model;
270 private static Manufacturer GetManufacturer(string name) {
273 return Manufacturer.Alienware;
275 return Manufacturer.Apple;
277 return Manufacturer.ASRock;
278 case "ASUSTeK Computer INC.":
279 return Manufacturer.ASUS;
281 return Manufacturer.Dell;
284 return Manufacturer.DFI;
286 return Manufacturer.ECS;
287 case "EPoX COMPUTER CO., LTD":
288 return Manufacturer.EPoX;
290 return Manufacturer.EVGA;
291 case "First International Computer, Inc.":
292 return Manufacturer.FIC;
294 case "FUJITSU SIEMENS":
295 return Manufacturer.Fujitsu;
296 case "Gigabyte Technology Co., Ltd.":
297 return Manufacturer.Gigabyte;
298 case "Hewlett-Packard":
299 return Manufacturer.HP;
301 return Manufacturer.IBM;
304 case "Intel Corporation":
305 case "INTEL Corporation":
306 return Manufacturer.Intel;
309 return Manufacturer.Lenovo;
310 case "Micro-Star International":
311 case "MICRO-STAR INTERNATIONAL CO., LTD":
312 case "MICRO-STAR INTERNATIONAL CO.,LTD":
314 return Manufacturer.MSI;
316 return Manufacturer.Supermicro;
318 return Manufacturer.Toshiba;
320 return Manufacturer.XFX;
321 case "To be filled by O.E.M.":
322 return Manufacturer.Unknown;
324 return Manufacturer.Unknown;
328 private static Model GetModel(string name) {
331 return Model._880GMH_USB3;
332 case "ASRock AOD790GX/128M":
333 return Model.AOD790GX_128M;
335 return Model.P55_Deluxe;
336 case "Crosshair III Formula":
337 return Model.Crosshair_III_Formula;
338 case "M2N-SLI DELUXE":
339 return Model.M2N_SLI_DELUXE;
341 return Model.M4A79XTD_EVO;
342 case "P5W DH Deluxe":
343 return Model.P5W_DH_Deluxe;
345 return Model.P6X58D_E;
347 return Model.P8P67_PRO;
349 return Model.P8P67_M_PRO;
350 case "Rampage Extreme":
351 return Model.Rampage_Extreme;
352 case "Rampage II GENE":
353 return Model.Rampage_II_GENE;
354 case "LP BI P45-T2RS Elite":
355 return Model.LP_BI_P45_T2RS_Elite;
356 case "LP DK P55-T3eH9":
357 return Model.LP_DK_P55_T3eH9;
359 return Model.A890GXM_A;
360 case "X58 SLI Classified":
361 return Model.X58_SLI_Classified;
363 return Model._965P_S3;
365 return Model.EP45_DS3R;
367 return Model.EP45_UD3R;
369 return Model.EX58_EXTREME;
370 case "GA-MA770T-UD3":
371 return Model.GA_MA770T_UD3;
372 case "GA-MA785GMT-UD2H":
373 return Model.GA_MA785GMT_UD2H;
375 return Model.H67A_UD3H_B3;
377 return Model.P35_DS3;
379 return Model.P35_DS3L;
381 return Model.P55_UD4;
383 return Model.P55M_UD4;
385 return Model.P67A_UD4_B3;
387 return Model.X38_DS5;
389 return Model.X58A_UD3R;
390 case "Base Board Product Name":
391 case "To be filled by O.E.M.":
392 return Model.Unknown;
394 return Model.Unknown;
398 public BaseBoardInformation(string manufacturerName, string productName,
399 string version, string serialNumber)
400 : base(0x02, 0, null, null)
402 this.manufacturerName = manufacturerName;
403 this.manufacturer = GetManufacturer(manufacturerName);
404 this.productName = productName;
405 this.model = GetModel(productName);
406 this.version = version;
407 this.serialNumber = serialNumber;
410 public BaseBoardInformation(byte type, ushort handle, byte[] data,
412 : base(type, handle, data, strings) {
414 this.manufacturerName = GetString(0x04).Trim();
415 this.manufacturer = GetManufacturer(this.manufacturerName);
416 this.productName = GetString(0x05).Trim();
417 this.model = GetModel(this.productName);
418 this.version = GetString(0x06).Trim();
419 this.serialNumber = GetString(0x07).Trim();
422 public string ManufacturerName { get { return manufacturerName; } }
424 public string ProductName { get { return productName; } }
426 public string Version { get { return version; } }
428 public string SerialNumber { get { return serialNumber; } }
430 public Manufacturer Manufacturer { get { return manufacturer; } }
432 public Model Model { get { return model; } }