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