2770 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Thermal Zone sensor class, getting information from Thermal Zone WMI class
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PSI_Sensor
|
|
|
9 |
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
|
|
|
10 |
* @copyright 2014 phpSysInfo
|
|
|
11 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
12 |
* @version Release: 3.0
|
|
|
13 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
14 |
*/
|
|
|
15 |
class ThermalZone extends Sensors
|
|
|
16 |
{
|
|
|
17 |
/**
|
|
|
18 |
* holds the COM object that we pull all the WMI data from
|
|
|
19 |
*
|
|
|
20 |
* @var Object
|
|
|
21 |
*/
|
|
|
22 |
private $_buf = array();
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* fill the private content var
|
|
|
26 |
*/
|
|
|
27 |
public function __construct()
|
|
|
28 |
{
|
|
|
29 |
parent::__construct();
|
|
|
30 |
if (PSI_OS == 'WINNT') {
|
|
|
31 |
$_wmi = null;
|
|
|
32 |
try {
|
|
|
33 |
// initialize the wmi object
|
|
|
34 |
$objLocator = new COM('WbemScripting.SWbemLocator');
|
|
|
35 |
$_wmi = $objLocator->ConnectServer('', 'root\WMI');
|
|
|
36 |
} catch (Exception $e) {
|
|
|
37 |
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
|
|
|
38 |
}
|
|
|
39 |
if ($_wmi) {
|
|
|
40 |
$this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* get temperature information
|
|
|
47 |
*
|
|
|
48 |
* @return void
|
|
|
49 |
*/
|
|
|
50 |
private function _temperature()
|
|
|
51 |
{
|
|
|
52 |
if (PSI_OS == 'WINNT') {
|
|
|
53 |
if ($this->_buf) foreach ($this->_buf as $buffer) {
|
|
|
54 |
if (isset($buffer['CurrentTemperature']) && (($value = ($buffer['CurrentTemperature'] - 2732)/10) > -100)) {
|
|
|
55 |
$dev = new SensorDevice();
|
|
|
56 |
if (isset($buffer['InstanceName']) && preg_match("/([^\\\\ ]+)$/", $buffer['InstanceName'], $outbuf)) {
|
|
|
57 |
$dev->setName('ThermalZone '.$outbuf[1]);
|
|
|
58 |
} else {
|
|
|
59 |
$dev->setName('ThermalZone THM0_0');
|
|
|
60 |
}
|
|
|
61 |
$dev->setValue($value);
|
|
|
62 |
if (isset($buffer['CriticalTripPoint']) && (($maxvalue = ($buffer['CriticalTripPoint'] - 2732)/10) > 0)) {
|
|
|
63 |
$dev->setMax($maxvalue);
|
|
|
64 |
}
|
|
|
65 |
$this->mbinfo->setMbTemp($dev);
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
} else {
|
|
|
69 |
$notwas = true;
|
|
|
70 |
$thermalzones = glob('/sys/class/thermal/thermal_zone*/');
|
|
|
71 |
if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
|
|
|
72 |
$thermalzonetemp = $thermalzone.'temp';
|
|
|
73 |
$temp = null;
|
|
|
74 |
if (CommonFunctions::rfts($thermalzonetemp, $temp, 1, 4096, false) && !is_null($temp) && (($temp = trim($temp)) != "")) {
|
|
|
75 |
if ($temp >= 1000) {
|
|
|
76 |
$div = 1000;
|
|
|
77 |
} elseif ($temp >= 200) {
|
|
|
78 |
$div = 10;
|
|
|
79 |
} else {
|
|
|
80 |
$div = 1;
|
|
|
81 |
}
|
|
|
82 |
$temp = $temp / $div;
|
|
|
83 |
|
|
|
84 |
if ($temp > -40) {
|
|
|
85 |
$dev = new SensorDevice();
|
|
|
86 |
$dev->setValue($temp);
|
|
|
87 |
|
|
|
88 |
$temp_type = null;
|
|
|
89 |
if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 1, 4096, false) && !is_null($temp_type) && (($temp_type = trim($temp_type)) != "")) {
|
|
|
90 |
$dev->setName($temp_type);
|
|
|
91 |
} else {
|
|
|
92 |
$dev->setName("ThermalZone");
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
$temp_max = null;
|
|
|
96 |
if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 1, 4096, false) && !is_null($temp_max) && (($temp_max = trim($temp_max)) != "") && ($temp_max > -40)) {
|
|
|
97 |
$temp_max = $temp_max / $div;
|
|
|
98 |
if (($temp_max != 0) || ($temp != 0)) { // if non-zero values
|
|
|
99 |
$dev->setMax($temp_max);
|
|
|
100 |
$this->mbinfo->setMbTemp($dev);
|
|
|
101 |
}
|
|
|
102 |
} else {
|
|
|
103 |
$this->mbinfo->setMbTemp($dev);
|
|
|
104 |
}
|
|
|
105 |
$notwas = false;
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
if ($notwas) {
|
|
|
110 |
$thermalzones = glob('/proc/acpi/thermal_zone/TH*/temperature');
|
|
|
111 |
if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
|
|
|
112 |
$temp = null;
|
|
|
113 |
if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && !is_null($temp) && (($temp = trim($temp)) != "")) {
|
|
|
114 |
$dev = new SensorDevice();
|
|
|
115 |
if (preg_match("/^\/proc\/acpi\/thermal_zone\/(.+)\/temperature$/", $thermalzone, $name)) {
|
|
|
116 |
$dev->setName("ThermalZone ".$name[1]);
|
|
|
117 |
} else {
|
|
|
118 |
$dev->setName("ThermalZone");
|
|
|
119 |
}
|
|
|
120 |
$dev->setValue(trim(substr($temp, 23, 4)));
|
|
|
121 |
$this->mbinfo->setMbTemp($dev);
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* get the information
|
|
|
130 |
*
|
|
|
131 |
* @see PSI_Interface_Sensor::build()
|
|
|
132 |
*
|
|
|
133 |
* @return Void
|
|
|
134 |
*/
|
|
|
135 |
public function build()
|
|
|
136 |
{
|
|
|
137 |
$this->_temperature();
|
|
|
138 |
}
|
|
|
139 |
}
|