3 #include "QTITempProbe.h"
16 sig_atomic_t timed_out;
18 static void timeout_handler(
int sig, siginfo_t *si,
void *uc)
24 QTITempProbe::QTITempProbe()
32 QTITempProbe::QTITempProbe(std::string dev_path)
38 QTITempProbe::~QTITempProbe()
47 void QTITempProbe::init()
52 long long freq_nanosecs;
54 sa.sa_flags = SA_SIGINFO;
55 sa.sa_sigaction = timeout_handler;
56 sigemptyset(&sa.sa_mask);
60 sev.sigev_notify = SIGEV_SIGNAL;
61 sev.sigev_signo = RTSIGTIMEOUT;
62 sev.sigev_value.sival_ptr = &timerid;
65 freq_nanosecs = (
long long) 2.*1e9;
66 its.it_value.tv_sec = freq_nanosecs/1000000000;
67 its.it_value.tv_nsec = freq_nanosecs % 1000000000;
68 its.it_interval.tv_sec = 0;
69 its.it_interval.tv_nsec = 0;
71 timer_create(CLOCK_REALTIME, &sev, &timerid);
75 int QTITempProbe::setDevPath(std::string dev_path)
79 fin.open(devPath.c_str());
83 std::cerr <<
"Error opening device path " << dev_path <<
" for reading.\n";
86 errNum = FIN_GOOD_ERROR;
90 fout.open(devPath.c_str());
94 std::cerr <<
"Error opening device path " << dev_path <<
" for writing.\n";
97 errNum = FOUT_GOOD_ERROR;
117 std::cerr <<
"Device not open. Cannot get serial number.\n";
118 errNum = DEV_NOT_OPEN_ERROR;
125 std::cerr <<
"Device " << devPath <<
" output is not good.\n";
126 errNum = FOUT_GOOD_ERROR;
132 std::cout <<
"1.0" << std::endl;
141 std::cout <<
"1.1" << std::endl;
143 std::cout <<
"1.2" << std::endl;
144 fin.readsome(details, 256);
145 std::cout <<
"1.3" << std::endl;
146 while(fin.gcount() > 0 ) fin.readsome(details, 256);
150 std::cout <<
"1.4" << std::endl;
163 std::cout <<
"1.1" << std::endl;
166 std::cout <<
"1.5" << std::endl;
170 std::cerr <<
"Device " << devPath <<
" input is not good.\n";
171 errNum = FIN_GOOD_ERROR;
179 std::cout <<
"1.6" << std::endl;
182 for(
int i=0;i<20;i++)
184 fin.getline(details, 256);
189 int srsn = line.find_first_of(
"\r\n");
190 if(srsn > -1) line[srsn] =
'\0';
192 std::cout << i <<
"+=" << line <<
" ";
194 isser = line.find(
"Ser.", 0);
195 std::cout << isser <<
"\n";
196 if(isser > -1)
break;
200 std::cout <<
"Found: " << line <<
"\n";
207 details[fin.gcount()-1] = 0;
209 serialNumber = details+7;
211 std::cout <<
"|<|" << serialNumber <<
"|>|\n";
220 fin.readsome(details, 256);
221 while(fin.gcount() > 0 ) fin.readsome(details, 256);
240 double QTITempProbe::getTemperature()
242 sigaction(RTSIGTIMEOUT, &sa, NULL);
245 timer_settime(timerid, 0, &its, 0);
254 fo = fopen(devPath.c_str(),
"w");
258 std::cerr <<
"Device not open. Cannot get temperature.\n";
259 errNum = DEV_NOT_OPEN_ERROR;
268 std::cout <<
"GT 1.0" << std::endl;
278 fi = fopen(devPath.c_str(),
"r");
281 std::cout <<
"GT 2.0" << std::endl;
286 std::cout <<
"GT 2.1" << std::endl;
304 std::cout <<
"GT 3.0" << std::endl;
309 if(timed_out)
return -1000;
310 std::cout << ts << std::endl;
311 std::cout <<
"GT 4.0" << std::endl;
315 while((ts[0] == 0 || strlen(ts) < 6) && ldt < 3.0 && !timed_out)
319 std::cout << ts << std::endl;
324 if(timed_out)
return -1000;
327 std::cerr <<
"get temperature timeout\n";
331 if(ts[0] ==
'>') ts[0] =
' ';
337 std::cout <<
"===>" << strtod(ts, 0) << std::endl;
338 return strtod(ts, 0);
double get_curr_time(void)
Gets the current CLOCK_REALTIME time, returns it in seconds to double precision.
int TimeToDie
Global set by SIGTERM.