Subversion Repositories ALCASAR

Rev

Rev 2770 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 2976
1
<?php
1
<?php
2
/**
2
/**
3
 * healthd sensor class, getting information from healthd
3
 * healthd sensor class, getting information from healthd
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 Healthd extends Sensors
15
class Healthd 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 $_values = array();
22
    private $_values = array();
23
 
23
 
24
    /**
24
    /**
25
     * fill the private content var through command or data access
25
     * fill the private content var through command or data access
26
     */
26
     */
27
    public function __construct()
27
    public function __construct()
28
    {
28
    {
29
        parent::__construct();
29
        parent::__construct();
30
        switch (defined('PSI_SENSOR_HEALTHD_ACCESS')?strtolower(PSI_SENSOR_HEALTHD_ACCESS):'command') {
30
        if (PSI_OS == 'FreeBSD') switch (defined('PSI_SENSOR_HEALTHD_ACCESS')?strtolower(PSI_SENSOR_HEALTHD_ACCESS):'command') {
31
        case 'command':
31
        case 'command':
32
            if (CommonFunctions::executeProgram('healthdc', '-t', $lines)) {
32
            if (CommonFunctions::executeProgram('healthdc', '-t', $lines)) {
33
                $lines0 = preg_split("/\n/", $lines, 1, PREG_SPLIT_NO_EMPTY);
33
                $lines0 = preg_split("/\n/", $lines, 1, PREG_SPLIT_NO_EMPTY);
34
                if (count($lines0) == 1) {
34
                if (count($lines0) == 1) {
35
                    $this->_values = preg_split("/\t+/", $lines0[0]);
35
                    $this->_values = preg_split("/\t+/", $lines0[0]);
36
                }
36
                }
37
            }
37
            }
38
            break;
38
            break;
39
        case 'data':
39
        case 'data':
40
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/healthd.txt', $lines)) {
40
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/healthd.txt', $lines)) {
41
                $lines0 = preg_split("/\n/", $lines, 1, PREG_SPLIT_NO_EMPTY);
41
                $lines0 = preg_split("/\n/", $lines, 1, PREG_SPLIT_NO_EMPTY);
42
                if (count($lines0) == 1) {
42
                if (count($lines0) == 1) {
43
                    $this->_values = preg_split("/\t+/", $lines0[0]);
43
                    $this->_values = preg_split("/\t+/", $lines0[0]);
44
                }
44
                }
45
            }
45
            }
46
            break;
46
            break;
47
        default:
47
        default:
48
            $this->error->addConfigError('__construct()', '[sensor_healthd] ACCESS');
48
            $this->error->addConfigError('__construct()', '[sensor_healthd] ACCESS');
49
            break;
49
            break;
50
        }
50
        }
51
    }
51
    }
52
 
52
 
53
    /**
53
    /**
54
     * get temperature information
54
     * get temperature information
55
     *
55
     *
56
     * @return void
56
     * @return void
57
     */
57
     */
58
    private function _temperature()
58
    private function _temperature()
59
    {
59
    {
60
        if (count($this->_values) == 14) {
60
        if (count($this->_values) == 14) {
61
            $dev1 = new SensorDevice();
61
            $dev1 = new SensorDevice();
62
            $dev1->setName('temp1');
62
            $dev1->setName('temp1');
63
            $dev1->setValue($this->_values[1]);
63
            $dev1->setValue($this->_values[1]);
64
//            $dev1->setMax(70);
64
//            $dev1->setMax(70);
65
            $this->mbinfo->setMbTemp($dev1);
65
            $this->mbinfo->setMbTemp($dev1);
66
            $dev2 = new SensorDevice();
66
            $dev2 = new SensorDevice();
67
            $dev2->setName('temp1');
67
            $dev2->setName('temp1');
68
            $dev2->setValue($this->_values[2]);
68
            $dev2->setValue($this->_values[2]);
69
//            $dev2->setMax(70);
69
//            $dev2->setMax(70);
70
            $this->mbinfo->setMbTemp($dev2);
70
            $this->mbinfo->setMbTemp($dev2);
71
            $dev3 = new SensorDevice();
71
            $dev3 = new SensorDevice();
72
            $dev3->setName('temp1');
72
            $dev3->setName('temp1');
73
            $dev3->setValue($this->_values[3]);
73
            $dev3->setValue($this->_values[3]);
74
//            $dev3->setMax(70);
74
//            $dev3->setMax(70);
75
            $this->mbinfo->setMbTemp($dev3);
75
            $this->mbinfo->setMbTemp($dev3);
76
        }
76
        }
77
    }
77
    }
78
 
78
 
79
    /**
79
    /**
80
     * get fan information
80
     * get fan information
81
     *
81
     *
82
     * @return void
82
     * @return void
83
     */
83
     */
84
    private function _fans()
84
    private function _fans()
85
    {
85
    {
86
        if (count($this->_values) == 14) {
86
        if (count($this->_values) == 14) {
87
            $dev1 = new SensorDevice();
87
            $dev1 = new SensorDevice();
88
            $dev1->setName('fan1');
88
            $dev1->setName('fan1');
89
            $dev1->setValue($this->_values[4]);
89
            $dev1->setValue($this->_values[4]);
90
//            $dev1->setMin(3000);
90
//            $dev1->setMin(3000);
91
            $this->mbinfo->setMbFan($dev1);
91
            $this->mbinfo->setMbFan($dev1);
92
            $dev2 = new SensorDevice();
92
            $dev2 = new SensorDevice();
93
            $dev2->setName('fan2');
93
            $dev2->setName('fan2');
94
            $dev2->setValue($this->_values[5]);
94
            $dev2->setValue($this->_values[5]);
95
//            $dev2->setMin(3000);
95
//            $dev2->setMin(3000);
96
            $this->mbinfo->setMbFan($dev2);
96
            $this->mbinfo->setMbFan($dev2);
97
            $dev3 = new SensorDevice();
97
            $dev3 = new SensorDevice();
98
            $dev3->setName('fan3');
98
            $dev3->setName('fan3');
99
            $dev3->setValue($this->_values[6]);
99
            $dev3->setValue($this->_values[6]);
100
//            $dev3->setMin(3000);
100
//            $dev3->setMin(3000);
101
            $this->mbinfo->setMbFan($dev3);
101
            $this->mbinfo->setMbFan($dev3);
102
        }
102
        }
103
    }
103
    }
104
 
104
 
105
    /**
105
    /**
106
     * get voltage information
106
     * get voltage information
107
     *
107
     *
108
     * @return void
108
     * @return void
109
     */
109
     */
110
    private function _voltage()
110
    private function _voltage()
111
    {
111
    {
112
        if (count($this->_values) == 14) {
112
        if (count($this->_values) == 14) {
113
            $dev1 = new SensorDevice();
113
            $dev1 = new SensorDevice();
114
            $dev1->setName('Vcore1');
114
            $dev1->setName('Vcore1');
115
            $dev1->setValue($this->_values[7]);
115
            $dev1->setValue($this->_values[7]);
116
            $this->mbinfo->setMbVolt($dev1);
116
            $this->mbinfo->setMbVolt($dev1);
117
            $dev2 = new SensorDevice();
117
            $dev2 = new SensorDevice();
118
            $dev2->setName('Vcore2');
118
            $dev2->setName('Vcore2');
119
            $dev2->setValue($this->_values[8]);
119
            $dev2->setValue($this->_values[8]);
120
            $this->mbinfo->setMbVolt($dev2);
120
            $this->mbinfo->setMbVolt($dev2);
121
            $dev3 = new SensorDevice();
121
            $dev3 = new SensorDevice();
122
            $dev3->setName('3volt');
122
            $dev3->setName('3volt');
123
            $dev3->setValue($this->_values[9]);
123
            $dev3->setValue($this->_values[9]);
124
            $this->mbinfo->setMbVolt($dev3);
124
            $this->mbinfo->setMbVolt($dev3);
125
            $dev4 = new SensorDevice();
125
            $dev4 = new SensorDevice();
126
            $dev4->setName('+5Volt');
126
            $dev4->setName('+5Volt');
127
            $dev4->setValue($this->_values[10]);
127
            $dev4->setValue($this->_values[10]);
128
            $this->mbinfo->setMbVolt($dev4);
128
            $this->mbinfo->setMbVolt($dev4);
129
            $dev5 = new SensorDevice();
129
            $dev5 = new SensorDevice();
130
            $dev5->setName('+12Volt');
130
            $dev5->setName('+12Volt');
131
            $dev5->setValue($this->_values[11]);
131
            $dev5->setValue($this->_values[11]);
132
            $this->mbinfo->setMbVolt($dev5);
132
            $this->mbinfo->setMbVolt($dev5);
133
            $dev6 = new SensorDevice();
133
            $dev6 = new SensorDevice();
134
            $dev6->setName('-12Volt');
134
            $dev6->setName('-12Volt');
135
            $dev6->setValue($this->_values[12]);
135
            $dev6->setValue($this->_values[12]);
136
            $this->mbinfo->setMbVolt($dev6);
136
            $this->mbinfo->setMbVolt($dev6);
137
            $dev7 = new SensorDevice();
137
            $dev7 = new SensorDevice();
138
            $dev7->setName('-5Volt');
138
            $dev7->setName('-5Volt');
139
            $dev7->setValue($this->_values[13]);
139
            $dev7->setValue($this->_values[13]);
140
            $this->mbinfo->setMbVolt($dev7);
140
            $this->mbinfo->setMbVolt($dev7);
141
        }
141
        }
142
    }
142
    }
143
 
143
 
144
    /**
144
    /**
145
     * get the information
145
     * get the information
146
     *
146
     *
147
     * @see PSI_Interface_Sensor::build()
147
     * @see PSI_Interface_Sensor::build()
148
     *
148
     *
149
     * @return Void
149
     * @return Void
150
     */
150
     */
151
    public function build()
151
    public function build()
152
    {
152
    {
153
        $this->_temperature();
153
        $this->_temperature();
154
        $this->_fans();
154
        $this->_fans();
155
        $this->_voltage();
155
        $this->_voltage();
156
    }
156
    }
157
}
157
}
158
 
158