Parcourir la source

WindowsSensor updated to work like LMSensor

Tankernn il y a 8 ans
Parent
commit
f8230825d1

+ 1 - 1
src/main/java/eu/tankernn/grid/model/sensor/LMSensor.java

@@ -16,7 +16,7 @@ public class LMSensor extends Sensor {
 		try {
 			proc.waitFor();
 		} catch (InterruptedException e) {
-			e.printStackTrace();
+			System.err.println("LMSensor polling was interrupted.");
 			return;
 		}
 

+ 6 - 39
src/main/java/eu/tankernn/grid/model/sensor/WindowsSensor.java

@@ -4,48 +4,15 @@ import java.io.IOException;
 
 /**
  *
- * This class is a model for a collection of sensors It contains a datamembers
- * for some specific sensors as well as members for lists of sensors of a
- * specific type. each member has a getter but no setter. Instead of the setter
- * the members (except for the lists) have a poll function which polls the value
- * of the member using the jWMI class
+ * Sensor for Windows systems. Uses the jWMI class to get all temperature
+ * readings from the OpenHardwareMonitor instance.
  * 
- * @author Roel
+ * @author Frans
  */
 public class WindowsSensor extends Sensor {
-
-	private double cpuPackageTemp;
-	private double gpuTemp;
-
 	public void poll() throws IOException {
-		pollCPUTemp();
-		pollGPUTemp();
-	}
-
-	/**
-	 * This method polls the value of the GPU Temperature sensor
-	 * 
-	 * @throws Exception
-	 */
-	public void pollGPUTemp() throws IOException {
-		gpuTemp = Double.parseDouble(jWMI.getWMIValue("Temperature", "GPU Core"));
-	}
-
-	/**
-	 * This method polls the value of the CPU Temperature sensor
-	 * 
-	 * @throws Exception
-	 */
-	public void pollCPUTemp() throws IOException {
-		cpuPackageTemp = Double.parseDouble(jWMI.getWMIValue("Temperature", "CPU Package"));
+		String[] sensors = jWMI.getWMISensorList("Temperature").split(",");
+		for (String s : sensors)
+			temperatures.put(s, Double.parseDouble(jWMI.getWMIValue("Temperature", s)));
 	}
-
-	public double getCPUTemp() {
-		return cpuPackageTemp;
-	}
-
-	public double getGPUTemp() {
-		return gpuTemp;
-	}
-
 }

+ 1 - 22
src/main/java/eu/tankernn/grid/model/sensor/jWMI.java

@@ -38,13 +38,6 @@ import javax.naming.InvalidNameException;
  *
  * @author Copyright 2009-2010 HenryRanch LLC. Author Shaun Henry, 2009-2010.
  * @version 1.0
- * 
- * Changes by Roel:     rewritten the getVBScript function and added two variants getVBScriptList and getVBScriptValue to work with the OpenHardwareMonitor WMI Classes
- *                      rewritten the getWMIValue and added another variant getWMISensorList
- *                      Changed some demoqueries for testing purposes.
- *                      
- *                 
- *
  */
 public class jWMI {
 
@@ -57,7 +50,6 @@ public class jWMI {
      * @param SensorType The sensorType to get a list form.
      * <br>i.e. "Load"
      * @return the vbscript string.
-     *
      */
     private static String getVBScriptList(String SensorType) {
         String vbs = "strComputer = \".\"" + CRLF;
@@ -90,20 +82,7 @@ public class jWMI {
      *
      */
     private static String getVBScriptValue(String SensorType, String name) {
-        String vbs = "strComputer = \".\"" + CRLF;
-        vbs += "strNameSpace = \"root\\OpenHardwareMonitor\"" + CRLF;
-        vbs += "Dim oWMI : Set oWMI = GetObject(\"winmgmts:{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\\" & strNameSpace )" + CRLF;
-        vbs += "Dim classComponent : Set classComponent = oWMI.ExecQuery(\"Select * from Sensor\")" + CRLF;
-        vbs += "Dim obj, strData" + CRLF;
-        vbs += "For Each obj in classComponent" + CRLF;
-        vbs += "    If obj.SensorType = \"" + SensorType + "\" then" + CRLF;
-        vbs += "        If obj.Name = \"" + name + "\" then" + CRLF;
-        vbs += "            strData = strData & obj.Value" + CRLF;
-        vbs += "        End If" + CRLF;
-        vbs += "    End If" + CRLF;
-        vbs += "Next" + CRLF;
-        vbs += "wscript.echo strData" + CRLF;
-        return vbs;
+    	return getVBScriptValue(SensorType, name, "Value");
     }
     
     /**