Subversion Repositories ALCASAR

Rev

Rev 2976 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2976 Rev 3037
1
<?php
1
<?php
2
/**
2
/**
3
 * PowerSoftPlus class
3
 * PowerSoftPlus 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    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
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.powersoftplus.inc.php 661 2014-06-13 11:26:39Z namiltd $
12
 * @version   SVN: $Id: class.powersoftplus.inc.php 661 2014-06-13 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 powersoftplus program
16
 * getting ups information from powersoftplus program
17
 *
17
 *
18
 * @category  PHP
18
 * @category  PHP
19
 * @package   PSI_UPS
19
 * @package   PSI_UPS
20
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
20
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
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 PowerSoftPlus extends UPS
26
class PowerSoftPlus 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 in phpsysinfo.ini and store output in internal array
36
     * get all information from all configured ups in phpsysinfo.ini 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 (defined('PSI_UPS_POWERSOFTPLUS_ACCESS') && (strtolower(trim(PSI_UPS_POWERSOFTPLUS_ACCESS))==='data')) {
-
 
42
            CommonFunctions::rftsdata('upspowersoftplus.tmp', $temp);
-
 
43
            if (! empty($temp)) {
-
 
44
                $this->_output[] = $temp;
-
 
45
            }
41
        if (PSI_OS == 'Linux') {
46
        } elseif (PSI_OS == 'Linux') {
42
            CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
47
            CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
43
            if (! empty($temp)) {
48
            if (! empty($temp)) {
44
                $this->_output[] = $temp;
49
                $this->_output[] = $temp;
45
            }
50
            }
46
        }
51
        }
47
    }
52
    }
48
 
53
 
49
    /**
54
    /**
50
     * parse the input and store data in resultset for xml generation
55
     * parse the input and store data in resultset for xml generation
51
     *
56
     *
52
     * @return Void
57
     * @return void
53
     */
58
     */
54
    private function _info()
59
    private function _info()
55
    {
60
    {
56
        foreach ($this->_output as $ups) {
61
        foreach ($this->_output as $ups) {
57
 
62
 
58
            $dev = new UPSDevice();
63
            $dev = new UPSDevice();
59
 
64
 
60
            // General info
65
            // General info
61
            $dev->setName("EVER");
66
            $dev->setName("EVER");
62
            $dev->setMode("PowerSoftPlus");
67
            $dev->setMode("PowerSoftPlus");
63
            $maxpwr = 0;
68
            $maxpwr = 0;
64
            $load = null;
69
            $load = null;
65
            if (preg_match('/^Identifier: UPS Model\s*:\s*(.*)$/m', $ups, $data)) {
70
            if (preg_match('/^Identifier: UPS Model\s*:\s*(.*)$/m', $ups, $data)) {
66
                $dev->setModel(trim($data[1]));
71
                $dev->setModel(trim($data[1]));
67
                if (preg_match('/\s(\d*)[^\d]*$/', trim($data[1]), $number)) {
72
                if (preg_match('/\s(\d*)[^\d]*$/', trim($data[1]), $number)) {
68
                    $maxpwr=$number[1]*0.65;
73
                    $maxpwr=$number[1]*0.65;
69
                }
74
                }
70
            }
75
            }
71
            if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) {
76
            if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) {
72
                $dev->setStatus(trim($data[1]));
77
                $dev->setStatus(trim($data[1]));
73
            }
78
            }
74
            if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]$/m', $ups, $data)) {
79
            if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]\r?$/m', $ups, $data)) {
75
               $load = trim($data[1]);
80
               $load = trim($data[1]);
76
            }
81
            }
77
            //wrong Output load issue
82
            //wrong Output load issue
78
            if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]$/m', $ups, $data)) {
83
            if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]\r?$/m', $ups, $data)) {
79
                $load = 100.0*trim($data[1])/$maxpwr;
84
                $load = 100.0*trim($data[1])/$maxpwr;
80
            }
85
            }
81
            if ($load != null) {
86
            if ($load != null) {
82
                $dev->setLoad($load);
87
                $dev->setLoad($load);
83
            }
88
            }
84
            // Battery
89
            // Battery
85
            if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
90
            if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]\r?$/m', $ups, $data)) {
86
                $dev->setBatteryVoltage(trim($data[1]));
91
                $dev->setBatteryVoltage(trim($data[1]));
87
            }
92
            }
88
            if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
93
            if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
89
                if (preg_match('/^At full capacity$/', trim($data[1]))) {
94
                if (preg_match('/^At full capacity$/', trim($data[1]))) {
90
                    $dev->setBatterCharge(100);
95
                    $dev->setBatterCharge(100);
91
                } elseif (preg_match('/^(Discharged)|(Depleted)$/', trim($data[1]))) {
96
                } elseif (preg_match('/^(Discharged)|(Depleted)$/', trim($data[1]))) {
92
                    $dev->setBatterCharge(0);
97
                    $dev->setBatterCharge(0);
93
                }
98
                }
94
            }
99
            }
95
            // Line
100
            // Line
96
            if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
101
            if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]\r?$/m', $ups, $data)) {
97
                $dev->setLineVoltage(trim($data[1]));
102
                $dev->setLineVoltage(trim($data[1]));
98
            }
103
            }
99
            if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) {
104
            if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]\r?$/m', $ups, $data)) {
100
                $dev->setLineFrequency(trim($data[1]));
105
                $dev->setLineFrequency(trim($data[1]));
101
            }
106
            }
102
            $this->upsinfo->setUpsDevices($dev);
107
            $this->upsinfo->setUpsDevices($dev);
103
        }
108
        }
104
    }
109
    }
105
 
110
 
106
    /**
111
    /**
107
     * get the information
112
     * get the information
108
     *
113
     *
109
     * @see PSI_Interface_UPS::build()
114
     * @see PSI_Interface_UPS::build()
110
     *
115
     *
111
     * @return Void
116
     * @return void
112
     */
117
     */
113
    public function build()
118
    public function build()
114
    {
119
    {
115
        $this->_info();
120
        $this->_info();
116
    }
121
    }
117
}
122
}
118
 
123