Subversion Repositories ALCASAR

Rev

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