Subversion Repositories ALCASAR

Rev

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

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