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
 * speedfan sensor class, getting hardware information through SpeedFanGet
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Sensor
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2016 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 SpeedFan extends Sensors
16
{
17
    /*
18
     * variable, which holds the content of the command
19
     * @var array
20
     */
21
    private $_filecontent = array();
22
 
23
    public function __construct()
24
    {
25
        parent::__construct();
2976 rexy 26
        if ((PSI_OS == 'WINNT') && !defined('PSI_EMU_HOSTNAME')) switch (defined('PSI_SENSOR_SPEEDFAN_ACCESS')?strtolower(PSI_SENSOR_SPEEDFAN_ACCESS):'command') {
2770 rexy 27
        case 'command':
28
            if (CommonFunctions::executeProgram("SpeedFanGet.exe", "", $buffer, PSI_DEBUG) && (strlen($buffer) > 0)) {
29
                if (preg_match("/^Temperatures:\s+(.+)$/m", $buffer, $out)) {
30
                    $this->_filecontent["temp"] = $out[1];
31
                }
32
                if (preg_match("/^Fans:\s+(.+)$/m", $buffer, $out)) {
33
                    $this->_filecontent["fans"] = $out[1];
34
                }
35
                if (preg_match("/^Voltages:\s+(.+)$/m", $buffer, $out)) {
36
                    $this->_filecontent["volt"] = $out[1];
37
                }
38
            }
39
            break;
40
        case 'data':
3037 rexy 41
            if (CommonFunctions::rftsdata('speedfan.tmp', $buffer) && (strlen($buffer) > 0)) {
2770 rexy 42
                if (preg_match("/^Temperatures:\s+(.+)$/m", $buffer, $out)) {
43
                    $this->_filecontent["temp"] = $out[1];
44
                }
45
                if (preg_match("/^Fans:\s+(.+)$/m", $buffer, $out)) {
46
                    $this->_filecontent["fans"] = $out[1];
47
                }
48
                if (preg_match("/^Voltages:\s+(.+)$/m", $buffer, $out)) {
49
                    $this->_filecontent["volt"] = $out[1];
50
                }
51
            }
52
            break;
53
        default:
54
            $this->error->addConfigError('__construct()', '[sensor_speedfan] ACCESS');
55
        }
56
    }
57
 
58
    /**
59
     * get temperature information
60
     *
61
     * @return void
62
     */
63
    private function _temperature()
64
    {
65
        if (isset($this->_filecontent["temp"]) && (trim($this->_filecontent["temp"]) !== "")) {
66
            $values = preg_split("/ /", trim($this->_filecontent["temp"]));
67
            foreach ($values as $id=>$value) {
68
                $dev = new SensorDevice();
69
                $dev->setName("temp".$id);
70
                $dev->setValue($value);
71
                $this->mbinfo->setMbTemp($dev);
72
            }
73
        }
74
    }
75
 
76
    /**
77
     * get fan information
78
     *
79
     * @return void
80
     */
81
    private function _fans()
82
    {
83
        if (isset($this->_filecontent["fans"]) && (trim($this->_filecontent["fans"]) !== "")) {
84
            $values = preg_split("/ /", trim($this->_filecontent["fans"]));
85
            foreach ($values as $id=>$value) {
86
                $dev = new SensorDevice();
87
                $dev->setName("fan".$id);
88
                $dev->setValue($value);
89
                $this->mbinfo->setMbFan($dev);
90
            }
91
        }
92
    }
93
 
94
    /**
95
     * get voltage information
96
     *
97
     * @return void
98
     */
99
    private function _voltage()
100
    {
101
        if (isset($this->_filecontent["volt"]) && (trim($this->_filecontent["volt"]) !== "")) {
102
            $values = preg_split("/ /", trim($this->_filecontent["volt"]));
103
            foreach ($values as $id=>$value) {
104
                $dev = new SensorDevice();
105
                $dev->setName("in".$id);
106
                $dev->setValue($value);
107
                $this->mbinfo->setMbVolt($dev);
108
            }
109
        }
110
    }
111
 
112
    /**
113
     * get the information
114
     *
115
     * @see PSI_Interface_Sensor::build()
116
     *
3037 rexy 117
     * @return void
2770 rexy 118
     */
119
    public function build()
120
    {
121
        $this->_temperature();
122
        $this->_fans();
123
        $this->_voltage();
124
    }
125
}