Sensor.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package camsucks.model;
  2. /**
  3. *
  4. * This class is a model for a collection of sensors
  5. * It contains a datamembers for some specific sensors as well as members for lists of sensors of a specific type.
  6. * each member has a getter but no setter.
  7. * 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
  8. *
  9. * @author Roel
  10. */
  11. public class Sensor {
  12. private String[] temperatureSensorList;
  13. private String[] loadSensorList;
  14. private int cpuCoreNumber;
  15. private double cpuLoad;
  16. private double cpuPackageTemp;
  17. private double cpuMax;
  18. private double gpuTemp;
  19. private double gpuMax;
  20. /**
  21. * The constructor for this class
  22. * At the start the lists of sensors are made with the help of the jWMI class
  23. * Then the number of cores of the system is calculated
  24. *
  25. * @throws Exception when the WMI value can't be obtained
  26. */
  27. public Sensor() throws Exception {
  28. temperatureSensorList = jWMI.getWMISensorList("Temperature").split(", ");
  29. loadSensorList = jWMI.getWMISensorList("Load").split(", ");
  30. //System.out.println(Arrays.toString(temperatureSensorList));
  31. //System.out.println(Arrays.toString(loadSensorList));
  32. //Init for cpuCoreNumber
  33. cpuCoreNumber = 0;
  34. for (String temperatureSensorList1 : loadSensorList) {
  35. if (temperatureSensorList1.contains("CPU Core #")) {
  36. int tempNumber;
  37. // gets the int value of the number after #
  38. tempNumber = Integer.parseInt(temperatureSensorList1.substring(10, 11).trim());
  39. if (tempNumber > cpuCoreNumber) {
  40. cpuCoreNumber = tempNumber;
  41. }
  42. }
  43. }
  44. }
  45. /**
  46. * This method polls the value of the CPU Load sensor
  47. * @throws Exception
  48. */
  49. public void pollCPULoad() throws Exception {
  50. cpuLoad = Double.parseDouble(jWMI.getWMIValue("Load", "CPU Total"));
  51. }
  52. /**
  53. * This method polls the value of the CPU Load sensor
  54. * @throws NumberFormatException
  55. * @throws Exception
  56. */
  57. public void pollCPUMax() throws NumberFormatException, Exception {
  58. cpuMax = Double.parseDouble(jWMI.getWMIValue("Temperature", "CPU Package", "Max"));
  59. }
  60. /**
  61. * This method polls the value of the CPU Load sensor
  62. * @throws Exception
  63. */
  64. public void pollGPUMax() throws Exception {
  65. gpuMax = Double.parseDouble(jWMI.getWMIValue("Temperature", "GPU Core", "Max"));
  66. }
  67. /**
  68. * This method polls the value of the GPU Temperature sensor
  69. * @throws Exception
  70. */
  71. public void pollGPUTemp() throws Exception {
  72. gpuTemp = Double.parseDouble(jWMI.getWMIValue("Temperature", "GPU Core"));
  73. }
  74. /**
  75. * This method polls the value of the CPU Temperature sensor
  76. * @throws Exception
  77. */
  78. public void pollCPUTemp() throws Exception {
  79. cpuPackageTemp = Double.parseDouble(jWMI.getWMIValue("Temperature", "CPU Package"));
  80. }
  81. /**
  82. * @return the temperatureSensorList
  83. */
  84. public String[] getTemperatureSensorList() {
  85. return temperatureSensorList;
  86. }
  87. /**
  88. * @return the loadSensorList
  89. */
  90. public String[] getLoadSensorList() {
  91. return loadSensorList;
  92. }
  93. /**
  94. * @return the cpuCoreNumber
  95. */
  96. public int getCpuCoreNumber() {
  97. return cpuCoreNumber;
  98. }
  99. /**
  100. * @return the cpuLoad
  101. */
  102. public double getCpuLoad() {
  103. return cpuLoad;
  104. }
  105. /**
  106. * @return the cpuPackageTemp
  107. */
  108. public double getCPUTemp() {
  109. return cpuPackageTemp;
  110. }
  111. /**
  112. * @return the gpuTemp
  113. */
  114. public double getGPUTemp() {
  115. return gpuTemp;
  116. }
  117. /**
  118. * @return the cpuMax
  119. */
  120. public double getCpuMax() {
  121. return cpuMax;
  122. }
  123. /**
  124. * @return the cpuMax
  125. */
  126. public double getGpuMax() {
  127. return gpuMax;
  128. }
  129. }