|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Thermal Zone sensor class |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI_Sensor |
|
9
|
|
|
* @author Michael Cramer <[email protected]> |
|
10
|
|
|
* @copyright 2009 phpSysInfo |
|
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
12
|
|
|
* @version SVN: $Id: class.ohm.inc.php 661 2012-08-27 11:26:39Z namiltd $ |
|
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* getting information from Thermal Zone WMI class |
|
17
|
|
|
* |
|
18
|
|
|
* @category PHP |
|
19
|
|
|
* @package PSI_Sensor |
|
20
|
|
|
* @author Michael Cramer <[email protected]> |
|
21
|
|
|
* @copyright 2009 phpSysInfo |
|
22
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
23
|
|
|
* @version Release: 3.0 |
|
24
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
25
|
|
|
*/ |
|
26
|
|
|
class ThermalZone extends Sensors |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* holds the COM object that we pull all the WMI data from |
|
30
|
|
|
* |
|
31
|
|
|
* @var Object |
|
32
|
|
|
*/ |
|
33
|
|
|
private $_buf = array(); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* fill the private content var |
|
37
|
|
|
*/ |
|
38
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct(); |
|
41
|
|
|
if (PSI_OS == 'WINNT') { |
|
42
|
|
|
$_wmi = null; |
|
43
|
|
|
// don't set this params for local connection, it will not work |
|
44
|
|
|
$strHostname = ''; |
|
45
|
|
|
$strUser = ''; |
|
46
|
|
|
$strPassword = ''; |
|
47
|
|
|
try { |
|
48
|
|
|
// initialize the wmi object |
|
49
|
|
|
$objLocator = new COM('WbemScripting.SWbemLocator'); |
|
|
|
|
|
|
50
|
|
|
if ($strHostname == "") { |
|
51
|
|
|
$_wmi = $objLocator->ConnectServer($strHostname, 'root\WMI'); |
|
52
|
|
|
|
|
53
|
|
|
} else { |
|
54
|
|
|
$_wmi = $objLocator->ConnectServer($strHostname, 'root\WMI', $strHostname.'\\'.$strUser, $strPassword); |
|
55
|
|
|
} |
|
56
|
|
|
} catch (Exception $e) { |
|
57
|
|
|
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data."); |
|
58
|
|
|
} |
|
59
|
|
|
if ($_wmi) { |
|
60
|
|
|
$this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature')); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* get temperature information |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
private function _temperature() |
|
71
|
|
|
{ |
|
72
|
|
|
if (PSI_OS == 'WINNT') { |
|
73
|
|
|
if ($this->_buf) foreach ($this->_buf as $buffer) { |
|
74
|
|
|
if (isset($buffer['CurrentTemperature']) && (($value = ($buffer['CurrentTemperature'] - 2732)/10) > -100)) { |
|
75
|
|
|
$dev = new SensorDevice(); |
|
76
|
|
|
if (isset($buffer['InstanceName']) && preg_match("/([^\\\\ ]+)$/", $buffer['InstanceName'], $outbuf)) { |
|
77
|
|
|
$dev->setName('ThermalZone '.$outbuf[1]); |
|
78
|
|
|
} else { |
|
79
|
|
|
$dev->setName('ThermalZone THM0_0'); |
|
80
|
|
|
} |
|
81
|
|
|
$dev->setValue($value); |
|
82
|
|
|
if (isset($buffer['CriticalTripPoint']) && (($maxvalue = ($buffer['CriticalTripPoint'] - 2732)/10) > 0)) { |
|
83
|
|
|
$dev->setMax($maxvalue); |
|
84
|
|
|
} |
|
85
|
|
|
$this->mbinfo->setMbTemp($dev); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} else { |
|
89
|
|
|
$notwas = true; |
|
90
|
|
|
foreach (glob('/sys/class/thermal/thermal_zone*/') as $thermalzone) { |
|
91
|
|
|
$thermalzonetemp = $thermalzone.'temp'; |
|
92
|
|
|
$temp = null; |
|
93
|
|
|
if (CommonFunctions::rfts($thermalzonetemp, $temp, 0, 4096, false) && !is_null($temp) && (trim($temp) != "")) { |
|
94
|
|
|
if ($temp >= 1000) { |
|
95
|
|
|
$temp = $temp / 1000; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if ($temp > -40) { |
|
99
|
|
|
$dev = new SensorDevice(); |
|
100
|
|
|
$dev->setValue($temp); |
|
101
|
|
|
|
|
102
|
|
|
$temp_type = null; |
|
103
|
|
|
if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 0, 4096, false) && !is_null($temp_type) && (trim($temp_type) != "")) { |
|
104
|
|
|
$dev->setName($temp_type); |
|
105
|
|
|
} else { |
|
106
|
|
|
$dev->setName("ThermalZone"); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$temp_max = null; |
|
110
|
|
|
if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 0, 4096, false) && !is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) { |
|
111
|
|
|
if ($temp_max >= 1000) { |
|
112
|
|
|
$temp_max = $temp_max / 1000; |
|
113
|
|
|
} |
|
114
|
|
|
$dev->setMax($temp_max); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$notwas = false; |
|
118
|
|
|
$this->mbinfo->setMbTemp($dev); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
if ($notwas) { |
|
123
|
|
|
foreach (glob('/proc/acpi/thermal_zone/TH*/temperature') as $thermalzone) { |
|
124
|
|
|
$temp = null; |
|
125
|
|
|
if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && !is_null($temp) && (trim($temp) != "")) { |
|
126
|
|
|
$dev = new SensorDevice(); |
|
127
|
|
|
if (preg_match("/^\/proc\/acpi\/thermal_zone\/(.+)\/temperature$/", $thermalzone, $name)) { |
|
128
|
|
|
$dev->setName("ThermalZone ".$name[1]); |
|
129
|
|
|
} else { |
|
130
|
|
|
$dev->setName("ThermalZone"); |
|
131
|
|
|
} |
|
132
|
|
|
$dev->setValue(trim(substr($temp, 23, 4))); |
|
133
|
|
|
$this->mbinfo->setMbTemp($dev); |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* get the information |
|
142
|
|
|
* |
|
143
|
|
|
* @see PSI_Interface_Sensor::build() |
|
144
|
|
|
* |
|
145
|
|
|
* @return Void |
|
146
|
|
|
*/ |
|
147
|
|
|
public function build() |
|
148
|
|
|
{ |
|
149
|
|
|
$this->_temperature(); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.