Subversion Repositories ALCASAR

Rev

Rev 2770 | Go to most recent revision | 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':
41
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/speedfan.txt', $buffer) && (strlen($buffer) > 0)) {
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
            break;
56
        }
57
    }
58
 
59
    /**
60
     * get temperature information
61
     *
62
     * @return void
63
     */
64
    private function _temperature()
65
    {
66
        if (isset($this->_filecontent["temp"]) && (trim($this->_filecontent["temp"]) !== "")) {
67
            $values = preg_split("/ /", trim($this->_filecontent["temp"]));
68
            foreach ($values as $id=>$value) {
69
                $dev = new SensorDevice();
70
                $dev->setName("temp".$id);
71
                $dev->setValue($value);
72
                $this->mbinfo->setMbTemp($dev);
73
            }
74
        }
75
    }
76
 
77
    /**
78
     * get fan information
79
     *
80
     * @return void
81
     */
82
    private function _fans()
83
    {
84
        if (isset($this->_filecontent["fans"]) && (trim($this->_filecontent["fans"]) !== "")) {
85
            $values = preg_split("/ /", trim($this->_filecontent["fans"]));
86
            foreach ($values as $id=>$value) {
87
                $dev = new SensorDevice();
88
                $dev->setName("fan".$id);
89
                $dev->setValue($value);
90
                $this->mbinfo->setMbFan($dev);
91
            }
92
        }
93
    }
94
 
95
    /**
96
     * get voltage information
97
     *
98
     * @return void
99
     */
100
    private function _voltage()
101
    {
102
        if (isset($this->_filecontent["volt"]) && (trim($this->_filecontent["volt"]) !== "")) {
103
            $values = preg_split("/ /", trim($this->_filecontent["volt"]));
104
            foreach ($values as $id=>$value) {
105
                $dev = new SensorDevice();
106
                $dev->setName("in".$id);
107
                $dev->setValue($value);
108
                $this->mbinfo->setMbVolt($dev);
109
            }
110
        }
111
    }
112
 
113
    /**
114
     * get the information
115
     *
116
     * @see PSI_Interface_Sensor::build()
117
     *
118
     * @return Void
119
     */
120
    public function build()
121
    {
122
        $this->_temperature();
123
        $this->_fans();
124
        $this->_voltage();
125
    }
126
}