
| Revision | 9ae25e539b85b797a617b3cfe470e314b02dd8cb (tree) |
|---|---|
| Time | 2013-01-30 00:07:36 |
| Author | arakaki <alucky4416@user...> |
| Commiter | arakaki |
feature: log save interval 1minute. change log file each days.
| @@ -60,31 +60,37 @@ void LogThread::LogData(quint64 timestamp, double tmpr, double humid) | ||
| 60 | 60 | void LogThread::run() |
| 61 | 61 | { |
| 62 | 62 | |
| 63 | - qDebug() << "logTh is started."; | |
| 63 | + // qDebug() << "logTh is started."; | |
| 64 | 64 | EventData event; |
| 65 | 65 | QFile csvfile; |
| 66 | 66 | QTextStream out; |
| 67 | 67 | QDateTime timestamp; |
| 68 | + int prev_Minute; // prev minutes for timestamp for 1 minutes interval | |
| 69 | + int prev_Day; // prev Day for Change logfile. | |
| 70 | + | |
| 68 | 71 | while(!stopped) { |
| 69 | 72 | if (EvtQue->isEmpty()) { |
| 70 | 73 | msleep(100); |
| 71 | - } else { | |
| 74 | + } else { | |
| 72 | 75 | event = EvtQue->dequeue(); |
| 73 | 76 | if (!logging) { // idle |
| 74 | 77 | if (event.id == Ev_Log_Start) { |
| 75 | 78 | // then file open |
| 76 | - logfilepath = logsavefolderpath + QDir::separator() + "USBRHLog_" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".csv"; | |
| 79 | + prev_Minute = -1; | |
| 80 | + QDateTime today = QDateTime::currentDateTime(); | |
| 81 | + logfilepath = logsavefolderpath + QDir::separator() + "USBRHLog_" + today.toString("yyyyMMdd") + ".csv"; | |
| 77 | 82 | csvfile.setFileName(logfilepath); |
| 78 | 83 | if (csvfile.open(QIODevice::WriteOnly | QIODevice::Append)) { |
| 79 | 84 | logging = true; |
| 80 | 85 | qDebug() << "logTh log started. logfilename is " << logfilepath; |
| 81 | - out.flush(); | |
| 86 | + //out.flush(); | |
| 82 | 87 | out.setDevice(&csvfile); |
| 83 | 88 | out.setRealNumberNotation(QTextStream::FixedNotation); |
| 84 | 89 | out.setRealNumberPrecision(2); |
| 85 | 90 | if (csvfile.size() == 0) { |
| 86 | 91 | out << "timestamp, tempr(C), humid(%)" << endl; // append header |
| 87 | 92 | } |
| 93 | + prev_Day = today.date().day(); | |
| 88 | 94 | emit LogStarted(); |
| 89 | 95 | } else { |
| 90 | 96 | emit LogEnded(1); |
| @@ -104,8 +110,28 @@ void LogThread::run() | ||
| 104 | 110 | } else if (event.id == Ev_Log_Data) { |
| 105 | 111 | // if data; // write data to file. |
| 106 | 112 | 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; | |
| 113 | + if (timestamp.time().minute() != prev_Minute) { // save interval is 1 minute | |
| 114 | + if (timestamp.date().day() != prev_Day) { | |
| 115 | + out.flush(); | |
| 116 | + csvfile.close(); | |
| 117 | + logfilepath = logsavefolderpath + QDir::separator() + "USBRHLog_" + timestamp.toString("yyyyMMdd") + ".csv"; | |
| 118 | + csvfile.setFileName(logfilepath); | |
| 119 | + if (csvfile.open(QIODevice::WriteOnly | QIODevice::Append)) { | |
| 120 | + logging = true; | |
| 121 | + qDebug() << "logTh log started. logfilename is " << logfilepath; | |
| 122 | + out.setDevice(&csvfile); | |
| 123 | + out.setRealNumberNotation(QTextStream::FixedNotation); | |
| 124 | + out.setRealNumberPrecision(2); | |
| 125 | + if (csvfile.size() == 0) { | |
| 126 | + out << "timestamp, tempr(C), humid(%)" << endl; // append header | |
| 127 | + } | |
| 128 | + prev_Day = timestamp.date().day(); | |
| 129 | + } | |
| 130 | + } | |
| 131 | + // qDebug() << "timestamp: " << timestamp.toString("yyyy/MM/dd hh:mm:ss") << "," << "tmpr = " << event.tmpr << ", humid = " << event.humid; | |
| 132 | + out << timestamp.toString("yyyy/MM/dd hh:mm") << ", " << event.tmpr << ", " << event.humid << endl; | |
| 133 | + prev_Minute = timestamp.time().minute(); | |
| 134 | + } | |
| 109 | 135 | } |
| 110 | 136 | } |
| 111 | 137 | } |
| @@ -121,5 +147,5 @@ void LogThread::run() | ||
| 121 | 147 | csvfile.close(); |
| 122 | 148 | } |
| 123 | 149 | |
| 124 | - qDebug() << "logTh is stopped."; | |
| 150 | + // qDebug() << "logTh is stopped."; | |
| 125 | 151 | } |
| @@ -28,6 +28,9 @@ | ||
| 28 | 28 | <pointsize>18</pointsize> |
| 29 | 29 | </font> |
| 30 | 30 | </property> |
| 31 | + <property name="segmentStyle"> | |
| 32 | + <enum>QLCDNumber::Flat</enum> | |
| 33 | + </property> | |
| 31 | 34 | </widget> |
| 32 | 35 | <widget class="QLCDNumber" name="lcdHumid"> |
| 33 | 36 | <property name="geometry"> |
| @@ -43,6 +46,9 @@ | ||
| 43 | 46 | <pointsize>18</pointsize> |
| 44 | 47 | </font> |
| 45 | 48 | </property> |
| 49 | + <property name="segmentStyle"> | |
| 50 | + <enum>QLCDNumber::Flat</enum> | |
| 51 | + </property> | |
| 46 | 52 | </widget> |
| 47 | 53 | <widget class="QLabel" name="label"> |
| 48 | 54 | <property name="geometry"> |