Added additional checks to SMBIOS parsing. New class HexStringArray is for debugging with report data.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Hardware/LPC/F71882.cs Fri Jan 29 20:05:32 2010 +0000
1.3 @@ -0,0 +1,188 @@
1.4 +/*
1.5 +
1.6 + Version: MPL 1.1/GPL 2.0/LGPL 2.1
1.7 +
1.8 + The contents of this file are subject to the Mozilla Public License Version
1.9 + 1.1 (the "License"); you may not use this file except in compliance with
1.10 + the License. You may obtain a copy of the License at
1.11 +
1.12 + http://www.mozilla.org/MPL/
1.13 +
1.14 + Software distributed under the License is distributed on an "AS IS" basis,
1.15 + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1.16 + for the specific language governing rights and limitations under the License.
1.17 +
1.18 + The Original Code is the Open Hardware Monitor code.
1.19 +
1.20 + The Initial Developer of the Original Code is
1.21 + Michael Möller <m.moeller@gmx.ch>.
1.22 + Portions created by the Initial Developer are Copyright (C) 2009-2010
1.23 + the Initial Developer. All Rights Reserved.
1.24 +
1.25 + Contributor(s):
1.26 +
1.27 + Alternatively, the contents of this file may be used under the terms of
1.28 + either the GNU General Public License Version 2 or later (the "GPL"), or
1.29 + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1.30 + in which case the provisions of the GPL or the LGPL are applicable instead
1.31 + of those above. If you wish to allow use of your version of this file only
1.32 + under the terms of either the GPL or the LGPL, and not to allow others to
1.33 + use your version of this file under the terms of the MPL, indicate your
1.34 + decision by deleting the provisions above and replace them with the notice
1.35 + and other provisions required by the GPL or the LGPL. If you do not delete
1.36 + the provisions above, a recipient may use your version of this file under
1.37 + the terms of any one of the MPL, the GPL or the LGPL.
1.38 +
1.39 +*/
1.40 +
1.41 +using System;
1.42 +using System.Collections.Generic;
1.43 +using System.Drawing;
1.44 +using System.Text;
1.45 +
1.46 +namespace OpenHardwareMonitor.Hardware.LPC {
1.47 + public class F71882 : IHardware {
1.48 +
1.49 + private string name;
1.50 + private Image icon;
1.51 +
1.52 + private ushort address;
1.53 +
1.54 + private List<ISensor> active = new List<ISensor>();
1.55 +
1.56 + private Sensor[] temperatures;
1.57 + private Sensor[] fans;
1.58 + private Sensor[] voltages;
1.59 + private float[] voltageGains;
1.60 +
1.61 + // Hardware Monitor
1.62 + private const byte ADDRESS_REGISTER_OFFSET = 0x05;
1.63 + private const byte DATA_REGISTER_OFFSET = 0x06;
1.64 +
1.65 + // Hardware Monitor Registers
1.66 + private const byte VOLTAGE_BASE_REG = 0x20;
1.67 + private const byte TEMPERATURE_BASE_REG = 0x72;
1.68 + private byte[] FAN_TACHOMETER_REG = new byte[] { 0xA0, 0xB0, 0xC0, 0xD0 };
1.69 +
1.70 + private byte ReadByte(byte register) {
1.71 + WinRing0.WriteIoPortByte(
1.72 + (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
1.73 + return WinRing0.ReadIoPortByte((ushort)(address + DATA_REGISTER_OFFSET));
1.74 + }
1.75 +
1.76 + public F71882(ushort address) {
1.77 + this.address = address;
1.78 +
1.79 + this.name = "Fintek F71882";
1.80 +
1.81 + temperatures = new Sensor[3];
1.82 + for (int i = 0; i < temperatures.Length; i++)
1.83 + temperatures[i] = new Sensor("Temperature #" + (i + 1), i,
1.84 + SensorType.Temperature, this);
1.85 +
1.86 + fans = new Sensor[4];
1.87 + for (int i = 0; i < fans.Length; i++)
1.88 + fans[i] = new Sensor("Fan #" + (i + 1), i, SensorType.Fan, this);
1.89 +
1.90 + voltageGains = new float[] { 1, 0.5f, 1, 1, 1, 1, 1, 1, 1 };
1.91 + voltages = new Sensor[4];
1.92 + voltages[0] = new Sensor("VCC3V", 0, SensorType.Voltage, this);
1.93 + voltages[1] = new Sensor("CPU VCore", 1, SensorType.Voltage, this);
1.94 + voltages[2] = new Sensor("VSB3V", 7, SensorType.Voltage, this);
1.95 + voltages[3] = new Sensor("Battery", 8, SensorType.Voltage, this);
1.96 +
1.97 + this.icon = Utilities.EmbeddedResources.GetImage("chip.png");
1.98 + }
1.99 +
1.100 + public string Name {
1.101 + get { return name; }
1.102 + }
1.103 +
1.104 + public string Identifier {
1.105 + get { return "/lpc/f71882fg"; }
1.106 + }
1.107 +
1.108 + public Image Icon {
1.109 + get { return icon; }
1.110 + }
1.111 +
1.112 + public ISensor[] Sensors {
1.113 + get { return active.ToArray(); }
1.114 + }
1.115 +
1.116 + public string GetReport() {
1.117 + StringBuilder r = new StringBuilder();
1.118 +
1.119 + r.AppendLine("LPC F71882FG");
1.120 + r.AppendLine();
1.121 + r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4"));
1.122 + r.AppendLine();
1.123 + r.AppendLine("Hardware Monitor Registers");
1.124 + r.AppendLine();
1.125 +
1.126 + r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
1.127 + r.AppendLine();
1.128 + for (int i = 0; i <= 0xF; i++) {
1.129 + r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" ");
1.130 + for (int j = 0; j <= 0xF; j++) {
1.131 + r.Append(" ");
1.132 + r.Append(ReadByte((byte)((i << 4) | j)).ToString("X2"));
1.133 + }
1.134 + r.AppendLine();
1.135 + }
1.136 + r.AppendLine();
1.137 + return r.ToString();
1.138 + }
1.139 +
1.140 + public void Update() {
1.141 +
1.142 + foreach (Sensor sensor in voltages) {
1.143 + int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index));
1.144 + sensor.Value = voltageGains[sensor.Index] * 0.001f * (value << 4);
1.145 + if (sensor.Value > 0)
1.146 + ActivateSensor(sensor);
1.147 + else
1.148 + DeactivateSensor(sensor);
1.149 + }
1.150 +
1.151 + foreach (Sensor sensor in temperatures) {
1.152 + int value = ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * sensor.Index));
1.153 + sensor.Value = value;
1.154 + if (value < 254)
1.155 + ActivateSensor(sensor);
1.156 + else
1.157 + DeactivateSensor(sensor);
1.158 + }
1.159 +
1.160 + foreach (Sensor sensor in fans) {
1.161 + int value = ReadByte(FAN_TACHOMETER_REG[sensor.Index]) << 8;
1.162 + value |= ReadByte((byte)(FAN_TACHOMETER_REG[sensor.Index] + 1));
1.163 +
1.164 + if (value > 0) {
1.165 + sensor.Value = (value < 0x0fff) ? 1.5e6f / value : 0;
1.166 + ActivateSensor(sensor);
1.167 + } else {
1.168 + DeactivateSensor(sensor);
1.169 + }
1.170 + }
1.171 + }
1.172 +
1.173 + private void ActivateSensor(Sensor sensor) {
1.174 + if (!active.Contains(sensor)) {
1.175 + active.Add(sensor);
1.176 + SensorAdded(sensor);
1.177 + }
1.178 + }
1.179 +
1.180 + private void DeactivateSensor(Sensor sensor) {
1.181 + if (active.Contains(sensor)) {
1.182 + active.Remove(sensor);
1.183 + SensorRemoved(sensor);
1.184 + }
1.185 + }
1.186 +
1.187 + public event SensorEventHandler SensorAdded;
1.188 + public event SensorEventHandler SensorRemoved;
1.189 +
1.190 + }
1.191 +}
2.1 --- a/Hardware/LPC/F71882FG.cs Fri Jan 29 19:20:44 2010 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,188 +0,0 @@
2.4 -/*
2.5 -
2.6 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
2.7 -
2.8 - The contents of this file are subject to the Mozilla Public License Version
2.9 - 1.1 (the "License"); you may not use this file except in compliance with
2.10 - the License. You may obtain a copy of the License at
2.11 -
2.12 - http://www.mozilla.org/MPL/
2.13 -
2.14 - Software distributed under the License is distributed on an "AS IS" basis,
2.15 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
2.16 - for the specific language governing rights and limitations under the License.
2.17 -
2.18 - The Original Code is the Open Hardware Monitor code.
2.19 -
2.20 - The Initial Developer of the Original Code is
2.21 - Michael Möller <m.moeller@gmx.ch>.
2.22 - Portions created by the Initial Developer are Copyright (C) 2009-2010
2.23 - the Initial Developer. All Rights Reserved.
2.24 -
2.25 - Contributor(s):
2.26 -
2.27 - Alternatively, the contents of this file may be used under the terms of
2.28 - either the GNU General Public License Version 2 or later (the "GPL"), or
2.29 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
2.30 - in which case the provisions of the GPL or the LGPL are applicable instead
2.31 - of those above. If you wish to allow use of your version of this file only
2.32 - under the terms of either the GPL or the LGPL, and not to allow others to
2.33 - use your version of this file under the terms of the MPL, indicate your
2.34 - decision by deleting the provisions above and replace them with the notice
2.35 - and other provisions required by the GPL or the LGPL. If you do not delete
2.36 - the provisions above, a recipient may use your version of this file under
2.37 - the terms of any one of the MPL, the GPL or the LGPL.
2.38 -
2.39 -*/
2.40 -
2.41 -using System;
2.42 -using System.Collections.Generic;
2.43 -using System.Drawing;
2.44 -using System.Text;
2.45 -
2.46 -namespace OpenHardwareMonitor.Hardware.LPC {
2.47 - public class F71882FG : IHardware {
2.48 -
2.49 - private string name;
2.50 - private Image icon;
2.51 -
2.52 - private ushort address;
2.53 -
2.54 - private List<ISensor> active = new List<ISensor>();
2.55 -
2.56 - private Sensor[] temperatures;
2.57 - private Sensor[] fans;
2.58 - private Sensor[] voltages;
2.59 - private float[] voltageGains;
2.60 -
2.61 - // Hardware Monitor
2.62 - private const byte ADDRESS_REGISTER_OFFSET = 0x05;
2.63 - private const byte DATA_REGISTER_OFFSET = 0x06;
2.64 -
2.65 - // Hardware Monitor Registers
2.66 - private const byte VOLTAGE_BASE_REG = 0x20;
2.67 - private const byte TEMPERATURE_BASE_REG = 0x72;
2.68 - private byte[] FAN_TACHOMETER_REG = new byte[] { 0xA0, 0xB0, 0xC0, 0xD0 };
2.69 -
2.70 - private byte ReadByte(byte register) {
2.71 - WinRing0.WriteIoPortByte(
2.72 - (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
2.73 - return WinRing0.ReadIoPortByte((ushort)(address + DATA_REGISTER_OFFSET));
2.74 - }
2.75 -
2.76 - public F71882FG(ushort address) {
2.77 - this.address = address;
2.78 -
2.79 - this.name = "Fintek F71882FG";
2.80 -
2.81 - temperatures = new Sensor[3];
2.82 - for (int i = 0; i < temperatures.Length; i++)
2.83 - temperatures[i] = new Sensor("Temperature #" + (i + 1), i,
2.84 - SensorType.Temperature, this);
2.85 -
2.86 - fans = new Sensor[4];
2.87 - for (int i = 0; i < fans.Length; i++)
2.88 - fans[i] = new Sensor("Fan #" + (i + 1), i, SensorType.Fan, this);
2.89 -
2.90 - voltageGains = new float[] { 1, 0.5f, 1, 1, 1, 1, 1, 1, 1 };
2.91 - voltages = new Sensor[4];
2.92 - voltages[0] = new Sensor("VCC3V", 0, SensorType.Voltage, this);
2.93 - voltages[1] = new Sensor("CPU VCore", 1, SensorType.Voltage, this);
2.94 - voltages[2] = new Sensor("VSB3V", 7, SensorType.Voltage, this);
2.95 - voltages[3] = new Sensor("Battery", 8, SensorType.Voltage, this);
2.96 -
2.97 - this.icon = Utilities.EmbeddedResources.GetImage("chip.png");
2.98 - }
2.99 -
2.100 - public string Name {
2.101 - get { return name; }
2.102 - }
2.103 -
2.104 - public string Identifier {
2.105 - get { return "/lpc/f71882fg"; }
2.106 - }
2.107 -
2.108 - public Image Icon {
2.109 - get { return icon; }
2.110 - }
2.111 -
2.112 - public ISensor[] Sensors {
2.113 - get { return active.ToArray(); }
2.114 - }
2.115 -
2.116 - public string GetReport() {
2.117 - StringBuilder r = new StringBuilder();
2.118 -
2.119 - r.AppendLine("LPC F71882FG");
2.120 - r.AppendLine();
2.121 - r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4"));
2.122 - r.AppendLine();
2.123 - r.AppendLine("Hardware Monitor Registers");
2.124 - r.AppendLine();
2.125 -
2.126 - r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
2.127 - r.AppendLine();
2.128 - for (int i = 0; i <= 0xF; i++) {
2.129 - r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append(" ");
2.130 - for (int j = 0; j <= 0xF; j++) {
2.131 - r.Append(" ");
2.132 - r.Append(ReadByte((byte)((i << 4) | j)).ToString("X2"));
2.133 - }
2.134 - r.AppendLine();
2.135 - }
2.136 - r.AppendLine();
2.137 - return r.ToString();
2.138 - }
2.139 -
2.140 - public void Update() {
2.141 -
2.142 - foreach (Sensor sensor in voltages) {
2.143 - int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index));
2.144 - sensor.Value = voltageGains[sensor.Index] * 0.001f * (value << 4);
2.145 - if (sensor.Value > 0)
2.146 - ActivateSensor(sensor);
2.147 - else
2.148 - DeactivateSensor(sensor);
2.149 - }
2.150 -
2.151 - foreach (Sensor sensor in temperatures) {
2.152 - int value = ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * sensor.Index));
2.153 - sensor.Value = value;
2.154 - if (value < 254)
2.155 - ActivateSensor(sensor);
2.156 - else
2.157 - DeactivateSensor(sensor);
2.158 - }
2.159 -
2.160 - foreach (Sensor sensor in fans) {
2.161 - int value = ReadByte(FAN_TACHOMETER_REG[sensor.Index]) << 8;
2.162 - value |= ReadByte((byte)(FAN_TACHOMETER_REG[sensor.Index] + 1));
2.163 -
2.164 - if (value > 0) {
2.165 - sensor.Value = (value < 0x0fff) ? 1.5e6f / value : 0;
2.166 - ActivateSensor(sensor);
2.167 - } else {
2.168 - DeactivateSensor(sensor);
2.169 - }
2.170 - }
2.171 - }
2.172 -
2.173 - private void ActivateSensor(Sensor sensor) {
2.174 - if (!active.Contains(sensor)) {
2.175 - active.Add(sensor);
2.176 - SensorAdded(sensor);
2.177 - }
2.178 - }
2.179 -
2.180 - private void DeactivateSensor(Sensor sensor) {
2.181 - if (active.Contains(sensor)) {
2.182 - active.Remove(sensor);
2.183 - SensorRemoved(sensor);
2.184 - }
2.185 - }
2.186 -
2.187 - public event SensorEventHandler SensorAdded;
2.188 - public event SensorEventHandler SensorRemoved;
2.189 -
2.190 - }
2.191 -}
3.1 --- a/Hardware/LPC/LPCGroup.cs Fri Jan 29 19:20:44 2010 +0000
3.2 +++ b/Hardware/LPC/LPCGroup.cs Fri Jan 29 20:05:32 2010 +0000
3.3 @@ -176,7 +176,7 @@
3.4 break;
3.5 case Chip.F71882FG:
3.6 if (vendorID == FINTEK_VENDOR_ID)
3.7 - hardware.Add(new F71882FG(address));
3.8 + hardware.Add(new F71882(address));
3.9 break;
3.10 default: break;
3.11 }
4.1 --- a/Hardware/SMBIOS/SMBIOSGroup.cs Fri Jan 29 19:20:44 2010 +0000
4.2 +++ b/Hardware/SMBIOS/SMBIOSGroup.cs Fri Jan 29 20:05:32 2010 +0000
4.3 @@ -144,6 +144,14 @@
4.4 private byte[] data;
4.5 private string[] strings;
4.6
4.7 + protected string GetString(int offset) {
4.8 + if (offset < data.Length && data[offset] > 0 &&
4.9 + data[offset] <= strings.Length)
4.10 + return strings[data[offset] - 1];
4.11 + else
4.12 + return "";
4.13 + }
4.14 +
4.15 public Structure(byte type, ushort handle, byte[] data, string[] strings)
4.16 {
4.17 this.type = type;
4.18 @@ -159,18 +167,15 @@
4.19
4.20 public class BIOSInformation : Structure {
4.21
4.22 - private string vendor = "";
4.23 - private string version = "";
4.24 + private string vendor;
4.25 + private string version;
4.26
4.27 public BIOSInformation(byte type, ushort handle, byte[] data,
4.28 string[] strings)
4.29 : base(type, handle, data, strings) {
4.30
4.31 - if (data[0x04] > 0 && data[0x04] <= strings.Length)
4.32 - vendor = strings[data[0x04] - 1];
4.33 -
4.34 - if (data[0x05] > 0 && data[0x05] <= strings.Length)
4.35 - version = strings[data[0x05] - 1];
4.36 + this.vendor = GetString(0x04);
4.37 + this.version = GetString(0x05);
4.38 }
4.39
4.40 public string Vendor { get { return vendor; } }
4.41 @@ -180,18 +185,15 @@
4.42
4.43 public class BaseBoardInformation : Structure {
4.44
4.45 - private string manufacturer = "";
4.46 - private string productName = "";
4.47 + private string manufacturer;
4.48 + private string productName;
4.49
4.50 public BaseBoardInformation(byte type, ushort handle, byte[] data,
4.51 string[] strings)
4.52 : base(type, handle, data, strings) {
4.53
4.54 - if (data[0x04] > 0 && data[0x04] <= strings.Length)
4.55 - manufacturer = strings[data[0x04] - 1];
4.56 -
4.57 - if (data[0x05] > 0 && data[0x05] <= strings.Length)
4.58 - productName = strings[data[0x05] - 1];
4.59 + this.manufacturer = GetString(0x04);
4.60 + this.productName = GetString(0x05);
4.61 }
4.62
4.63 public string Manufacturer { get { return manufacturer; } }
5.1 --- a/OpenHardwareMonitor.csproj Fri Jan 29 19:20:44 2010 +0000
5.2 +++ b/OpenHardwareMonitor.csproj Fri Jan 29 20:05:32 2010 +0000
5.3 @@ -62,7 +62,7 @@
5.4 <Compile Include="Hardware\HDD\HDDGroup.cs" />
5.5 <Compile Include="Hardware\HDD\SMART.cs" />
5.6 <Compile Include="Hardware\LPC\Chip.cs" />
5.7 - <Compile Include="Hardware\LPC\F71882FG.cs" />
5.8 + <Compile Include="Hardware\LPC\F71882.cs" />
5.9 <Compile Include="Hardware\SMBIOS\SMBIOSGroup.cs" />
5.10 <Compile Include="Hardware\LPC\W83627DHG.cs" />
5.11 <Compile Include="Hardware\ReportWriter.cs" />
5.12 @@ -94,6 +94,7 @@
5.13 <Compile Include="Hardware\Nvidia\NVAPI.cs" />
5.14 <Compile Include="Hardware\Nvidia\NvidiaGPU.cs" />
5.15 <Compile Include="Hardware\Nvidia\NvidiaGroup.cs" />
5.16 + <Compile Include="Utilities\HexStringArray.cs" />
5.17 <Compile Include="Utilities\PInvokeDelegateFactory.cs" />
5.18 <Compile Include="GUI\PlotPanel.cs">
5.19 <SubType>UserControl</SubType>
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/Utilities/HexStringArray.cs Fri Jan 29 20:05:32 2010 +0000
6.3 @@ -0,0 +1,60 @@
6.4 +/*
6.5 +
6.6 + Version: MPL 1.1/GPL 2.0/LGPL 2.1
6.7 +
6.8 + The contents of this file are subject to the Mozilla Public License Version
6.9 + 1.1 (the "License"); you may not use this file except in compliance with
6.10 + the License. You may obtain a copy of the License at
6.11 +
6.12 + http://www.mozilla.org/MPL/
6.13 +
6.14 + Software distributed under the License is distributed on an "AS IS" basis,
6.15 + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
6.16 + for the specific language governing rights and limitations under the License.
6.17 +
6.18 + The Original Code is the Open Hardware Monitor code.
6.19 +
6.20 + The Initial Developer of the Original Code is
6.21 + Michael Möller <m.moeller@gmx.ch>.
6.22 + Portions created by the Initial Developer are Copyright (C) 2009-2010
6.23 + the Initial Developer. All Rights Reserved.
6.24 +
6.25 + Contributor(s):
6.26 +
6.27 + Alternatively, the contents of this file may be used under the terms of
6.28 + either the GNU General Public License Version 2 or later (the "GPL"), or
6.29 + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
6.30 + in which case the provisions of the GPL or the LGPL are applicable instead
6.31 + of those above. If you wish to allow use of your version of this file only
6.32 + under the terms of either the GPL or the LGPL, and not to allow others to
6.33 + use your version of this file under the terms of the MPL, indicate your
6.34 + decision by deleting the provisions above and replace them with the notice
6.35 + and other provisions required by the GPL or the LGPL. If you do not delete
6.36 + the provisions above, a recipient may use your version of this file under
6.37 + the terms of any one of the MPL, the GPL or the LGPL.
6.38 +
6.39 +*/
6.40 +
6.41 +using System;
6.42 +using System.Collections.Generic;
6.43 +using System.Text;
6.44 +
6.45 +namespace OpenHardwareMonitor.Utilities {
6.46 + public class HexStringArray {
6.47 +
6.48 + private byte[] array;
6.49 +
6.50 + public HexStringArray(string input) {
6.51 + List<byte> list = new List<byte>();
6.52 + foreach (string str in input.Split(' ')) {
6.53 + if (str.Trim().Length > 0)
6.54 + list.Add(Convert.ToByte(str, 16));
6.55 + }
6.56 + array = list.ToArray();
6.57 + }
6.58 +
6.59 + public byte this[int i] {
6.60 + get { return array[i]; }
6.61 + }
6.62 + }
6.63 +}