-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmainform.cpp
More file actions
133 lines (118 loc) · 3.55 KB
/
Copy pathmainform.cpp
File metadata and controls
133 lines (118 loc) · 3.55 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "mainform.h"
#include "ui_mainform.h"
enum Action
{
ReadQCN,
WriteQCN
} action;
int cport;
QString qpath;
MainForm::MainForm(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainForm)
{
ui->setupUi(this);
thread = new MainThread(this);
connect(thread, SIGNAL(log(QString,QString)),this, SLOT(log(QString,QString)));
connect(thread, SIGNAL(progressValue(int)),ui->progressBar,SLOT(setValue(int)));
connect(thread, SIGNAL(progressText(QString)),this, SLOT(progressText(QString)));
ui->progressBar->setAlignment(Qt::AlignCenter);
foreach(QSerialPortInfo port, QSerialPortInfo::availablePorts()){ ui->cb_comport->addItem(port.description()+" ("+port.portName()+")");}
}
MainForm::~MainForm()
{
delete ui;
}
void MainThread::run()
{
instance_ = this;
DiagInfo info;
info.portnum = cport;
if (!ConnectDevice(info))
return;
if (action == ReadQCN)
{
log("\nReading QCN from phone...","black");
int renas2;
QDateTime dteNow = QDateTime::currentDateTime();
QString fnl = dteNow.toString("smh_d_M_yyyy").replace(" ","_").replace(":","_");
QString path = QDir().currentPath()+"/QCN_"+fnl+".qcn";
if (!QLIB_BackupNVFromMobileToQCN(info.hndl,path.toLocal8Bit().data(),&renas2))
{
log(" error","red");
return;
}else{
log(" OK","green");
log("\nBackup file : ","black");
log(path,"blue");
progressValue(100);
}
}
if (action == WriteQCN)
{
log("\nLoading Data File...","black");
int get1 = -1;
int get2 = -1;
if (!QLIB_NV_LoadNVsFromQCN(info.hndl,qpath.toLocal8Bit().data(),&get1,&get2))
{
log(" error","red");
}else{
log(" OK","green");
log("\nWriting Data File to phone...","black");
int res2;
if (!QLIB_NV_WriteNVsToMobile(info.hndl,&res2))
{
log(" error","red");
}else{
log(" OK","green");
progressValue(100);
}
}
}
QLIB_DisconnectServer(info.hndl);
}
MainThread::MainThread(QObject *parent)
: QThread(parent)
{
}
MainThread *MainThread::instance_ = NULL;
MainThread *MainThread::Instance()
{
return instance_;
}
void MainForm::progressText(QString log)
{
ui->progressBar->setFormat(log);
}
void MainForm::log(QString log,QString color)
{
ui->textEdit->setTextColor(color);
ui->textEdit->insertPlainText(log);
ui->textEdit->moveCursor(QTextCursor::End);
}
void MainForm::on_btn_read_qcn_clicked()
{
ui->textEdit->clear();
action = ReadQCN;
cport = getSTR("(COM",")",ui->cb_comport->currentText()).toInt();
thread->start(QThread::NormalPriority);
}
void MainForm::on_btn_write_qcn_clicked()
{
ui->textEdit->clear();
QString filename = QFileDialog::getOpenFileName(this,tr("Open XML File 1"),"", tr("QCN Files (*.qcn)"));
if (filename == "")
{
log("Please select QCN file first!","red");
return;
}
qpath = filename;
action = WriteQCN;
cport = getSTR("(COM",")",ui->cb_comport->currentText()).toInt();
thread->start(QThread::NormalPriority);
}
void MainForm::on_btn_scan_port_clicked()
{
ui->cb_comport->clear();
foreach(QSerialPortInfo port, QSerialPortInfo::availablePorts()){ ui->cb_comport->addItem(port.description()+" ("+port.portName()+")");}
}