Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2976 Rev 3037
Line 28... Line 28...
28
    {
28
    {
29
        parent::__construct();
29
        parent::__construct();
30
        switch (defined('PSI_SENSOR_THERMALZONE_ACCESS')?strtolower(PSI_SENSOR_THERMALZONE_ACCESS):'command') {
30
        switch (defined('PSI_SENSOR_THERMALZONE_ACCESS')?strtolower(PSI_SENSOR_THERMALZONE_ACCESS):'command') {
31
        case 'command':
31
        case 'command':
32
            if ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')) {
32
            if ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')) {
33
                if (defined('PSI_EMU_HOSTNAME') || CommonFunctions::isAdmin()) {
33
                if (defined('PSI_EMU_HOSTNAME') || WINNT::isAdmin()) {
34
                    $_wmi = CommonFunctions::initWMI('root\WMI', true);
34
                    $_wmi = WINNT::initWMI('root\WMI', true);
35
                    if ($_wmi) {
35
                    if ($_wmi) {
36
                        $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
36
                        $this->_buf = WINNT::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
37
                    }
37
                    }
38
                } else {
38
                } else {
-
 
39
                    $_wmi = WINNT::getcimv2wmi();
-
 
40
                    if ($_wmi) {
-
 
41
                        $this->_buf = WINNT::getWMI($_wmi, 'Win32_PerfFormattedData_Counters_ThermalZoneInformation', array('Name', 'HighPrecisionTemperature', 'Temperature'));
-
 
42
                    }
-
 
43
                    if (!$this->_buf || PSI_DEBUG) {
39
                    $this->error->addError("Error reading data from thermalzone sensor", "Allowed only for systems with administrator privileges (run as administrator)");
44
                        $this->error->addError("Error reading data from thermalzone sensor", "Allowed only for systems with administrator privileges (run as administrator)");
-
 
45
                    }
40
                }
46
                }
41
            }
47
            }
42
            break;
48
            break;
43
        case 'data':
49
        case 'data':
44
            if (!defined('PSI_EMU_HOSTNAME') && CommonFunctions::rfts(PSI_APP_ROOT.'/data/thermalzone.txt', $lines, 0, 4096, false)) { //output of "wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature,InstanceName"
50
            if (!defined('PSI_EMU_HOSTNAME') && CommonFunctions::rftsdata('thermalzone.tmp', $lines)) { //output of "wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature,InstanceName"
45
                $lines = trim(preg_replace('/[\x00-\x09\x0b-\x1F]/', '', $lines));
51
                $lines = trim(preg_replace('/[\x00-\x09\x0b-\x1F]/', '', $lines));
46
                $lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
52
                $lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
47
                if ((($clines=count($lines)) > 1) && preg_match("/CriticalTripPoint\s+CurrentTemperature\s+InstanceName/i", $lines[0])) for ($i = 1; $i < $clines; $i++) {
53
                if ((($clines=count($lines)) > 1) && preg_match("/CriticalTripPoint\s+CurrentTemperature\s+InstanceName/i", $lines[0])) for ($i = 1; $i < $clines; $i++) {
48
                    $values = preg_split("/\s+/", trim($lines[$i]), -1, PREG_SPLIT_NO_EMPTY);
54
                    $values = preg_split("/\s+/", trim($lines[$i]), -1, PREG_SPLIT_NO_EMPTY);
49
                    if (count($values)==3) {
55
                    if (count($values)==3) {
Line 52... Line 58...
52
                }
58
                }
53
            }
59
            }
54
            break;
60
            break;
55
        default:
61
        default:
56
            $this->error->addConfigError('__construct()', '[sensor_thermalzone] ACCESS');
62
            $this->error->addConfigError('__construct()', '[sensor_thermalzone] ACCESS');
57
            break;
-
 
58
        }
63
        }
59
    }
64
    }
60
 
65
 
61
    /**
66
    /**
62
     * get temperature information
67
     * get temperature information
Line 79... Line 84...
79
                    $dev->setValue($value);
84
                    $dev->setValue($value);
80
                    if (isset($buffer['CriticalTripPoint']) && (($maxvalue = ($buffer['CriticalTripPoint'] - 2732)/10) > 0)) {
85
                    if (isset($buffer['CriticalTripPoint']) && (($maxvalue = ($buffer['CriticalTripPoint'] - 2732)/10) > 0)) {
81
                        $dev->setMax($maxvalue);
86
                        $dev->setMax($maxvalue);
82
                    }
87
                    }
83
                    $this->mbinfo->setMbTemp($dev);
88
                    $this->mbinfo->setMbTemp($dev);
-
 
89
                } else {
-
 
90
                    if ((isset($buffer['HighPrecisionTemperature']) && (($value = ($buffer['HighPrecisionTemperature'] - 2732)/10) > -100))
-
 
91
                       || (isset($buffer['Temperature']) && (($value = ($buffer['Temperature'] - 273)) > -100))) {
-
 
92
                        $dev = new SensorDevice();
-
 
93
                        if (isset($buffer['Name']) && preg_match("/([^\\\\\. ]+)$/", $buffer['Name'], $outbuf)) {
-
 
94
                            $dev->setName('ThermalZone '.$outbuf[1]);
-
 
95
                        } else {
-
 
96
                            $dev->setName('ThermalZone THM0');
-
 
97
                        }
-
 
98
                        $dev->setValue($value);
-
 
99
                        $this->mbinfo->setMbTemp($dev);
-
 
100
                    }
84
                }
101
                }
85
            }
102
            }
86
        } elseif (($mode == 'command') && (PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) {
103
        } elseif (($mode == 'command') && (PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) {
87
            $notwas = true;
104
            $notwas = true;
88
            $thermalzones = glob('/sys/class/thermal/thermal_zone*/');
105
            $thermalzones = CommonFunctions::findglob('/sys/class/thermal/thermal_zone*/');
89
            if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
106
            if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
90
                $thermalzonetemp = $thermalzone.'temp';
107
                $thermalzonetemp = $thermalzone.'temp';
91
                $temp = null;
108
                $temp = null;
92
                if (CommonFunctions::rfts($thermalzonetemp, $temp, 1, 4096, false) && !is_null($temp) && (($temp = trim($temp)) != "")) {
109
                if (CommonFunctions::rfts($thermalzonetemp, $temp, 1, 4096, false) && ($temp !== null) && (($temp = trim($temp)) != "")) {
93
                    if ($temp >= 1000) {
110
                    if ($temp >= 1000) {
94
                        $div = 1000;
111
                        $div = 1000;
95
                    } elseif ($temp >= 200) {
112
                    } elseif ($temp >= 200) {
96
                        $div = 10;
113
                        $div = 10;
97
                    } else {
114
                    } else {
Line 102... Line 119...
102
                    if ($temp > -40) {
119
                    if ($temp > -40) {
103
                        $dev = new SensorDevice();
120
                        $dev = new SensorDevice();
104
                        $dev->setValue($temp);
121
                        $dev->setValue($temp);
105
 
122
 
106
                        $temp_type = null;
123
                        $temp_type = null;
107
                        if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 1, 4096, false) && !is_null($temp_type) && (($temp_type = trim($temp_type)) != "")) {
124
                        if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 1, 4096, false) && ($temp_type !== null) && (($temp_type = trim($temp_type)) != "")) {
108
                            $dev->setName($temp_type);
125
                            $dev->setName($temp_type);
109
                        } else {
126
                        } else {
110
                            $dev->setName("ThermalZone");
127
                            $dev->setName("ThermalZone");
111
                        }
128
                        }
112
 
129
 
113
                        $temp_max = null;
130
                        $temp_max = null;
114
                        if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 1, 4096, false) && !is_null($temp_max) && (($temp_max = trim($temp_max)) != "") && ($temp_max > -40)) {
131
                        if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 1, 4096, false) && ($temp_max !== null) && (($temp_max = trim($temp_max)) != "") && ($temp_max > -40)) {
115
                            $temp_max = $temp_max / $div;
132
                            $temp_max = $temp_max / $div;
116
                            if (($temp_max != 0) || ($temp != 0)) { // if non-zero values
133
                            if (($temp_max != 0) || ($temp != 0)) { // if non-zero values
117
                                $dev->setMax($temp_max);
134
                                $dev->setMax($temp_max);
118
                                $this->mbinfo->setMbTemp($dev);
135
                                $this->mbinfo->setMbTemp($dev);
119
                            }
136
                            }
Line 123... Line 140...
123
                        $notwas = false;
140
                        $notwas = false;
124
                    }
141
                    }
125
                }
142
                }
126
            }
143
            }
127
            if ($notwas) {
144
            if ($notwas) {
128
                $thermalzones = glob('/proc/acpi/thermal_zone/TH*/temperature');
145
                $thermalzones = (PSI_ROOT_FILESYSTEM.'/proc/acpi/thermal_zone/TH*/temperature');
129
                if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
146
                if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
130
                    $temp = null;
147
                    $temp = null;
131
                    if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && !is_null($temp) && (($temp = trim($temp)) != "")) {
148
                    if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && ($temp !== null) && (($temp = trim($temp)) != "")) {
132
                        $dev = new SensorDevice();
149
                        $dev = new SensorDevice();
133
                        if (preg_match("/^\/proc\/acpi\/thermal_zone\/(.+)\/temperature$/", $thermalzone, $name)) {
150
                        if (preg_match("/^\/proc\/acpi\/thermal_zone\/(.+)\/temperature$/", $thermalzone, $name)) {
134
                           $dev->setName("ThermalZone ".$name[1]);
151
                           $dev->setName("ThermalZone ".$name[1]);
135
                        } else {
152
                        } else {
136
                            $dev->setName("ThermalZone");
153
                            $dev->setName("ThermalZone");
Line 146... Line 163...
146
    /**
163
    /**
147
     * get the information
164
     * get the information
148
     *
165
     *
149
     * @see PSI_Interface_Sensor::build()
166
     * @see PSI_Interface_Sensor::build()
150
     *
167
     *
151
     * @return Void
168
     * @return void
152
     */
169
     */
153
    public function build()
170
    public function build()
154
    {
171
    {
155
      $this->_temperature();
172
      $this->_temperature();
156
    }
173
    }