Subversion Repositories ALCASAR

Rev

Rev 2770 | 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
 * 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
        $lines = "";
31
            $lines = "";
31
//        CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
32
//            CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
32
        CommonFunctions::executeProgram('sysctl', 'hw.sensors', $lines);
33
            CommonFunctions::executeProgram('sysctl', 'hw.sensors', $lines);
33
        $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
34
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
-
 
35
        }
34
    }
36
    }
35
 
37
 
36
    /**
38
    /**
37
     * get temperature information
39
     * get temperature information
38
     *
40
     *
39
     * @return void
41
     * @return void
40
     */
42
     */
41
    private function _temperature()
43
    private function _temperature()
42
    {
44
    {
43
        foreach ($this->_lines as $line) {
45
        foreach ($this->_lines as $line) {
44
            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)) {
45
                $dev = new SensorDevice();
47
                $dev = new SensorDevice();
46
                $dev->setName($ar_buf[1]);
48
                $dev->setName($ar_buf[1]);
47
                $dev->setValue($ar_buf[2]);
49
                $dev->setValue($ar_buf[2]);
48
                $this->mbinfo->setMbTemp($dev);
50
                $this->mbinfo->setMbTemp($dev);
49
            } 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)) {
50
                $dev = new SensorDevice();
52
                $dev = new SensorDevice();
51
                $dev->setName($ar_buf[1]);
53
                $dev->setName($ar_buf[1]);
52
                $dev->setValue($ar_buf[2]);
54
                $dev->setValue($ar_buf[2]);
53
                $this->mbinfo->setMbTemp($dev);
55
                $this->mbinfo->setMbTemp($dev);
54
            } 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)) {
55
                $dev = new SensorDevice();
57
                $dev = new SensorDevice();
56
                $dev->setName($ar_buf[3]);
58
                $dev->setName($ar_buf[3]);
57
                $dev->setValue($ar_buf[2]);
59
                $dev->setValue($ar_buf[2]);
58
                $this->mbinfo->setMbTemp($dev);
60
                $this->mbinfo->setMbTemp($dev);
59
            } 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)) {
60
                $dev = new SensorDevice();
62
                $dev = new SensorDevice();
61
                $dev->setName($ar_buf[1]);
63
                $dev->setName($ar_buf[1]);
62
                $dev->setValue($ar_buf[2]);
64
                $dev->setValue($ar_buf[2]);
63
                $this->mbinfo->setMbTemp($dev);
65
                $this->mbinfo->setMbTemp($dev);
64
            }
66
            }
65
        }
67
        }
66
    }
68
    }
67
 
69
 
68
    /**
70
    /**
69
     * get fan information
71
     * get fan information
70
     *
72
     *
71
     * @return void
73
     * @return void
72
     */
74
     */
73
    private function _fans()
75
    private function _fans()
74
    {
76
    {
75
        foreach ($this->_lines as $line) {
77
        foreach ($this->_lines as $line) {
76
            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)) {
77
                $dev = new SensorDevice();
79
                $dev = new SensorDevice();
78
                $dev->setName($ar_buf[1]);
80
                $dev->setName($ar_buf[1]);
79
                $dev->setValue($ar_buf[2]);
81
                $dev->setValue($ar_buf[2]);
80
                $this->mbinfo->setMbFan($dev);
82
                $this->mbinfo->setMbFan($dev);
81
            } 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)) {
82
                $dev = new SensorDevice();
84
                $dev = new SensorDevice();
83
                $dev->setName($ar_buf[1]);
85
                $dev->setName($ar_buf[1]);
84
                $dev->setValue($ar_buf[2]);
86
                $dev->setValue($ar_buf[2]);
85
                $this->mbinfo->setMbFan($dev);
87
                $this->mbinfo->setMbFan($dev);
86
            } 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)) {
87
                $dev = new SensorDevice();
89
                $dev = new SensorDevice();
88
                $dev->setName($ar_buf[3]);
90
                $dev->setName($ar_buf[3]);
89
                $dev->setValue($ar_buf[2]);
91
                $dev->setValue($ar_buf[2]);
90
                $this->mbinfo->setMbFan($dev);
92
                $this->mbinfo->setMbFan($dev);
91
            } 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)) {
92
                $dev = new SensorDevice();
94
                $dev = new SensorDevice();
93
                $dev->setName($ar_buf[1]);
95
                $dev->setName($ar_buf[1]);
94
                $dev->setValue($ar_buf[2]);
96
                $dev->setValue($ar_buf[2]);
95
                $this->mbinfo->setMbFan($dev);
97
                $this->mbinfo->setMbFan($dev);
96
            }
98
            }
97
        }
99
        }
98
    }
100
    }
99
 
101
 
100
    /**
102
    /**
101
     * get voltage information
103
     * get voltage information
102
     *
104
     *
103
     * @return void
105
     * @return void
104
     */
106
     */
105
    private function _voltage()
107
    private function _voltage()
106
    {
108
    {
107
        foreach ($this->_lines as $line) {
109
        foreach ($this->_lines as $line) {
108
            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)) {
109
                $dev = new SensorDevice();
111
                $dev = new SensorDevice();
110
                $dev->setName($ar_buf[1]);
112
                $dev->setName($ar_buf[1]);
111
                $dev->setValue($ar_buf[2]);
113
                $dev->setValue($ar_buf[2]);
112
                $this->mbinfo->setMbVolt($dev);
114
                $this->mbinfo->setMbVolt($dev);
113
            } 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)) {
114
                $dev = new SensorDevice();
116
                $dev = new SensorDevice();
115
                $dev->setName($ar_buf[1]);
117
                $dev->setName($ar_buf[1]);
116
                $dev->setValue($ar_buf[2]);
118
                $dev->setValue($ar_buf[2]);
117
                $this->mbinfo->setMbVolt($dev);
119
                $this->mbinfo->setMbVolt($dev);
118
            } 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)) {
119
                $dev = new SensorDevice();
121
                $dev = new SensorDevice();
120
                $dev->setName($ar_buf[3]);
122
                $dev->setName($ar_buf[3]);
121
                $dev->setValue($ar_buf[2]);
123
                $dev->setValue($ar_buf[2]);
122
                $this->mbinfo->setMbVolt($dev);
124
                $this->mbinfo->setMbVolt($dev);
123
            } 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)) {
124
                $dev = new SensorDevice();
126
                $dev = new SensorDevice();
125
                $dev->setName($ar_buf[1]);
127
                $dev->setName($ar_buf[1]);
126
                $dev->setValue($ar_buf[2]);
128
                $dev->setValue($ar_buf[2]);
127
                $this->mbinfo->setMbVolt($dev);
129
                $this->mbinfo->setMbVolt($dev);
128
            }
130
            }
129
        }
131
        }
130
    }
132
    }
131
 
133
 
132
    /**
134
    /**
133
     * get the information
135
     * get the information
134
     *
136
     *
135
     * @see PSI_Interface_Sensor::build()
137
     * @see PSI_Interface_Sensor::build()
136
     *
138
     *
137
     * @return Void
139
     * @return Void
138
     */
140
     */
139
    public function build()
141
    public function build()
140
    {
142
    {
141
        $this->_temperature();
143
        $this->_temperature();
142
        $this->_voltage();
144
        $this->_voltage();
143
        $this->_fans();
145
        $this->_fans();
144
    }
146
    }
145
}
147
}
146
 
148