Subversion Repositories ALCASAR

Rev

Rev 2770 | Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 2976
1
<?php
1
<?php
2
/**
2
/**
3
 * Open Hardware Monitor sensor class, getting information from Open Hardware Monitor
3
 * Open Hardware Monitor sensor class, getting information from Open Hardware Monitor
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI_Sensor
8
 * @package   PSI_Sensor
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2014 phpSysInfo
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
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
12
 * @version   Release: 3.0
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
class OHM extends Sensors
15
class OHM extends Sensors
16
{
16
{
17
/**
17
/**
18
     * holds the COM object that we pull all the WMI data from
18
     * holds the COM object that we pull all the WMI data from
19
     *
19
     *
20
     * @var Object
20
     * @var Object
21
     */
21
     */
22
    private $_buf = array();
22
    private $_buf = array();
23
 
23
 
24
    /**
24
    /**
25
     * fill the private content var
25
     * fill the private content var
26
     */
26
     */
27
    public function __construct()
27
    public function __construct()
28
    {
28
    {
29
        parent::__construct();
29
        parent::__construct();
30
        $_wmi = null;
-
 
31
        try {
-
 
32
            // initialize the wmi object
-
 
33
            $objLocator = new COM('WbemScripting.SWbemLocator');
30
        if ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')) {
34
            $_wmi = $objLocator->ConnectServer('', 'root\OpenHardwareMonitor');
31
            $_wmi = CommonFunctions::initWMI('root\OpenHardwareMonitor', true);
35
        } catch (Exception $e) {
-
 
36
            $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data.");
-
 
37
        }
-
 
38
        if ($_wmi) {
32
            if ($_wmi) {
39
            $tmpbuf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
33
                $tmpbuf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
40
            if ($tmpbuf) foreach ($tmpbuf as $buffer) {
34
                if ($tmpbuf) foreach ($tmpbuf as $buffer) {
41
                if (!isset($this->_buf[$buffer['SensorType']]) || !isset($this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']])) { // avoid duplicates
35
                    if (!isset($this->_buf[$buffer['SensorType']]) || !isset($this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']])) { // avoid duplicates
42
                    $this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']] = $buffer['Value'];
36
                        $this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']] = $buffer['Value'];
-
 
37
                    }
43
                }
38
                }
44
            }
39
            }
45
        }
40
        }
46
    }
41
    }
47
 
42
 
48
    /**
43
    /**
49
     * get temperature information
44
     * get temperature information
50
     *
45
     *
51
     * @return void
46
     * @return void
52
     */
47
     */
53
    private function _temperature()
48
    private function _temperature()
54
    {
49
    {
55
        if (isset($this->_buf['Temperature'])) foreach ($this->_buf['Temperature'] as $name=>$value) {
50
        if (isset($this->_buf['Temperature'])) foreach ($this->_buf['Temperature'] as $name=>$value) {
56
            $dev = new SensorDevice();
51
            $dev = new SensorDevice();
57
            $dev->setName($name);
52
            $dev->setName($name);
58
            $dev->setValue($value);
53
            $dev->setValue($value);
59
            $this->mbinfo->setMbTemp($dev);
54
            $this->mbinfo->setMbTemp($dev);
60
        }
55
        }
61
    }
56
    }
62
 
57
 
63
    /**
58
    /**
64
     * get voltage information
59
     * get voltage information
65
     *
60
     *
66
     * @return void
61
     * @return void
67
     */
62
     */
68
    private function _voltage()
63
    private function _voltage()
69
    {
64
    {
70
        if (isset($this->_buf['Voltage'])) foreach ($this->_buf['Voltage'] as $name=>$value) {
65
        if (isset($this->_buf['Voltage'])) foreach ($this->_buf['Voltage'] as $name=>$value) {
71
            $dev = new SensorDevice();
66
            $dev = new SensorDevice();
72
            $dev->setName($name);
67
            $dev->setName($name);
73
            $dev->setValue($value);
68
            $dev->setValue($value);
74
            $this->mbinfo->setMbVolt($dev);
69
            $this->mbinfo->setMbVolt($dev);
75
        }
70
        }
76
    }
71
    }
77
 
72
 
78
    /**
73
    /**
79
     * get fan information
74
     * get fan information
80
     *
75
     *
81
     * @return void
76
     * @return void
82
     */
77
     */
83
    private function _fans()
78
    private function _fans()
84
    {
79
    {
85
        if (isset($this->_buf['Fan'])) foreach ($this->_buf['Fan'] as $name=>$value) {
80
        if (isset($this->_buf['Fan'])) foreach ($this->_buf['Fan'] as $name=>$value) {
86
            $dev = new SensorDevice();
81
            $dev = new SensorDevice();
87
            $dev->setName($name);
82
            $dev->setName($name);
88
            $dev->setValue($value);
83
            $dev->setValue($value);
89
            $this->mbinfo->setMbFan($dev);
84
            $this->mbinfo->setMbFan($dev);
90
        }
85
        }
91
    }
86
    }
92
 
87
 
93
    /**
88
    /**
94
     * get power information
89
     * get power information
95
     *
90
     *
96
     * @return void
91
     * @return void
97
     */
92
     */
98
    private function _power()
93
    private function _power()
99
    {
94
    {
100
        if (isset($this->_buf['Power'])) foreach ($this->_buf['Power'] as $name=>$value) {
95
        if (isset($this->_buf['Power'])) foreach ($this->_buf['Power'] as $name=>$value) {
101
            $dev = new SensorDevice();
96
            $dev = new SensorDevice();
102
            $dev->setName($name);
97
            $dev->setName($name);
103
            $dev->setValue($value);
98
            $dev->setValue($value);
104
            $this->mbinfo->setMbPower($dev);
99
            $this->mbinfo->setMbPower($dev);
105
        }
100
        }
106
    }
101
    }
107
 
102
 
108
    /**
103
    /**
109
     * get the information
104
     * get the information
110
     *
105
     *
111
     * @see PSI_Interface_Sensor::build()
106
     * @see PSI_Interface_Sensor::build()
112
     *
107
     *
113
     * @return Void
108
     * @return Void
114
     */
109
     */
115
    public function build()
110
    public function build()
116
    {
111
    {
117
      $this->_temperature();
112
      $this->_temperature();
118
      $this->_voltage();
113
      $this->_voltage();
119
      $this->_fans();
114
      $this->_fans();
120
      $this->_power();
115
      $this->_power();
121
    }
116
    }
122
}
117
}
123
 
118