123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package camsucks.model;
- /**
- *
- * 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
- *
- * @author Roel
- */
- public class Sensor {
- private String[] temperatureSensorList;
- private String[] loadSensorList;
- private int cpuCoreNumber;
- private double cpuLoad;
- private double cpuPackageTemp;
- private double cpuMax;
- private double gpuTemp;
- private double gpuMax;
- /**
- * The constructor for this class
- * At the start the lists of sensors are made with the help of the jWMI class
- * Then the number of cores of the system is calculated
- *
- * @throws Exception when the WMI value can't be obtained
- */
- public Sensor() throws Exception {
-
- temperatureSensorList = jWMI.getWMISensorList("Temperature").split(", ");
- loadSensorList = jWMI.getWMISensorList("Load").split(", ");
- //System.out.println(Arrays.toString(temperatureSensorList));
- //System.out.println(Arrays.toString(loadSensorList));
- //Init for cpuCoreNumber
- cpuCoreNumber = 0;
- for (String temperatureSensorList1 : loadSensorList) {
- if (temperatureSensorList1.contains("CPU Core #")) {
- int tempNumber;
- // gets the int value of the number after #
- tempNumber = Integer.parseInt(temperatureSensorList1.substring(10, 11).trim());
- if (tempNumber > cpuCoreNumber) {
- cpuCoreNumber = tempNumber;
- }
- }
- }
- }
- /**
- * This method polls the value of the CPU Load sensor
- * @throws Exception
- */
- public void pollCPULoad() throws Exception {
- cpuLoad = Double.parseDouble(jWMI.getWMIValue("Load", "CPU Total"));
- }
-
- /**
- * This method polls the value of the CPU Load sensor
- * @throws NumberFormatException
- * @throws Exception
- */
- public void pollCPUMax() throws NumberFormatException, Exception {
- cpuMax = Double.parseDouble(jWMI.getWMIValue("Temperature", "CPU Package", "Max"));
- }
-
- /**
- * This method polls the value of the CPU Load sensor
- * @throws Exception
- */
- public void pollGPUMax() throws Exception {
- gpuMax = Double.parseDouble(jWMI.getWMIValue("Temperature", "GPU Core", "Max"));
- }
-
- /**
- * This method polls the value of the GPU Temperature sensor
- * @throws Exception
- */
- public void pollGPUTemp() throws Exception {
- gpuTemp = Double.parseDouble(jWMI.getWMIValue("Temperature", "GPU Core"));
- }
- /**
- * This method polls the value of the CPU Temperature sensor
- * @throws Exception
- */
- public void pollCPUTemp() throws Exception {
- cpuPackageTemp = Double.parseDouble(jWMI.getWMIValue("Temperature", "CPU Package"));
- }
- /**
- * @return the temperatureSensorList
- */
- public String[] getTemperatureSensorList() {
- return temperatureSensorList;
- }
- /**
- * @return the loadSensorList
- */
- public String[] getLoadSensorList() {
- return loadSensorList;
- }
- /**
- * @return the cpuCoreNumber
- */
- public int getCpuCoreNumber() {
- return cpuCoreNumber;
- }
-
- /**
- * @return the cpuLoad
- */
- public double getCpuLoad() {
- return cpuLoad;
- }
- /**
- * @return the cpuPackageTemp
- */
- public double getCPUTemp() {
- return cpuPackageTemp;
- }
- /**
- * @return the gpuTemp
- */
- public double getGPUTemp() {
- return gpuTemp;
- }
- /**
- * @return the cpuMax
- */
- public double getCpuMax() {
- return cpuMax;
- }
-
- /**
- * @return the cpuMax
- */
- public double getGpuMax() {
- return gpuMax;
- }
- }
|