Subversion Repositories ALCASAR

Rev

Rev 2775 | Go to most recent revision | Details | Compare with Previous | 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();
2976 rexy 41
        if (PSI_OS == 'Linux') {
42
            CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
43
            if (! empty($temp)) {
44
                $this->_output[] = $temp;
45
            }
2775 rexy 46
        }
47
    }
48
 
49
    /**
50
     * parse the input and store data in resultset for xml generation
51
     *
52
     * @return Void
53
     */
54
    private function _info()
55
    {
56
        foreach ($this->_output as $ups) {
57
 
58
            $dev = new UPSDevice();
59
 
60
            // General info
61
            $dev->setName("EVER");
62
            $dev->setMode("PowerSoftPlus");
63
            $maxpwr = 0;
64
            $load = null;
65
            if (preg_match('/^Identifier: UPS Model\s*:\s*(.*)$/m', $ups, $data)) {
66
                $dev->setModel(trim($data[1]));
67
                if (preg_match('/\s(\d*)[^\d]*$/', trim($data[1]), $number)) {
68
                    $maxpwr=$number[1]*0.65;
69
                }
70
            }
71
            if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) {
72
                $dev->setStatus(trim($data[1]));
73
            }
74
            if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]$/m', $ups, $data)) {
75
               $load = trim($data[1]);
76
            }
77
            //wrong Output load issue
78
            if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]$/m', $ups, $data)) {
79
                $load = 100.0*trim($data[1])/$maxpwr;
80
            }
81
            if ($load != null) {
82
                $dev->setLoad($load);
83
            }
84
            // Battery
85
            if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
86
                $dev->setBatteryVoltage(trim($data[1]));
87
            }
88
            if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
89
                if (preg_match('/^At full capacity$/', trim($data[1]))) {
90
                    $dev->setBatterCharge(100);
91
                } elseif (preg_match('/^(Discharged)|(Depleted)$/', trim($data[1]))) {
92
                    $dev->setBatterCharge(0);
93
                }
94
            }
95
            // Line
96
            if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
97
                $dev->setLineVoltage(trim($data[1]));
98
            }
99
            if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) {
100
                $dev->setLineFrequency(trim($data[1]));
101
            }
102
            $this->upsinfo->setUpsDevices($dev);
103
        }
104
    }
105
 
106
    /**
107
     * get the information
108
     *
109
     * @see PSI_Interface_UPS::build()
110
     *
111
     * @return Void
112
     */
113
    public function build()
114
    {
115
        $this->_info();
116
    }
117
}