superkaramba
lmsensor.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "lmsensor.h"
00012
00013 SensorSensor::SensorSensor(int interval, char tempUnit) : Sensor(interval)
00014 {
00015 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00016 sensorMapBSD["VCore 1"] = "VC0";
00017 sensorMapBSD["VCore 2"] = "VC1";
00018 sensorMapBSD["+3.3V"] = "V33";
00019 sensorMapBSD["+5V"] = "V50P";
00020 sensorMapBSD["+12V"] = "V12P";
00021 sensorMapBSD["-12V"] = "V12N";
00022 sensorMapBSD["-5V"] = "V50N";
00023 sensorMapBSD["fan1"] = "FAN0";
00024 sensorMapBSD["fan2"] = "FAN1";
00025 sensorMapBSD["fan3"] = "FAN2";
00026 sensorMapBSD["temp1"] = "TEMP0";
00027 sensorMapBSD["temp2"] = "TEMP1";
00028 sensorMapBSD["temp3"] = "TEMP2";
00029 #endif
00030 if (tempUnit == 'F')
00031 extraParams = " -f";
00032 connect(&ksp, SIGNAL(receivedStdout(K3Process *, char *, int)),
00033 this, SLOT(receivedStdout(K3Process *, char *, int)));
00034 connect(&ksp, SIGNAL(processExited(K3Process *)),
00035 this, SLOT(processExited(K3Process *)));
00036
00037
00038 }
00039
00040
00041 SensorSensor::~SensorSensor()
00042 {}
00043
00044 void SensorSensor::receivedStdout(K3Process *, char *buffer, int len)
00045 {
00046 buffer[len] = 0;
00047 sensorResult += QString(buffer);
00048 }
00049
00050 void SensorSensor::processExited(K3Process *)
00051 {
00052 QStringList stringList = sensorResult.split('\n');
00053 sensorResult = "";
00054 QStringList::Iterator it = stringList.begin();
00055 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00056 QRegExp rx("^(\\S+)\\s+:\\s+[\\+\\-]?(\\d+\\.?\\d*)");
00057 #else
00058 QRegExp rx("^(.+):\\s+[\\+\\-]?(\\d+\\.?\\d*)");
00059 #endif
00060 while (it != stringList.end()) {
00061 rx.indexIn(*it);
00062
00063 if (!rx.cap(0).isEmpty()) {
00064 sensorMap[rx.cap(1)] = rx.cap(2);
00065 }
00066 it++;
00067 }
00068
00069 QString format;
00070 QString type;
00071 SensorParams *sp;
00072 Meter *meter;
00073
00074 QObject *lobject;
00075 foreach(lobject, *objList) {
00076 sp = (SensorParams*)(lobject);
00077 meter = sp->getMeter();
00078 format = sp->getParam("FORMAT");
00079 type = sp->getParam("TYPE");
00080
00081 if (type.length() == 0)
00082 type = "temp2";
00083
00084 if (format.length() == 0) {
00085 format = "%v";
00086 }
00087
00088 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00089 format.replace(QRegExp("%v", Qt::CaseInsensitive),
00090 sensorMap[sensorMapBSD[type]]);
00091 #else
00092 format.replace(QRegExp("%v", Qt::CaseInsensitive),
00093 sensorMap[type]);
00094 #endif
00095 meter->setValue(format);
00096 }
00097 }
00098
00099 void SensorSensor::update()
00100 {
00101 ksp.clearArguments();
00102 #if defined __FreeBSD__ || defined(Q_OS_NETBSD)
00103 ksp << "mbmon -r -c 1" << extraParams;
00104 #else
00105 ksp << "sensors" << extraParams;
00106 #endif
00107 ksp.start(K3Process::NotifyOnExit, K3ProcIO::Stdout);
00108 }
00109
00110
00111 #include "lmsensor.moc"