Subversion Repositories ALCASAR

Rev

Rev 3037 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * Open Hardware Monitor sensor class, getting information from Open Hardware Monitor
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 OHM 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();
3100 rexy 30
        if ((PSI_OS == 'WINNT') || (defined('PSI_EMU_HOSTNAME')  && !defined('PSI_EMU_PORT'))) {
3037 rexy 31
            $_wmi = WINNT::initWMI('root\OpenHardwareMonitor', true);
2976 rexy 32
            if ($_wmi) {
3037 rexy 33
                $tmpbuf = WINNT::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
2976 rexy 34
                if ($tmpbuf) foreach ($tmpbuf as $buffer) {
35
                    if (!isset($this->_buf[$buffer['SensorType']]) || !isset($this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']])) { // avoid duplicates
36
                        $this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']] = $buffer['Value'];
37
                    }
2770 rexy 38
                }
39
            }
40
        }
41
    }
42
 
43
    /**
44
     * get temperature information
45
     *
46
     * @return void
47
     */
48
    private function _temperature()
49
    {
50
        if (isset($this->_buf['Temperature'])) foreach ($this->_buf['Temperature'] as $name=>$value) {
51
            $dev = new SensorDevice();
52
            $dev->setName($name);
53
            $dev->setValue($value);
54
            $this->mbinfo->setMbTemp($dev);
55
        }
56
    }
57
 
58
    /**
59
     * get voltage information
60
     *
61
     * @return void
62
     */
63
    private function _voltage()
64
    {
65
        if (isset($this->_buf['Voltage'])) foreach ($this->_buf['Voltage'] as $name=>$value) {
66
            $dev = new SensorDevice();
67
            $dev->setName($name);
68
            $dev->setValue($value);
69
            $this->mbinfo->setMbVolt($dev);
70
        }
71
    }
72
 
73
    /**
74
     * get fan information
75
     *
76
     * @return void
77
     */
78
    private function _fans()
79
    {
80
        if (isset($this->_buf['Fan'])) foreach ($this->_buf['Fan'] as $name=>$value) {
81
            $dev = new SensorDevice();
82
            $dev->setName($name);
83
            $dev->setValue($value);
84
            $this->mbinfo->setMbFan($dev);
85
        }
86
    }
87
 
88
    /**
89
     * get power information
90
     *
91
     * @return void
92
     */
93
    private function _power()
94
    {
95
        if (isset($this->_buf['Power'])) foreach ($this->_buf['Power'] as $name=>$value) {
96
            $dev = new SensorDevice();
97
            $dev->setName($name);
98
            $dev->setValue($value);
99
            $this->mbinfo->setMbPower($dev);
100
        }
101
    }
102
 
103
    /**
104
     * get the information
105
     *
106
     * @see PSI_Interface_Sensor::build()
107
     *
3037 rexy 108
     * @return void
2770 rexy 109
     */
110
    public function build()
111
    {
112
      $this->_temperature();
113
      $this->_voltage();
114
      $this->_fans();
115
      $this->_power();
116
    }
117
}