Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Details | 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();
30
        $_wmi = null;
31
        try {
32
            // initialize the wmi object
33
            $objLocator = new COM('WbemScripting.SWbemLocator');
34
            $_wmi = $objLocator->ConnectServer('', 'root\OpenHardwareMonitor');
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) {
39
            $tmpbuf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
40
            if ($tmpbuf) foreach ($tmpbuf as $buffer) {
41
                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'];
43
                }
44
            }
45
        }
46
    }
47
 
48
    /**
49
     * get temperature information
50
     *
51
     * @return void
52
     */
53
    private function _temperature()
54
    {
55
        if (isset($this->_buf['Temperature'])) foreach ($this->_buf['Temperature'] as $name=>$value) {
56
            $dev = new SensorDevice();
57
            $dev->setName($name);
58
            $dev->setValue($value);
59
            $this->mbinfo->setMbTemp($dev);
60
        }
61
    }
62
 
63
    /**
64
     * get voltage information
65
     *
66
     * @return void
67
     */
68
    private function _voltage()
69
    {
70
        if (isset($this->_buf['Voltage'])) foreach ($this->_buf['Voltage'] as $name=>$value) {
71
            $dev = new SensorDevice();
72
            $dev->setName($name);
73
            $dev->setValue($value);
74
            $this->mbinfo->setMbVolt($dev);
75
        }
76
    }
77
 
78
    /**
79
     * get fan information
80
     *
81
     * @return void
82
     */
83
    private function _fans()
84
    {
85
        if (isset($this->_buf['Fan'])) foreach ($this->_buf['Fan'] as $name=>$value) {
86
            $dev = new SensorDevice();
87
            $dev->setName($name);
88
            $dev->setValue($value);
89
            $this->mbinfo->setMbFan($dev);
90
        }
91
    }
92
 
93
    /**
94
     * get power information
95
     *
96
     * @return void
97
     */
98
    private function _power()
99
    {
100
        if (isset($this->_buf['Power'])) foreach ($this->_buf['Power'] as $name=>$value) {
101
            $dev = new SensorDevice();
102
            $dev->setName($name);
103
            $dev->setValue($value);
104
            $this->mbinfo->setMbPower($dev);
105
        }
106
    }
107
 
108
    /**
109
     * get the information
110
     *
111
     * @see PSI_Interface_Sensor::build()
112
     *
113
     * @return Void
114
     */
115
    public function build()
116
    {
117
      $this->_temperature();
118
      $this->_voltage();
119
      $this->_fans();
120
      $this->_power();
121
    }
122
}