forked from Ezurio/UwTerminalX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUwxMainWindow.cpp
More file actions
7290 lines (6716 loc) · 312 KB
/
UwxMainWindow.cpp
File metadata and controls
7290 lines (6716 loc) · 312 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
** Copyright (C) 2015-2016 Laird
**
** Project: UwTerminalX
**
** Module: UwxMainWindow.cpp
**
** Notes:
**
** License: This program is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see http://www.gnu.org/licenses/
**
*******************************************************************************/
/******************************************************************************/
// Include Files
/******************************************************************************/
#include "UwxMainWindow.h"
#include "ui_UwxMainWindow.h"
/******************************************************************************/
// Conditional Compile Defines
/******************************************************************************/
#ifdef QT_DEBUG
//Include debug output when compiled for debugging
#include <QDebug>
#endif
#ifdef _WIN32
//Windows
#define OS "Win"
#elif __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_MAC
//Mac OSX
#define OS "Mac"
QString gstrMacBundlePath;
#endif
#else
//Assume linux
#define OS "Linux"
#endif
/******************************************************************************/
// Local Functions or Private Members
/******************************************************************************/
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
//Setup the GUI
ui->setupUi(this);
#if TARGET_OS_MAC
//On mac, get the directory of the bundle (which will be <location>/Term.app/Contents/MacOS) and go up to the folder with the file in
QDir BundleDir(QCoreApplication::applicationDirPath());
BundleDir.cdUp();
BundleDir.cdUp();
BundleDir.cdUp();
gstrMacBundlePath = BundleDir.path().append("/");
if (!QDir().exists(QStandardPaths::writableLocation(QStandardPaths::DataLocation)))
{
//Create UwTerminalX directory in application support
QDir().mkdir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
}
//Fix mac's resize
resize(720, 360);
//Disable viewing files externally for mac
ui->btn_EditExternal->setEnabled(false);
//Increase duplicate button size for mac
ui->btn_Duplicate->setMinimumWidth(130);
#endif
#ifndef _WIN32
#ifndef __APPLE__
//Increase Linux window size to cope with possible large Linux fonts
resize(this->width()+50, this->height()+20);
#endif
#endif
#ifndef _WIN32
#ifdef __APPLE__
//Change size of text fonts for Mac
QFont fntTmpFnt(ui->label_PreXCompInfo->font());
fntTmpFnt.setPixelSize(12);
ui->label_PreXCompInfo->setFont(fntTmpFnt);
ui->label_OnlineXCompInfo->setFont(fntTmpFnt);
ui->label_UwTerminalXText->setFont(fntTmpFnt);
ui->label_ErrorCodeText->setFont(fntTmpFnt);
ui->label_AppFirmwareText1->setFont(fntTmpFnt);
ui->label_AppFirmwareText2->setFont(fntTmpFnt);
#else
//Change size of text fonts for Linux
QFont fntTmpFnt(ui->label_PreXCompInfo->font());
fntTmpFnt.setPixelSize(11);
ui->label_PreXCompInfo->setFont(fntTmpFnt);
ui->label_OnlineXCompInfo->setFont(fntTmpFnt);
ui->label_UwTerminalXText->setFont(fntTmpFnt);
ui->label_ErrorCodeText->setFont(fntTmpFnt);
ui->label_AppFirmwareText1->setFont(fntTmpFnt);
ui->label_AppFirmwareText2->setFont(fntTmpFnt);
#endif
#endif
//Define default variable values
gbTermBusy = false;
gbStreamingFile = false;
gintRXBytes = 0;
gintTXBytes = 0;
gintQueuedTXBytes = 0;
gchTermBusyLines = 0;
gchTermMode = 0;
gchTermMode2 = 0;
gbMainLogEnabled = false;
gbLoopbackMode = false;
gbSysTrayEnabled = false;
gbIsUWCDownload = false;
gbCTSStatus = 0;
gbDCDStatus = 0;
gbDSRStatus = 0;
gbRIStatus = 0;
gbStreamingBatch = false;
gbaBatchReceive.clear();
gbFileOpened = false;
gbEditFileModified = false;
giEditFileType = -1;
gbErrorsLoaded = false;
gbAutoBaud = false;
gnmManager = 0;
gtmrSpeedTestDelayTimer = 0;
gbSpeedTestRunning = false;
#ifndef SKIPAUTOMATIONFORM
guaAutomationForm = 0;
#endif
#ifndef SKIPERRORCODEFORM
gecErrorCodeForm = 0;
#else
ui->btn_Error->deleteLater();
#endif
#ifndef SKIPSCRIPTINGFORM
gbScriptingRunning = false;
gusScriptingForm = 0;
#endif
//Clear display buffer byte array.
gbaDisplayBuffer.clear();
//Load settings from configuration files
LoadSettings();
//Create logging handle
gpMainLog = new LrdLogger();
//Move to 'About' tab
ui->selector_Tab->setCurrentIndex(TabAbout);
//Set default values for combo boxes on 'Config' tab
ui->combo_Baud->setCurrentIndex(8);
ui->combo_Stop->setCurrentIndex(0);
ui->combo_Data->setCurrentIndex(1);
ui->combo_Handshake->setCurrentIndex(1);
//Load images
gimEmptyCircleImage = QImage(":/images/EmptyCircle.png");
gimRedCircleImage = QImage(":/images/RedCircle.png");
gimGreenCircleImage = QImage(":/images/GreenCircle.png");
#ifdef _WIN32
//Load ICOs for windows
gimUw16Image = QImage(":/images/UwTerminal16.ico");
gimUw32Image = QImage(":/images/UwTerminal32.ico");
#else
//Load PNGs for Linux/Mac
gimUw16Image = QImage(":/images/UwTerminal16.png");
gimUw32Image = QImage(":/images/UwTerminal32.png");
#endif
#ifndef UseSSL
//Disable SSL checkbox for non-SSL builds
ui->check_EnableSSL->setCheckable(false);
ui->check_EnableSSL->setChecked(false);
ui->check_EnableSSL->setEnabled(false);
#endif
//Create pixmaps
gpEmptyCirclePixmap = new QPixmap(QPixmap::fromImage(gimEmptyCircleImage));
gpRedCirclePixmap = new QPixmap(QPixmap::fromImage(gimRedCircleImage));
gpGreenCirclePixmap = new QPixmap(QPixmap::fromImage(gimGreenCircleImage));
gpUw16Pixmap = new QPixmap(QPixmap::fromImage(gimUw16Image));
gpUw32Pixmap = new QPixmap(QPixmap::fromImage(gimUw32Image));
//Show images on help
ui->label_AboutI1->setPixmap(*gpEmptyCirclePixmap);
ui->label_AboutI2->setPixmap(*gpRedCirclePixmap);
ui->label_AboutI3->setPixmap(*gpGreenCirclePixmap);
//Enable custom context menu policy
ui->text_TermEditData->setContextMenuPolicy(Qt::CustomContextMenu);
#ifdef _WIN32
//Connect process termination to signal
connect(&gprocCompileProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(process_finished(int, QProcess::ExitStatus)));
#endif
//Connect quit signals
connect(ui->btn_Decline, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->btn_Quit, SIGNAL(clicked()), this, SLOT(close()));
//Connect key-press signals
connect(ui->text_TermEditData, SIGNAL(EnterPressed()), this, SLOT(EnterPressed()));
connect(ui->text_TermEditData, SIGNAL(KeyPressed(QChar)), this, SLOT(KeyPressed(QChar)));
//Connect file drag/drop signal
connect(ui->text_TermEditData, SIGNAL(FileDropped(QString)), this, SLOT(DroppedFile(QString)));
//Initialise popup message
gpmErrorForm = new PopupMessage;
//Populate the list of devices
RefreshSerialDevices();
//Setup speed test mode timers
gtmrSpeedTestStats.setInterval(SpeedTestStatUpdateTime);
gtmrSpeedTestStats.setSingleShot(false);
connect(>mrSpeedTestStats, SIGNAL(timeout()), this, SLOT(UpdateSpeedTestValues()));
gtmrSpeedTestStats10s.setInterval(10000);
gtmrSpeedTestStats10s.setSingleShot(false);
connect(>mrSpeedTestStats10s, SIGNAL(timeout()), this, SLOT(OutputSpeedTestStats()));
//Display version
ui->statusBar->showMessage(QString("UwTerminalX")
#ifdef UseSSL
.append("-SSL")
#endif
.append(" version ").append(UwVersion).append(" (").append(OS).append("), Built ").append(__DATE__).append(" Using QT ").append(QT_VERSION_STR)
#ifdef QT_DEBUG
.append(" [DEBUG BUILD]")
#endif
);
setWindowTitle(QString("UwTerminalX (v").append(UwVersion).append(")"));
#pragma warning("TODO: Remove old configuration moving code for mac for v1.8 release")
#if TARGET_OS_MAC
//Check if old configuration files exist
if (gpTermSettings->value("OldConfigIgnore").isNull() || gpTermSettings->value("OldConfigIgnore").toInt() != 1)
{
if (QFile::exists(QString(gstrMacBundlePath).append("UwTerminalX.ini")) == true)
{
//Old config files present, ask user if they want them copied
QMessageBox mbMoveFiles;
mbMoveFiles.setText("Old UwTerminalX configuration found");
mbMoveFiles.setInformativeText("The UwTerminalX configuration is now stored in the Application Support directory (instead of in the same directory as UwTermiminalX).\r\nYou can either:\r\n \u2022Migrate the old configuration (Yes, UwTerminalX will restart)\r\n \u2022Ignore the old configuration and not be asked again (No)\r\n \u2022Choose next time UwTerminalX is opened (Ignore).");
mbMoveFiles.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Ignore);
mbMoveFiles.setDefaultButton(QMessageBox::Yes);
int intBtnClicked = mbMoveFiles.exec();
if (intBtnClicked == QMessageBox::Yes)
{
//Move files
delete gpTermSettings;
delete gpErrorMessages;
delete gpPredefinedDevice;
gbErrorsLoaded = false;
//Remove file
QFile::remove(QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/UwTerminalX.ini"));
//Rename other file. This will fail if the other file resides on another volume (unlikely)
QFile::rename(QString(gstrMacBundlePath).append("UwTerminalX.ini"), QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/UwTerminalX.ini"));
if (QFile::exists(QString(gstrMacBundlePath).append("codes.csv")) == true)
{
if (QFile::exists(QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/codes.csv")) == true)
{
//Remove file
QFile::remove(QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/codes.csv"));
}
//Rename other file. This will fail if the other file resides on another volume (unlikely)
QFile::rename(QString(gstrMacBundlePath).append("codes.csv"), QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/codes.csv"));
}
if (QFile::exists(QString(gstrMacBundlePath).append("Devices.ini")) == true)
{
if (QFile::exists(QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/Devices.ini")) == true)
{
//Remove file
QFile::remove(QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/Devices.ini"));
}
//Rename other file. This will fail if the other file resides on another volume (unlikely)
QFile::rename(QString(gstrMacBundlePath).append("Devices.ini"), QString(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).append("/Devices.ini"));
}
//Reload settings
LoadSettings();
}
else if (intBtnClicked == QMessageBox::No)
{
//Do not move files, mark as done in configuration
gpTermSettings->setValue(QString("OldConfigIgnore"), "1");
}
}
}
#endif
//Create menu items
gpMenu = new QMenu(this);
gpMenu->addAction("XCompile")->setData(MenuActionXCompile);
gpMenu->addAction("XCompile + Load")->setData(MenuActionXCompileLoad);
gpMenu->addAction("XCompile + Load + Run")->setData(MenuActionXCompileLoadRun);
gpMenu->addAction("Load")->setData(MenuActionLoad);
gpMenu->addAction("Load + Run")->setData(MenuActionLoadRun);
gpMenu->addAction("Lookup Selected Error-Code (Hex)")->setData(MenuActionErrorHex);
gpMenu->addAction("Lookup Selected Error-Code (Int)")->setData(MenuActionErrorInt);
gpMenu->addAction("Enable Loopback (Rx->Tx)")->setData(MenuActionLoopback);
gpSMenu1 = gpMenu->addMenu("Download");
gpSMenu2 = gpSMenu1->addMenu("BASIC");
gpSMenu2->addAction("Load Precompiled BASIC")->setData(MenuActionLoad2);
gpSMenu2->addAction("Erase File")->setData(MenuActionEraseFile);
gpSMenu2->addAction("Dir")->setData(MenuActionDir);
gpSMenu2->addAction("Run")->setData(MenuActionRun);
gpSMenu2->addAction("Debug")->setData(MenuActionDebug);
gpSMenu3 = gpSMenu1->addMenu("Data");
gpSMenu3->addAction("Data File +")->setData(MenuActionDataFile);
gpSMenu3->addAction("Erase File +")->setData(MenuActionEraseFile2);
gpSMenu3->addAction("Clear Filesystem")->setData(MenuActionClearFilesystem);
gpSMenu3->addAction("Multi Data File +")->setData(MenuActionMultiDataFile); //Downloads more than 1 data file
gpSMenu1->addAction("Stream File Out")->setData(MenuActionStreamFile);
gpMenu->addAction("Font")->setData(MenuActionFont);
gpMenu->addAction("Run")->setData(MenuActionRun2);
gpMenu->addAction("Automation")->setData(MenuActionAutomation);
gpMenu->addAction("Scripting")->setData(MenuActionScripting);
gpMenu->addAction("Batch")->setData(MenuActionBatch);
gpMenu->addAction("Clear module")->setData(MenuActionClearModule);
gpMenu->addAction("Clear Display")->setData(MenuActionClearDisplay);
gpMenu->addAction("Clear RX/TX count")->setData(MenuActionClearRxTx);
gpMenu->addSeparator();
gpMenu->addAction("Copy")->setData(MenuActionCopy);
gpMenu->addAction("Copy All")->setData(MenuActionCopyAll);
gpMenu->addAction("Paste")->setData(MenuActionPaste);
gpMenu->addAction("Select All")->setData(MenuActionSelectAll);
//Create balloon menu items
gpBalloonMenu = new QMenu(this);
gpBalloonMenu->addAction("Show UwTerminalX")->setData(BalloonActionShow);
gpBalloonMenu->addAction("Exit")->setData(BalloonActionExit);
//Create speed test button items
gpSpeedMenu = new QMenu(this);
gpSpeedMenu->addAction("Receive-only test")->setData(SpeedMenuActionRecv);
gpSpeedMenu->addAction("Send-only test")->setData(SpeedMenuActionSend);
gpSpeedMenu->addAction("Send && receive test")->setData(SpeedMenuActionSendRecv);
gpSpeedMenu->addAction("Send && receive test (delay 5 seconds)")->setData(SpeedMenuActionSendRecv5Delay);
gpSpeedMenu->addAction("Send && receive test (delay 10 seconds)")->setData(SpeedMenuActionSendRecv10Delay);
gpSpeedMenu->addAction("Send && receive test (delay 15 seconds)")->setData(SpeedMenuActionSendRecv15Delay);
//Disable unimplemented actions
gpSMenu3->actions()[3]->setEnabled(false); //Multi Data File +
#ifdef SKIPAUTOMATIONFORM
//Disable automation option
gpMenu->actions()[11]->setEnabled(false);
#endif
#ifdef SKIPSCRIPTINGFORM
//Disable scripting option
gpMenu->actions()[12]->setEnabled(false);
#endif
//Connect the menu actions
connect(gpMenu, SIGNAL(triggered(QAction*)), this, SLOT(MenuSelected(QAction*)), Qt::AutoConnection);
connect(gpMenu, SIGNAL(aboutToHide()), this, SLOT(ContextMenuClosed()), Qt::AutoConnection);
connect(gpBalloonMenu, SIGNAL(triggered(QAction*)), this, SLOT(balloontriggered(QAction*)), Qt::AutoConnection);
connect(gpSpeedMenu, SIGNAL(triggered(QAction*)), this, SLOT(SpeedMenuSelected(QAction*)), Qt::AutoConnection);
//Configure the module timeout timer
gtmrDownloadTimeoutTimer.setSingleShot(true);
gtmrDownloadTimeoutTimer.setInterval(ModuleTimeout);
connect(>mrDownloadTimeoutTimer, SIGNAL(timeout()), this, SLOT(DevRespTimeout()));
//Configure the signal timer
gpSignalTimer = new QTimer(this);
connect(gpSignalTimer, SIGNAL(timeout()), this, SLOT(SerialStatusSlot()));
//Connect serial signals
connect(&gspSerialPort, SIGNAL(readyRead()), this, SLOT(SerialRead()));
connect(&gspSerialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(SerialError(QSerialPort::SerialPortError)));
connect(&gspSerialPort, SIGNAL(bytesWritten(qint64)), this, SLOT(SerialBytesWritten(qint64)));
connect(&gspSerialPort, SIGNAL(aboutToClose()), this, SLOT(SerialPortClosing()));
//Set update text display timer to be single shot only and connect to slot
gtmrTextUpdateTimer.setSingleShot(true);
gtmrTextUpdateTimer.setInterval(gpTermSettings->value("TextUpdateInterval", DefaultTextUpdateInterval).toInt());
connect(>mrTextUpdateTimer, SIGNAL(timeout()), this, SLOT(UpdateReceiveText()));
//Set update speed display timer to be single shot only and connect to slot
gtmrSpeedUpdateTimer.setSingleShot(true);
gtmrSpeedUpdateTimer.setInterval(gpTermSettings->value("TextUpdateInterval", DefaultTextUpdateInterval).toInt());
connect(>mrSpeedUpdateTimer, SIGNAL(timeout()), this, SLOT(UpdateDisplayText()));
//Setup timer for batch file timeout
gtmrBatchTimeoutTimer.setSingleShot(true);
connect(>mrBatchTimeoutTimer, SIGNAL(timeout()), this, SLOT(BatchTimeoutSlot()));
//Setup timer for automatic baud rate detection
gtmrBaudTimer.setSingleShot(true);
gtmrBaudTimer.setInterval(AutoBaudTimeout);
connect(>mrBaudTimer, SIGNAL(timeout()), this, SLOT(DetectBaudTimeout()));
//Set logging options
ui->edit_LogFile->setText(gpTermSettings->value("LogFile", DefaultLogFile).toString());
ui->check_LogEnable->setChecked(gpTermSettings->value("LogEnable", DefaultLogEnable).toBool());
ui->check_LogAppend->setChecked(gpTermSettings->value("LogMode", DefaultLogMode).toBool());
#ifdef UseSSL
//Set SSL status
ui->check_EnableSSL->setChecked(gpTermSettings->value("SSLEnable", DefaultSSLEnable).toBool());
if (ui->check_EnableSSL->isChecked() == true)
{
//HTTPS
WebProtocol = "https";
}
else
{
//HTTP
WebProtocol = "http";
}
#endif
//Set showing filesize option
ui->check_ShowFileSize->setChecked(gpTermSettings->value("ShowFileSize", DefaultShowFileSize).toBool());
//Set clearing confirmation option
ui->check_ConfirmClear->setChecked(gpTermSettings->value("ConfirmClear", DefaultConfirmClear).toBool());
//Check if default devices were created
if (gpPredefinedDevice->value("DoneSetup").isNull())
{
//Create default device configurations... BT900
gpPredefinedDevice->setValue(QString("Port1Name"), "BT900");
gpPredefinedDevice->setValue(QString("Port1Baud"), "115200");
gpPredefinedDevice->setValue(QString("Port1Parity"), "0");
gpPredefinedDevice->setValue(QString("Port1Stop"), "1");
gpPredefinedDevice->setValue(QString("Port1Data"), "8");
gpPredefinedDevice->setValue(QString("Port1Flow"), "1");
//BL600/BL620
gpPredefinedDevice->setValue(QString("Port2Name"), "BL600/BL620");
gpPredefinedDevice->setValue(QString("Port2Baud"), "9600");
gpPredefinedDevice->setValue(QString("Port2Parity"), "0");
gpPredefinedDevice->setValue(QString("Port2Stop"), "1");
gpPredefinedDevice->setValue(QString("Port2Data"), "8");
gpPredefinedDevice->setValue(QString("Port2Flow"), "1");
//BL620-US
gpPredefinedDevice->setValue(QString("Port3Name"), "BL620-US");
gpPredefinedDevice->setValue(QString("Port3Baud"), "9600");
gpPredefinedDevice->setValue(QString("Port3Parity"), "0");
gpPredefinedDevice->setValue(QString("Port3Stop"), "1");
gpPredefinedDevice->setValue(QString("Port3Data"), "8");
gpPredefinedDevice->setValue(QString("Port3Flow"), "0");
//BL652
gpPredefinedDevice->setValue(QString("Port4Name"), "BL652");
gpPredefinedDevice->setValue(QString("Port4Baud"), "115200");
gpPredefinedDevice->setValue(QString("Port4Parity"), "0");
gpPredefinedDevice->setValue(QString("Port4Stop"), "1");
gpPredefinedDevice->setValue(QString("Port4Data"), "8");
gpPredefinedDevice->setValue(QString("Port4Flow"), "1");
//RM186/RM191
gpPredefinedDevice->setValue(QString("Port5Name"), "RM186/RM191");
gpPredefinedDevice->setValue(QString("Port5Baud"), "115200");
gpPredefinedDevice->setValue(QString("Port5Parity"), "0");
gpPredefinedDevice->setValue(QString("Port5Stop"), "1");
gpPredefinedDevice->setValue(QString("Port5Data"), "8");
gpPredefinedDevice->setValue(QString("Port5Flow"), "1");
//Mark as completed
gpPredefinedDevice->setValue(QString("DoneSetup"), "1");
}
//Add predefined devices
unsigned char i = 1;
while (i < 255)
{
if (gpPredefinedDevice->value(QString("Port").append(QString::number(i)).append("Name")).isNull())
{
break;
}
ui->combo_PredefinedDevice->addItem(gpPredefinedDevice->value(QString("Port").append(QString::number(i)).append("Name")).toString());
++i;
}
//Load settings from first device
if (ui->combo_PredefinedDevice->count() > 0)
{
on_combo_PredefinedDevice_currentIndexChanged(ui->combo_PredefinedDevice->currentIndex());
}
//Add tooltips
ui->check_SkipDL->setToolTip("Enable this to skip displaying the commands sent/received to the module when downloading a file to it.");
ui->check_ShowCLRF->setToolTip("Enable this to escape various characters (CR will show as \\r, LF will show as \\n and Tab will show as \\t).");
ui->check_EnableSSL->setToolTip("Enable this to use HTTPS (SSL) when communicating with UwTerminalX server (when updating or compiling applications), otherwise uses plaintext HTTP.");
ui->check_ShowFileSize->setToolTip("Enable this to see the filesize of compiled applications.");
ui->check_ConfirmClear->setToolTip("Enable this in order to confirm clearing the filesystem or resetting the module configuration to factory settings.");
ui->check_LineSeparator->setToolTip("When enabled, pressing shit+enter in the terminal will create a line separator allowing for multiple lines to be sent when enter is pressed. If disabled then shift+enter will behave the same as pressing enter and send the line.");
//Give focus to accept button
if (ui->btn_Accept->isEnabled() == true)
{
ui->btn_Accept->setFocus();
}
//Enable system tray if it's available and enabled
if (gpTermSettings->value("SysTrayIcon", DefaultSysTrayIcon).toBool() == true && QSystemTrayIcon::isSystemTrayAvailable())
{
//System tray enabled and available on system, set it up with contect menu/icon and show it
gpSysTray = new QSystemTrayIcon;
gpSysTray->setContextMenu(gpBalloonMenu);
gpSysTray->setIcon(QIcon(*gpUw16Pixmap));
gpSysTray->show();
gbSysTrayEnabled = true;
}
//Update pre/post XCompile executable options
ui->check_PreXCompRun->setChecked(gpTermSettings->value("PrePostXCompRun", DefaultPrePostXCompRun).toBool());
ui->check_PreXCompFail->setChecked(gpTermSettings->value("PrePostXCompFail", DefaultPrePostXCompFail).toBool());
if (gpTermSettings->value("PrePostXCompMode", DefaultPrePostXCompMode).toInt() == 1)
{
//Post-XCompiler run
ui->radio_XCompPost->setChecked(true);
}
else
{
//Pre-XCompiler run
ui->radio_XCompPre->setChecked(true);
}
ui->edit_PreXCompFilename->setText(gpTermSettings->value("PrePostXCompPath", DefaultPrePostXCompPath).toString());
//Load skip download display setting
ui->check_SkipDL->setChecked(gpTermSettings->value("SkipDownloadDisplay", DefaultSkipDownloadDisplay).toBool());
//Load line separator setting
ui->check_LineSeparator->setChecked(gpTermSettings->value("ShiftEnterLineSeparator", DefaultShiftEnterLineSeparator).toBool());
//Notify scroll edit area of line separator value
ui->text_TermEditData->mbLineSeparator = ui->check_LineSeparator->isChecked();
//Update GUI for pre/post XComp executable
on_check_PreXCompRun_stateChanged(ui->check_PreXCompRun->isChecked()*2);
//Set Online XCompilation mode
#ifdef _WIN32
//Windows
ui->label_OnlineXCompInfo->setText("By enabling Online XCompilation support, if a local XCompiler is not found the source code will be uploaded and compiled remotely on a Laird cloud server. Uploaded data is not stored by Laird.");
#else
//Mac or Linux
ui->label_OnlineXCompInfo->setText("By enabling Online XCompilation support, when compiling an application, the source data will be uploadeda and compiled remotely on a Laird cloud server. Uploaded data is not stored by Laird.");
#endif
ui->check_OnlineXComp->setChecked(gpTermSettings->value("OnlineXComp", DefaultOnlineXComp).toBool());
//Load last directory path
gstrLastFilename[FilenameIndexApplication] = gpTermSettings->value("LastFileDirectory", "").toString();
gstrLastFilename[FilenameIndexOthers] = gpTermSettings->value("LastOtherFileDirectory", "").toString();
//Refresh list of log files
on_btn_LogRefresh_clicked();
//Change terminal font to a monospaced font
#pragma warning("TODO: Revert manual font selection when QTBUG-54623 is fixed")
#ifdef _WIN32
QFont fntTmpFnt2 = QFontDatabase::systemFont(QFontDatabase::FixedFont);
#elif __APPLE__
QFont fntTmpFnt2 = QFontDatabase::systemFont(QFontDatabase::FixedFont);
#else
//Fix for qt bug
QFont fntTmpFnt2 = QFont("monospace");
#endif
QFontMetrics tmTmpFM(fntTmpFnt2);
ui->text_TermEditData->setFont(fntTmpFnt2);
ui->text_TermEditData->setTabStopWidth(tmTmpFM.width(" ")*6);
ui->text_LogData->setFont(fntTmpFnt2);
ui->text_LogData->setTabStopWidth(tmTmpFM.width(" ")*6);
ui->text_SpeedEditData->setFont(fntTmpFnt2);
ui->text_SpeedEditData->setTabStopWidth(tmTmpFM.width(" ")*6);
//Set resolved hostname to be empty
gstrResolvedServer = "";
#ifdef UseSSL
//Load SSL certificate
QFile certFile(":/certificates/UwTerminalX.crt");
if (certFile.open(QIODevice::ReadOnly))
{
//Load certificate data
sslcLairdSSL = new QSslCertificate(certFile.readAll());
QSslSocket::addDefaultCaCertificate(*sslcLairdSSL);
certFile.close();
}
certFile.setFileName(":/certificates/UwTerminalX_new.crt");
if (certFile.open(QIODevice::ReadOnly))
{
//Load certificate data
sslcLairdSSLNew = new QSslCertificate(certFile.readAll());
QSslSocket::addDefaultCaCertificate(*sslcLairdSSLNew);
certFile.close();
}
#endif
//Check command line
QStringList slArgs = QCoreApplication::arguments();
unsigned char chi = 1;
bool bArgCom = false;
bool bArgAccept = false;
bool bArgNoConnect = false;
bool bStartScript = false;
while (chi < slArgs.length())
{
if (slArgs[chi].toUpper() == "ACCEPT")
{
//Skip the front panel - disable buttons
ui->btn_Accept->setEnabled(false);
ui->btn_Decline->setEnabled(false);
//Switch to config tab
ui->selector_Tab->setCurrentIndex(TabConfig);
//Default empty images
ui->image_CTS->setPixmap(*gpEmptyCirclePixmap);
ui->image_DCD->setPixmap(*gpEmptyCirclePixmap);
ui->image_DSR->setPixmap(*gpEmptyCirclePixmap);
ui->image_RI->setPixmap(*gpEmptyCirclePixmap);
ui->image_CTSb->setPixmap(*gpEmptyCirclePixmap);
ui->image_DCDb->setPixmap(*gpEmptyCirclePixmap);
ui->image_DSRb->setPixmap(*gpEmptyCirclePixmap);
ui->image_RIb->setPixmap(*gpEmptyCirclePixmap);
bArgAccept = true;
}
else if (slArgs[chi].left(4).toUpper() == "COM=")
{
//Set com port
QString strPort = slArgs[chi].right(slArgs[chi].length()-4);
#ifdef _WIN32
if (strPort.left(3) != "COM")
{
//Prepend COM for UwTerminal shortcut compatibility
strPort.prepend("COM");
}
#endif
ui->combo_COM->setCurrentText(strPort);
bArgCom = true;
//Update serial port info
on_combo_COM_currentIndexChanged(0);
}
else if (slArgs[chi].left(5).toUpper() == "BAUD=")
{
//Set baud rate
ui->combo_Baud->setCurrentText(slArgs[chi].right(slArgs[chi].length()-5));
}
else if (slArgs[chi].left(5).toUpper() == "STOP=")
{
//Set stop bits
if (slArgs[chi].right(1) == "1")
{
//One
ui->combo_Stop->setCurrentIndex(0);
}
else if (slArgs[chi].right(1) == "2")
{
//Two
ui->combo_Stop->setCurrentIndex(1);
}
}
else if (slArgs[chi].left(5).toUpper() == "DATA=")
{
//Set data bits
if (slArgs[chi].right(1) == "7")
{
//Seven
ui->combo_Data->setCurrentIndex(0);
}
else if (slArgs[chi].right(1).toUpper() == "8")
{
//Eight
ui->combo_Data->setCurrentIndex(1);
}
}
else if (slArgs[chi].left(4).toUpper() == "PAR=")
{
//Set parity
if (slArgs[chi].right(1).toInt() >= 0 && slArgs[chi].right(1).toInt() < 3)
{
ui->combo_Parity->setCurrentIndex(slArgs[chi].right(1).toInt());
}
}
else if (slArgs[chi].left(5).toUpper() == "FLOW=")
{
//Set flow control
if (slArgs[chi].right(1).toInt() >= 0 && slArgs[chi].right(1).toInt() < 3)
{
//Valid
ui->combo_Handshake->setCurrentIndex(slArgs[chi].right(1).toInt());
}
}
else if (slArgs[chi].left(7).toUpper() == "ENDCHR=")
{
//Sets the end of line character
if (slArgs[chi].right(1) == "0")
{
//CR
ui->radio_LCR->setChecked(true);
}
else if (slArgs[chi].right(1) == "1")
{
//LF
ui->radio_LLF->setChecked(true);
}
else if (slArgs[chi].right(1) == "2")
{
//CRLF
ui->radio_LCRLF->setChecked(true);
}
else if (slArgs[chi].right(1) == "3")
{
//LFCR
ui->radio_LLFCR->setChecked(true);
}
}
else if (slArgs[chi].left(10).toUpper() == "LOCALECHO=")
{
//Enable or disable local echo
if (slArgs[chi].right(1) == "0")
{
//Off
ui->check_Echo->setChecked(false);
}
else if (slArgs[chi].right(1) == "1")
{
//On (default)
ui->check_Echo->setChecked(true);
}
}
else if (slArgs[chi].left(9).toUpper() == "LINEMODE=")
{
//Enable or disable line mode
if (slArgs[chi].right(1) == "0")
{
//Off
ui->check_Line->setChecked(false);
on_check_Line_stateChanged();
}
else if (slArgs[chi].right(1) == "1")
{
//On (default)
ui->check_Line->setChecked(true);
on_check_Line_stateChanged();
}
}
else if (slArgs[chi].toUpper() == "LOG")
{
//Enables logging
ui->check_LogEnable->setChecked(true);
}
else if (slArgs[chi].toUpper() == "LOG+")
{
//Enables appending to the previous log file instead of erasing
ui->check_LogAppend->setChecked(true);
}
else if (slArgs[chi].left(4).toUpper() == "LOG=")
{
//Specifies log filename
ui->edit_LogFile->setText(slArgs[chi].mid(4, -1));
}
else if (slArgs[chi].toUpper() == "SHOWCRLF")
{
//Displays \t, \r, \n etc. as \t, \r, \n instead of [tab], [new line], [carriage return]
ui->check_ShowCLRF->setChecked(true);
}
else if (slArgs[chi].toUpper() == "NOCONNECT")
{
//Connect to device at startup
bArgNoConnect = true;
}
#ifndef SKIPAUTOMATIONFORM
else if (slArgs[chi].toUpper() == "AUTOMATION" && bArgAccept == true)
{
//Show automation window
if (guaAutomationForm == 0)
{
//Initialise automation popup
guaAutomationForm = new UwxAutomation(this);
//Populate window handles for automation object
guaAutomationForm->SetPopupHandle(gpmErrorForm);
//Update automation form with connection status
guaAutomationForm->ConnectionChange(gspSerialPort.isOpen());
//Connect signals
connect(guaAutomationForm, SIGNAL(SendData(QString,bool,bool)), this, SLOT(MessagePass(QString,bool,bool)));
//Give focus to the first line
guaAutomationForm->SetFirstLineFocus();
//Show form
guaAutomationForm->show();
}
}
else if (slArgs[chi].left(15).toUpper() == "AUTOMATIONFILE=")
{
//Load automation file
if (guaAutomationForm == 0)
{
//Initialise automation popup
guaAutomationForm = new UwxAutomation(this);
//Populate window handles for automation object
guaAutomationForm->SetPopupHandle(gpmErrorForm);
//Update automation form with connection status
guaAutomationForm->ConnectionChange(gspSerialPort.isOpen());
//Connect signals
connect(guaAutomationForm, SIGNAL(SendData(QString,bool,bool)), this, SLOT(MessagePass(QString,bool,bool)));
}
//Load file
guaAutomationForm->LoadFile(slArgs[chi].right(slArgs[chi].size()-15));
}
#endif
#ifndef SKIPSCRIPTINGFORM
else if (slArgs[chi].toUpper() == "SCRIPTING" && bArgAccept == true)
{
//Show scripting window
if (gusScriptingForm == 0)
{
//Initialise scripting form
gusScriptingForm = new UwxScripting(this);
//Populate window handles for automation object
gusScriptingForm->SetPopupHandle(gpmErrorForm);
//Send the UwTerminalX version string
gusScriptingForm->SetUwTerminalXVersion(UwVersion);
//Connect the message passing signal and slot
connect(gusScriptingForm, SIGNAL(SendData(QString,bool,bool)), this, SLOT(MessagePass(QString,bool,bool)));
connect(gusScriptingForm, SIGNAL(ScriptStartRequest()), this, SLOT(ScriptStartRequest()));
connect(gusScriptingForm, SIGNAL(ScriptFinished()), this, SLOT(ScriptFinished()));
if (gspSerialPort.isOpen())
{
//Tell the form that the serial port is open
gusScriptingForm->SerialPortStatus(true);
}
//Show form
gusScriptingForm->show();
gusScriptingForm->SetEditorFocus();
}
}
else if (slArgs[chi].left(11).toUpper() == "SCRIPTFILE=")
{
//Load a script file
if (gusScriptingForm != 0)
{
QString strFilename = slArgs[chi].right(slArgs[chi].size()-11);
gusScriptingForm->LoadScriptFile(&strFilename);
}
}
else if (slArgs[chi].left(13).toUpper() == "SCRIPTACTION=")
{
//Action for scripting form
if (slArgs[chi].right(slArgs[chi].size()-13) == "1" && gusScriptingForm != 0)
{
//Enable script execution
bStartScript = true;
}
}
#endif
++chi;
}
if (bArgAccept == true && bArgCom == true && bArgNoConnect == false)
{
//Enough information to connect!
OpenDevice();
if (bStartScript == true)
{
//Start script execution request
ScriptStartRequest();
}
}
#if __APPLE__
//Show a warning to Mac users with the FTDI driver installed
if ((QFile::exists("/System/Library/Extensions/FTDIUSBSerialDriver.kext") || QFile::exists("/Library/Extensions/FTDIUSBSerialDriver.kext")) && gpTermSettings->value("MacFTDIDriverWarningShown").isNull())
{
//FTDI driver detected and warning has not been shown, show warning
gpTermSettings->setValue("MacFTDIDriverWarningShown", 1);
QString strMessage = tr("Warning: The Mac FTDI VCP driver has been detected on your system. There is a known issue with this driver that can cause your system to crash if the serial port is closed and the buffer is not empty.\r\n\r\nIf you experience this issue, it is recommended that you remove the FTDI driver and use the apple VCP driver instead. Instructions to do this are available from the FTDI website (follow the uninstall section): http://www.ftdichip.com/Support/Documents/AppNotes/AN_134_FTDI_Drivers_Installation_Guide_for_MAC_OSX.pdf\r\n\r\nThis message will not be shown again.");
gpmErrorForm->show();
gpmErrorForm->SetMessage(&strMessage);
}
#endif
}
//=============================================================================
//=============================================================================
MainWindow::~MainWindow(){
//Disconnect all signals
#ifdef _WIN32
disconnect(this, SLOT(process_finished(int, QProcess::ExitStatus)));
#endif
disconnect(this, SLOT(close()));
disconnect(this, SLOT(EnterPressed()));
disconnect(this, SLOT(KeyPressed(QChar)));
disconnect(this, SLOT(DroppedFile(QString)));
disconnect(this, SLOT(MenuSelected(QAction*)));
disconnect(this, SLOT(balloontriggered(QAction*)));
disconnect(this, SLOT(ContextMenuClosed()));
disconnect(this, SLOT(DevRespTimeout()));
disconnect(this, SLOT(SerialStatusSlot()));
disconnect(this, SLOT(SerialRead()));
disconnect(this, SLOT(SerialError(QSerialPort::SerialPortError)));
disconnect(this, SLOT(SerialBytesWritten(qint64)));
disconnect(this, SLOT(UpdateReceiveText()));
disconnect(this, SLOT(UpdateDisplayText()));
disconnect(this, SLOT(SerialPortClosing()));
disconnect(this, SLOT(BatchTimeoutSlot()));
disconnect(this, SLOT(replyFinished(QNetworkReply*)));
disconnect(this, SLOT(DetectBaudTimeout()));
disconnect(this, SLOT(MessagePass(QString,bool,bool)));
disconnect(this, SLOT(UpdateSpeedTestValues()));
disconnect(this, SLOT(OutputSpeedTestStats()));
if (gtmrSpeedTestDelayTimer != 0)
{
if (gtmrSpeedTestDelayTimer->isActive())
{
//Stop timer
gtmrSpeedTestDelayTimer->stop();
}
//Disconnect slots and delete timer
disconnect(this, SLOT(SpeedTestStartTimer()));
disconnect(this, SLOT(SpeedTestStopTimer()));
delete gtmrSpeedTestDelayTimer;
}
if (gspSerialPort.isOpen() == true)
{
//Close serial connection before quitting
gspSerialPort.close();
gpSignalTimer->stop();
}
if (gbMainLogEnabled == true)
{
//Close main log file before quitting
gpMainLog->CloseLogFile();
}
//Close popups if open
if (gpmErrorForm->isVisible())
{
//Close warning message
gpmErrorForm->close();
}
#ifndef SKIPAUTOMATIONFORM
if (guaAutomationForm != 0)
{
if (guaAutomationForm->isVisible())
{
//Close automation form
guaAutomationForm->close();
}
delete guaAutomationForm;
}
#endif
#ifndef SKIPSCRIPTINGFORM
if (gusScriptingForm != 0)
{
if (gusScriptingForm->isVisible())
{
//Close scripting form
gusScriptingForm->close();
}