📄 temp.cpp
字号:
/* LiMon-Server| Copyright (C) 2006 Marcelo Busico|| Author: Marcelo Busico marcelobusico@gmail.com|| This program is free software which I release under the GNU General Public| License. You may redistribute and/or modify this program under the terms| of that license as published by the Free Software Foundation; either| version 2 of the License, or (at your option) any later version.|| This program is distributed in the hope that it will be useful,| but WITHOUT ANY WARRANTY; without even the implied warranty of| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the| GNU General Public License for more details. Version 2 is in the| LICENSE.txt file in the top level directory of this distribution.| | To get a copy of the GNU General Puplic License, write to the Free Software| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*//* Implementacion de la libreria que lee la Temperatura de la PC */#include "temp.h"#include "rutas.h"#include <stdio.h>#include <string.h>#include <stdlib.h>//ConstructorTemperatura::Temperatura(){ FILE *f; //Puntero a archivo char ejecutable[100]; //Para ejecutar el Script char buf[1024]; //Resultado del Script //Ruta del script strcpy(ejecutable,RUTA_SCRIPTS); //Nombre del script strcat(ejecutable,"temp.sh"); //Ejecuta el script system(ejecutable); // Temperatura del SISTEMA //Sale si no puede abrir el archivo if ((f = fopen("/tmp/limon-temp-sys", "r")) == NULL) { strcpy(cadenaSistema,""); strcpy(cadenaCPU,""); strcpy(cadenaHD,""); return; } if(fgets(buf, sizeof(buf), f)!=NULL) strcpy(cadenaSistema,buf); else strcpy(cadenaSistema,""); //Cierra el archivo fclose(f); // Temperatura de la CPU //Sale si no puede abrir el archivo if ((f = fopen("/tmp/limon-temp-cpu", "r")) == NULL) { strcpy(cadenaSistema,""); strcpy(cadenaCPU,""); strcpy(cadenaHD,""); return; } if(fgets(buf, sizeof(buf), f)!=NULL) strcpy(cadenaCPU,buf); else strcpy(cadenaCPU,""); //Cierra el archivo fclose(f); // Temperatura del Disco Rigido //Sale si no puede abrir el archivo if ((f = fopen("/tmp/limon-temp-hd", "r")) == NULL) { strcpy(cadenaSistema,""); strcpy(cadenaCPU,""); strcpy(cadenaHD,""); return; } if(fgets(buf, sizeof(buf), f)!=NULL) strcpy(cadenaHD,buf); else strcpy(cadenaHD,""); //Cierra el archivo fclose(f);}//Devuelve Temperatura del Sistemaint Temperatura::getSistema(){ int aux=-1; //Almacena el retorno de la funcion if(strlen(cadenaSistema)>0) { //Encuentra en la cadena del archivo el valor buscado a devolver sscanf(cadenaSistema,"%d",&aux); } //Retorna valor en grados celsius return aux ;}//Devuelve Temperatura de la CPUint Temperatura::getCPU(){ int aux=-1; //Almacena el retorno de la funcion if(strlen(cadenaCPU)>0) { //Encuentra en la cadena del archivo el valor buscado a devolver sscanf(cadenaCPU,"%d",&aux); } //Retorna valor en grados celsius return aux ;}//Devuelve Temperatura del Disco Rigidoint Temperatura::getHD(){ int aux=-1; //Almacena el retorno de la funcion if(strlen(cadenaHD)>0) { //Encuentra en la cadena del archivo el valor buscado a devolver sscanf(cadenaHD,"%d",&aux); } //Retorna valor en grados celsius return aux ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -