Subversion Repositories ALCASAR

Rev

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

Rev 2775 Rev 2976
1
<?php
1
<?php
2
/**
2
/**
3
 * Pmset class
3
 * Pmset class
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI_UPS
8
 * @package   PSI_UPS
9
 * @author    Robert Pelletier <drizzt@menzonet.org>
9
 * @author    Robert Pelletier <drizzt@menzonet.org>
10
 * @copyright 2014 phpSysInfo
10
 * @copyright 2014 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   SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
12
 * @version   SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
 /**
15
 /**
16
 * getting ups information from pmset program
16
 * getting ups information from pmset program
17
 *
17
 *
18
 * @category  PHP
18
 * @category  PHP
19
 * @package   PSI_UPS
19
 * @package   PSI_UPS
20
 * @author    Robert Pelletier <drizzt@menzonet.org>
20
 * @author    Robert Pelletier <drizzt@menzonet.org>
21
 * @copyright 2014 phpSysInfo
21
 * @copyright 2014 phpSysInfo
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
23
 * @version   Release: 3.0
23
 * @version   Release: 3.0
24
 * @link      http://phpsysinfo.sourceforge.net
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
25
 */
26
class Pmset extends UPS
26
class Pmset extends UPS
27
{
27
{
28
    /**
28
    /**
29
     * internal storage for all gathered data
29
     * internal storage for all gathered data
30
     *
30
     *
31
     * @var array
31
     * @var array
32
     */
32
     */
33
    private $_output = array();
33
    private $_output = array();
34
 
34
 
35
    /**
35
    /**
36
     * get all information from all configured ups and store output in internal array
36
     * get all information from all configured ups and store output in internal array
37
     */
37
     */
38
    public function __construct()
38
    public function __construct()
39
    {
39
    {
40
        parent::__construct();
40
        parent::__construct();
-
 
41
        if (PSI_OS == 'Darwin') {
41
        $temp = "";
42
            $temp = "";
42
        if (CommonFunctions::executeProgram('pmset', '-g batt', $temp) && !empty($temp)) {
43
            if (CommonFunctions::executeProgram('pmset', '-g batt', $temp) && !empty($temp)) {
43
            $this->_output[] = $temp;
44
                $this->_output[] = $temp;
-
 
45
            }
44
        }
46
        }
45
    }
47
    }
46
 
48
 
47
    /**
49
    /**
48
     * parse the input and store data in resultset for xml generation
50
     * parse the input and store data in resultset for xml generation
49
     *
51
     *
50
     * @return void
52
     * @return void
51
     */
53
     */
52
   private function _info()
54
   private function _info()
53
    {
55
    {
54
        if (empty($this->_output)) {
56
        if (empty($this->_output)) {
55
            return;
57
            return;
56
        }
58
        }
57
        $model = array();
59
        $model = array();
58
        $percCharge = array();
60
        $percCharge = array();
59
        $lines = explode(PHP_EOL, implode($this->_output));
61
        $lines = explode(PHP_EOL, implode($this->_output));
60
        if (count($lines)>1) {
62
        if (count($lines)>1) {
61
            $model = explode('FW:', $lines[1]);
63
            $model = explode('FW:', $lines[1]);
62
            if (strpos($model[0], 'InternalBattery') === false) {
64
            if (strpos($model[0], 'InternalBattery') === false) {
63
                $dev = new UPSDevice();
65
                $dev = new UPSDevice();
64
                $percCharge = explode(';', $lines[1]);
66
                $percCharge = explode(';', $lines[1]);
65
                $dev->setName('UPS');
67
                $dev->setName('UPS');
66
                if ($model !== false) {
68
                if ($model !== false) {
67
                    $dev->setModel(substr(trim($model[0]), 1));
69
                    $dev->setModel(substr(trim($model[0]), 1));
68
                }
70
                }
69
                if ($percCharge !== false) {
71
                if ($percCharge !== false) {
70
                    $dev->setBatterCharge(trim(substr($percCharge[0], -4, 3)));
72
                    $dev->setBatterCharge(trim(substr($percCharge[0], -4, 3)));
71
                    $dev->setStatus(trim($percCharge[1]));
73
                    $dev->setStatus(trim($percCharge[1]));
72
                    if (isset($percCharge[2])) {
74
                    if (isset($percCharge[2])) {
73
                        $time = explode(':', $percCharge[2]);
75
                        $time = explode(':', $percCharge[2]);
74
                        $hours = $time[0];
76
                        $hours = $time[0];
75
                        $minutes = $hours*60+substr($time[1], 0, 2);
77
                        $minutes = $hours*60+substr($time[1], 0, 2);
76
                        $dev->setTimeLeft($minutes);
78
                        $dev->setTimeLeft($minutes);
77
                    }
79
                    }
78
                }
80
                }
79
                $dev->setMode("pmset");
81
                $dev->setMode("pmset");
80
                $this->upsinfo->setUpsDevices($dev);
82
                $this->upsinfo->setUpsDevices($dev);
81
            }
83
            }
82
        }
84
        }
83
    }
85
    }
84
 
86
 
85
    /**
87
    /**
86
     * get the information
88
     * get the information
87
     *
89
     *
88
     * @see PSI_Interface_UPS::build()
90
     * @see PSI_Interface_UPS::build()
89
     *
91
     *
90
     * @return Void
92
     * @return Void
91
     */
93
     */
92
    public function build()
94
    public function build()
93
    {
95
    {
94
        $this->_info();
96
        $this->_info();
95
    }
97
    }
96
}
98
}
97
 
99