Subversion Repositories ALCASAR

Rev

Rev 2976 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2976 Rev 3037
1
<?php
1
<?php
2
/**
2
/**
3
 * hwsensors sensor class, getting information from hwsensors
3
 * hwsensors sensor class, getting information from hwsensors
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    Michael Cramer <BigMichi1@users.sourceforge.net>
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
10
 * @copyright 2009 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 HWSensors extends Sensors
15
class HWSensors extends Sensors
16
{
16
{
17
    /**
17
    /**
18
     * content to parse
18
     * content to parse
19
     *
19
     *
20
     * @var array
20
     * @var array
21
     */
21
     */
22
    private $_lines = array();
22
    private $_lines = array();
23
 
23
 
24
    /**
24
    /**
25
     * fill the private content var through command
25
     * fill the private content var through command
26
     */
26
     */
27
    public function __construct()
27
    public function __construct()
28
    {
28
    {
29
        parent::__construct();
29
        parent::__construct();
30
        if (PSI_OS == 'OpenBSD') {
30
        if (PSI_OS == 'OpenBSD') {
31
            $lines = "";
31
            $lines = "";
32
//            CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
32
//            CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
33
            CommonFunctions::executeProgram('sysctl', 'hw.sensors', $lines);
33
            CommonFunctions::executeProgram('sysctl', 'hw.sensors', $lines);
34
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
34
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
35
        }
35
        }
36
    }
36
    }
37
 
37
 
38
    /**
38
    /**
39
     * get temperature information
39
     * get temperature information
40
     *
40
     *
41
     * @return void
41
     * @return void
42
     */
42
     */
43
    private function _temperature()
43
    private function _temperature()
44
    {
44
    {
45
        foreach ($this->_lines as $line) {
45
        foreach ($this->_lines as $line) {
46
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+temp,\s+([0-9\.]+)\s+degC.*$/', $line, $ar_buf)) {
46
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+temp,\s+([0-9\.]+)\s+degC.*$/', $line, $ar_buf)) {
47
                $dev = new SensorDevice();
47
                $dev = new SensorDevice();
48
                $dev->setName($ar_buf[1]);
48
                $dev->setName($ar_buf[1]);
49
                $dev->setValue($ar_buf[2]);
49
                $dev->setValue($ar_buf[2]);
50
                $this->mbinfo->setMbTemp($dev);
50
                $this->mbinfo->setMbTemp($dev);
51
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
51
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
52
                $dev = new SensorDevice();
52
                $dev = new SensorDevice();
53
                $dev->setName($ar_buf[1]);
53
                $dev->setName($ar_buf[1]);
54
                $dev->setValue($ar_buf[2]);
54
                $dev->setValue($ar_buf[2]);
55
                $this->mbinfo->setMbTemp($dev);
55
                $this->mbinfo->setMbTemp($dev);
56
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC\s+\((.*)\)$/', $line, $ar_buf)) {
56
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC\s+\((.*)\)$/', $line, $ar_buf)) {
57
                $dev = new SensorDevice();
57
                $dev = new SensorDevice();
58
                $dev->setName($ar_buf[3]);
58
                $dev->setName($ar_buf[3]);
59
                $dev->setValue($ar_buf[2]);
59
                $dev->setValue($ar_buf[2]);
60
                $this->mbinfo->setMbTemp($dev);
60
                $this->mbinfo->setMbTemp($dev);
61
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
61
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
62
                $dev = new SensorDevice();
62
                $dev = new SensorDevice();
63
                $dev->setName($ar_buf[1]);
63
                $dev->setName($ar_buf[1]);
64
                $dev->setValue($ar_buf[2]);
64
                $dev->setValue($ar_buf[2]);
65
                $this->mbinfo->setMbTemp($dev);
65
                $this->mbinfo->setMbTemp($dev);
66
            }
66
            }
67
        }
67
        }
68
    }
68
    }
69
 
69
 
70
    /**
70
    /**
71
     * get fan information
71
     * get fan information
72
     *
72
     *
73
     * @return void
73
     * @return void
74
     */
74
     */
75
    private function _fans()
75
    private function _fans()
76
    {
76
    {
77
        foreach ($this->_lines as $line) {
77
        foreach ($this->_lines as $line) {
78
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+fanrpm,\s+([0-9\.]+)\s+RPM.*$/', $line, $ar_buf)) {
78
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+fanrpm,\s+([0-9\.]+)\s+RPM.*$/', $line, $ar_buf)) {
79
                $dev = new SensorDevice();
79
                $dev = new SensorDevice();
80
                $dev->setName($ar_buf[1]);
80
                $dev->setName($ar_buf[1]);
81
                $dev->setValue($ar_buf[2]);
81
                $dev->setValue($ar_buf[2]);
82
                $this->mbinfo->setMbFan($dev);
82
                $this->mbinfo->setMbFan($dev);
83
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
83
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
84
                $dev = new SensorDevice();
84
                $dev = new SensorDevice();
85
                $dev->setName($ar_buf[1]);
85
                $dev->setName($ar_buf[1]);
86
                $dev->setValue($ar_buf[2]);
86
                $dev->setValue($ar_buf[2]);
87
                $this->mbinfo->setMbFan($dev);
87
                $this->mbinfo->setMbFan($dev);
88
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM\s+\((.*)\)$/', $line, $ar_buf)) {
88
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM\s+\((.*)\)$/', $line, $ar_buf)) {
89
                $dev = new SensorDevice();
89
                $dev = new SensorDevice();
90
                $dev->setName($ar_buf[3]);
90
                $dev->setName($ar_buf[3]);
91
                $dev->setValue($ar_buf[2]);
91
                $dev->setValue($ar_buf[2]);
92
                $this->mbinfo->setMbFan($dev);
92
                $this->mbinfo->setMbFan($dev);
93
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
93
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
94
                $dev = new SensorDevice();
94
                $dev = new SensorDevice();
95
                $dev->setName($ar_buf[1]);
95
                $dev->setName($ar_buf[1]);
96
                $dev->setValue($ar_buf[2]);
96
                $dev->setValue($ar_buf[2]);
97
                $this->mbinfo->setMbFan($dev);
97
                $this->mbinfo->setMbFan($dev);
98
            }
98
            }
99
        }
99
        }
100
    }
100
    }
101
 
101
 
102
    /**
102
    /**
103
     * get voltage information
103
     * get voltage information
104
     *
104
     *
105
     * @return void
105
     * @return void
106
     */
106
     */
107
    private function _voltage()
107
    private function _voltage()
108
    {
108
    {
109
        foreach ($this->_lines as $line) {
109
        foreach ($this->_lines as $line) {
110
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+volts_dc,\s+([0-9\.]+)\s+V.*$/', $line, $ar_buf)) {
110
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+volts_dc,\s+([0-9\.]+)\s+V.*$/', $line, $ar_buf)) {
111
                $dev = new SensorDevice();
111
                $dev = new SensorDevice();
112
                $dev->setName($ar_buf[1]);
112
                $dev->setName($ar_buf[1]);
113
                $dev->setValue($ar_buf[2]);
113
                $dev->setValue($ar_buf[2]);
114
                $this->mbinfo->setMbVolt($dev);
114
                $this->mbinfo->setMbVolt($dev);
115
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+V\sDC$/', $line, $ar_buf)) {
115
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+V\sDC$/', $line, $ar_buf)) {
116
                $dev = new SensorDevice();
116
                $dev = new SensorDevice();
117
                $dev->setName($ar_buf[1]);
117
                $dev->setName($ar_buf[1]);
118
                $dev->setValue($ar_buf[2]);
118
                $dev->setValue($ar_buf[2]);
119
                $this->mbinfo->setMbVolt($dev);
119
                $this->mbinfo->setMbVolt($dev);
120
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC\s+\((.*)\)$/', $line, $ar_buf)) {
120
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC\s+\((.*)\)$/', $line, $ar_buf)) {
121
                $dev = new SensorDevice();
121
                $dev = new SensorDevice();
122
                $dev->setName($ar_buf[3]);
122
                $dev->setName($ar_buf[3]);
123
                $dev->setValue($ar_buf[2]);
123
                $dev->setValue($ar_buf[2]);
124
                $this->mbinfo->setMbVolt($dev);
124
                $this->mbinfo->setMbVolt($dev);
125
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC$/', $line, $ar_buf)) {
125
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC$/', $line, $ar_buf)) {
126
                $dev = new SensorDevice();
126
                $dev = new SensorDevice();
127
                $dev->setName($ar_buf[1]);
127
                $dev->setName($ar_buf[1]);
128
                $dev->setValue($ar_buf[2]);
128
                $dev->setValue($ar_buf[2]);
129
                $this->mbinfo->setMbVolt($dev);
129
                $this->mbinfo->setMbVolt($dev);
130
            }
130
            }
131
        }
131
        }
132
    }
132
    }
133
 
133
 
134
    /**
134
    /**
135
     * get the information
135
     * get the information
136
     *
136
     *
137
     * @see PSI_Interface_Sensor::build()
137
     * @see PSI_Interface_Sensor::build()
138
     *
138
     *
139
     * @return Void
139
     * @return void
140
     */
140
     */
141
    public function build()
141
    public function build()
142
    {
142
    {
143
        $this->_temperature();
143
        $this->_temperature();
144
        $this->_voltage();
144
        $this->_voltage();
145
        $this->_fans();
145
        $this->_fans();
146
    }
146
    }
147
}
147
}
148
 
148