Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Details | Last modification | View Log

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