• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂f904d12b0357c0e675604c36814860309c854e17 (tree)
時間2013-01-29 00:20:59
作者arakaki <alucky4416@user...>
Commiterarakaki

Log Message

feature: add function save log to file.

Change Summary

差異

--- a/daqthread.cpp
+++ b/daqthread.cpp
@@ -67,10 +67,11 @@ void DAQThread::run()
6767 while(!stopped) {
6868 if (1) {
6969 timestamp = QDateTime::currentDateTime();
70- GetTempHumidTrue(deviceStr, &tmpr, &humid);
70+
71+ GetTempHumidTrue(deviceStr, &tmpr, &humid); // Get Data from USBRH
7172
7273 //qDebug() << "NowTime=" << timestamp << ", Tempr=" << tmpr << ", humid=" << humid;
73- emit GetData(timestamp, tmpr, humid);
74+ emit GetData(timestamp, tmpr, humid); // Send Data to MainWindow
7475
7576 if (logging) {
7677 // Send Data to LogTh; // toMSecsSinceEpoch() is UTC ms uint64
--- a/logthread.cpp
+++ b/logthread.cpp
@@ -1,5 +1,10 @@
11 #include "logthread.h"
22
3+#include <QFile>
4+#include <QDir>
5+#include <QTextStream>
6+
7+#include <QDateTime>
38 #include <QDebug>
49
510 LogThread::LogThread(QObject *parent) :
@@ -57,6 +62,9 @@ void LogThread::run()
5762
5863 qDebug() << "logTh is started.";
5964 EventData event;
65+ QFile csvfile;
66+ QTextStream out;
67+ QDateTime timestamp;
6068 while(!stopped) {
6169 if (EvtQue->isEmpty()) {
6270 msleep(100);
@@ -65,13 +73,29 @@ void LogThread::run()
6573 if (!logging) { // idle
6674 if (event.id == Ev_Log_Start) {
6775 // then file open
68- logging = true;
69- qDebug() << "logTh log started.";
70- emit LogStarted();
76+ logfilepath = logsavefolderpath + QDir::separator() + "USBRHLog_" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".csv";
77+ csvfile.setFileName(logfilepath);
78+ if (csvfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
79+ logging = true;
80+ qDebug() << "logTh log started. logfilename is " << logfilepath;
81+ out.flush();
82+ out.setDevice(&csvfile);
83+ out.setRealNumberNotation(QTextStream::FixedNotation);
84+ out.setRealNumberPrecision(2);
85+ if (csvfile.size() == 0) {
86+ out << "timestamp, tempr(C), humid(%)" << endl; // append header
87+ }
88+ emit LogStarted();
89+ } else {
90+ emit LogEnded(1);
91+ qDebug() << "open error";
92+ }
7193 }
7294 } else { // logging
7395 if (event.id == Ev_Log_Stop) {
7496 // then file close
97+ out.flush();
98+ if (csvfile.isOpen()) csvfile.close();
7599 logsavefolderpath = "";
76100 logfilepath = "";
77101 logging = false;
@@ -79,11 +103,23 @@ void LogThread::run()
79103 emit LogEnded(0);
80104 } else if (event.id == Ev_Log_Data) {
81105 // if data; // write data to file.
82- qDebug() << "tmpr = " << event.tmpr << ", humid = " << event.humid;
106+ timestamp.setMSecsSinceEpoch(event.timestamp_ms);
107+ qDebug() << "timestamp: " << timestamp.toString("yyyy/MM/dd hh:mm:ss") << "," << "tmpr = " << event.tmpr << ", humid = " << event.humid;
108+ out << timestamp.toString("yyyy/MM/dd hh:mm:ss") << "," << event.tmpr << "," << event.humid << endl;
83109 }
84110 }
85111 }
86112 }
87- qDebug() << "logTh is stopped.";
88113
114+ if (logging) {
115+ logging = false;
116+ logsavefolderpath = "";
117+ emit LogEnded(0);
118+ }
119+ if (csvfile.isOpen()) {
120+ out.flush();
121+ csvfile.close();
122+ }
123+
124+ qDebug() << "logTh is stopped.";
89125 }