-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
341 lines (317 loc) · 7.51 KB
/
mainwindow.cpp
File metadata and controls
341 lines (317 loc) · 7.51 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
/*
serial=new QSerialPort();
*/
ui->setupUi(this);
t1=new PortThread();
t1->start();
t2=new ThreadSend();
t2->start();
sending=false;
statusBar()->showMessage("To begin, select the COM Port");
connect(ui->None,SIGNAL(toggled(bool)),this,SLOT(noEncryption(bool)));
connect(ui->update,SIGNAL(clicked()),this,SLOT(sendConfig()));
connect(this,SIGNAL(SendMessage(QString,QByteArray,QByteArray,QByteArray)),t2,SLOT(test(QString,QByteArray,QByteArray,QByteArray)));
connect(t2,SIGNAL(write(int)),this,SLOT(write(int)));
connect(t1,SIGNAL(updateName(QString)),this,SLOT(UpdateList(QString)));
connect(this,SIGNAL(SaveConf(bool)),t2,SLOT(writeConf(bool)));
connect(t1,SIGNAL(isPlugged(bool)),this,SLOT(connectedAirbox(bool)));
}
void MainWindow::write(int a)
{
//If error (a>=10), close connection, thread)
if (a>=10 && a!=13)
{
emit CloseConnection();
}
QString m;
switch(a)
{
case 1:
m="Connecting to serial";
break;
case 2:
m="Entering configuration mode";
break;
case 3:
m="Sending new configuration";
break;
case 4:
m="Waiting for information";
break;
case 5:
m="Saving";
break;
case 6:
{
m="";
int ret=QMessageBox::information(this, "Configuration saved","Configuration saved successfully");
if( ret == QMessageBox::Ok ) qApp->quit();
break;
}
case 10:
{
m="";
int reponse = QMessageBox::warning(this, "Could not connect", "Can't connect to the device, please try again");
sending=false;
lockui(false);
break;
}
case 11:
{
m="";
int reponse = QMessageBox::warning(this, "Configuration mode", "Error while entering configuration mode, please try again");
sending=false;
lockui(false);
break;
}
case 12:
{
m="";
int reponse = QMessageBox::warning(this, "Configuration mode", "Error while sending configuration, please try again");
sending=false;
lockui(false);
break;
}
case 13:
{
m="";
int reponse = QMessageBox::warning(this, "Could not connect", "AIRBOXLAB COULD NOT CONNECT TO THE WIRELESS SIGNAL(Time out in 60 sec) Do you want WiFi credentials to be saved in Airboxlab anyway?",QMessageBox::Yes|QMessageBox::No);
if (reponse==QMessageBox::Yes)
{
emit SaveConf(true);
}
else emit SaveConf(false);
break;
}
case 14:
{
m="";
int ret=QMessageBox::information(this, "Configuration not saved","Could not confirm information, no saving, please try again");
sending=false;
lockui(false);
//if( ret == QMessageBox::Ok ) qApp->quit();
break;
}
case 15:
{
m="";
int ret=QMessageBox::information(this, "Can't save","Error while saving, please try again");
sending=false;
lockui(false);
//if( ret == QMessageBox::Ok ) qApp->quit();
break;
}
case 16:
{
m="";
int ret=QMessageBox::information(this, "Configuration not saved","Error while writing no saving");
sending=false;
lockui(false);
//if( ret == QMessageBox::Ok ) qApp->quit();
break;
}
default:
m="No message saved";
break;
//}
}
ui->statusBar->showMessage(m);
}
void MainWindow::UpdateList(QString q)
{
portConnectedName=q;
}
void MainWindow::noEncryption(bool b)
{
ui->pwd->clear();
ui->pwd->setDisabled(b);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::connectedAirbox(bool b)
{
if (!sending)
{
bool enabled=false;
if (b)
{
ui->statusBar->showMessage("Airboxlab detected");
enabled=false;
}
else
{
ui->statusBar->showMessage("Airboxlab not detected : Please plug it to the computer");
enabled=true;
}
lockui(enabled);
}
}
void MainWindow::ChangeStatusBar()
{
statusBar()->showMessage("Enter the WiFi parameter");
}
void MainWindow::UnlockWifiParameter()
{
ui->ssid->setEnabled(true);
ui->pwd->setEnabled(true);
ui->encryption->setEnabled(true);
}
void MainWindow::lockui(bool b)
{
ui->encryption->setDisabled(b);
ui->ssid->setDisabled(b);
if (ui->None->isChecked())
{
ui->pwd->setDisabled(true);
}
else ui->pwd->setDisabled(b);
ui->update->setDisabled(b);
}
bool MainWindow::checkData()
{
if (ui->ssid->text()==NULL && ((!ui->None->isChecked()) && ui->pwd->text()==NULL) )
{
QMessageBox::warning(
this,
tr("Application Name"),
tr("No SSID & No password") );
return false;
}
else if ((!ui->None->isChecked()) && ui->pwd->text()==NULL)
{
QMessageBox::warning(
this,
tr("Application Name"),
tr("Empty password") );
return false;
}
else if (ui->ssid->text()==NULL)
{
QMessageBox::warning(
this,
tr("Application Name"),
tr("No SSID") );
return false;
}
else return true;
}
void MainWindow::displayError(const char val)
{
QString str;
switch (val)
{
case '0':
str="Ok";
break;
case '1':
str="SSID Length";
break;
case '2':
str="Pass length";
break;
case '3':
str="Encrypt mode";
break;
case '4':
str="NEW AP";
break;
case '5':
str="Error saving";
break;
case '6':
str="Timeout";
break;
case '7':
str="no config saved to restore";
break;
case '8':
str="could not get an IP";
break;
case '9':
str="could not get the adress of the backend";
break;
case 'a':
str="could not ping the backend";
break;
case 'b':
str="timeout2";
break;
case 'c':
str="settinf profile fail";
break;
}
ui->statusBar->showMessage(str);
}
void MainWindow::sendConfig()
{
sending=true;
if (t2->isFinished())
{
t2->start();
}
if (checkData())
{
lockui(true);
//TryConnect();
QString ssid=ui->ssid->text();
QString pwd=ui->pwd->text();
QByteArray SSID=ssid.toUtf8();
QByteArray PWD=pwd.toUtf8();
QByteArray ENCRYPTION=getIndex().toUtf8();
emit SendMessage(portConnectedName,SSID,PWD,ENCRYPTION);
}
}
/*
QByteArray MainWindow::wait_for_response(int msec)
{
bool b=true;
QByteArray tmp;
serial->waitForReadyRead(msec);
while (b)
{
tmp=serial->read(1);
ui->statusBar->showMessage(tmp);
if (tmp=="#")
{
b=false;
}
}
return serial->readAll();
}
*/
QString MainWindow::getIndex()
{
QString i="0";
if (ui->None->isChecked())
{
i="0";
}
else if (ui->WEP->isChecked())
{
i="1";
}
else if (ui->WPA->isChecked())
{
i="2";
}
else if (ui->WPA2->isChecked())
{
i="3";
}
return i;
}
/*
void MainWindow::closeSerialPort()
{
serial->close();
//ui->statusBar->showMessage(tr("Disconnected"));
}
*/