-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuart2net_log.cpp
46 lines (34 loc) · 1.11 KB
/
uart2net_log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "uart2net.h"
int UART2NET::create_log()
{
QDateTime current_time = QDateTime::currentDateTime();
QString filename = current_time.toString("yyyy-MM-dd-hh-mm-ss") + ".txt";
QDir dir;
if(!dir.exists("log"))
{
bool res = dir.mkpath("log");
if(res == false)
return -1;
}
//log_data.open("log\\" + filename, QFile::WriteOnly | QIODevice::Truncate);
log_data.setFileName("log\\" + filename);
if(!log_data.open(QFile::WriteOnly | QIODevice::Truncate))
return -2;
log_out = new QTextStream(&log_data);
// *log_out << current_time.toString("[yyyy-MM-dd hh:mm:ss.zzz]: 12345");
// log_data.close();
return 1;
}
void UART2NET::close_log()
{
delete[] log_out;
log_data.close();
}
void UART2NET::write_log(QByteArray binaryData, QString sourcetype)
{
QDateTime current_time = QDateTime::currentDateTime();
QString outstr = current_time.toString("[yyyy-MM-dd hh:mm:ss.zzz]: ") +
sourcetype + " " +
ByteArrayToHexString(binaryData);
*log_out<<binaryData;
}