-
Notifications
You must be signed in to change notification settings - Fork 19
/
UwxMainWindow.cpp
9837 lines (9054 loc) · 426 KB
/
UwxMainWindow.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
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-2023 Laird Connectivity
**
** 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/
**
** SPDX-License-Identifier: GPL-3.0
**
*******************************************************************************/
/******************************************************************************/
// Include Files
/******************************************************************************/
#include "UwxMainWindow.h"
#include "ui_UwxMainWindow.h"
/******************************************************************************/
// Defines
/******************************************************************************/
#ifdef RESOLVEIPSEPARATELY
#define WEB_HOST_NAME gstrResolvedServer
#else
#define WEB_HOST_NAME gpTermSettings->value("OnlineXCompServer", ServerHost).toString()
#endif
/******************************************************************************/
// Conditional Compile Defines
/******************************************************************************/
#ifdef QT_DEBUG
//Include debug output when compiled for debugging
#include <QDebug>
#endif
#ifdef _WIN32
//Windows
#ifdef _WIN64
//Windows 64-bit
#define OS "Windows (x86_64)"
#else
//Windows 32-bit
#define OS "Windows (x86)"
#endif
#elif defined(__APPLE__)
#include "TargetConditionals.h"
#ifdef TARGET_OS_MAC
//Mac OSX
#define OS "Mac"
QString gstrMacBundlePath;
#endif
#else
//Assume Linux
#ifdef __aarch64__
//ARM64
#define OS "Linux (AArch64)"
#elif __arm__
//ARM
#define OS "Linux (ARM)"
#elif __x86_64__
//x86_64
#define OS "Linux (x86_64)"
#elif __i386
//x86
#define OS "Linux (x86)"
#else
//Unknown
#define OS "Linux (other)"
#endif
#endif
//Functions used for sorting local XCompiler versions
#ifdef _WIN32
bool
CompByATI3(
const XCompInfoStruct &a,
const XCompInfoStruct &b
);
bool
CompByDevName(
const XCompDevStruct &a,
const XCompDevStruct &b
);
#endif
/******************************************************************************/
// Local Functions or Private Members
/******************************************************************************/
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
//Setup the GUI
ui->setupUi(this);
#if SKIPSPEEDTEST == 1
//Delete speed test elements to reduce RAM usage
ui->tab_SpeedTest->setEnabled(false);
ui->edit_SpeedBytesRec->deleteLater();
ui->edit_SpeedBytesRec10s->deleteLater();
ui->edit_SpeedBytesRecAvg->deleteLater();
ui->edit_SpeedBytesSent->deleteLater();
ui->edit_SpeedBytesSent10s->deleteLater();
ui->edit_SpeedBytesSentAvg->deleteLater();
ui->edit_SpeedPacketsBad->deleteLater();
ui->edit_SpeedPacketsErrorRate->deleteLater();
ui->edit_SpeedPacketsGood->deleteLater();
ui->edit_SpeedPacketsRec->deleteLater();
ui->edit_SpeedTestData->deleteLater();
ui->text_SpeedEditData->deleteLater();
ui->combo_SpeedDataDisplay->deleteLater();
ui->combo_SpeedDataType->deleteLater();
ui->check_SpeedDTR->deleteLater();
ui->check_SpeedRTS->deleteLater();
ui->check_SpeedShowErrors->deleteLater();
ui->check_SpeedShowRX->deleteLater();
ui->check_SpeedShowTX->deleteLater();
ui->check_SpeedStringUnescape->deleteLater();
ui->check_SpeedSyncReceive->deleteLater();
ui->btn_SpeedClear->deleteLater();
ui->btn_SpeedClose->deleteLater();
ui->btn_SpeedCopy->deleteLater();
ui->btn_SpeedStartStop->deleteLater();
ui->tab_SpeedTest->deleteLater();
#endif
//Output build information
#if SKIPAUTOMATIONFORM == 1 || SKIPERRORCODEFORM == 1 || SKIPSCRIPTINGFORM == 1 || SKIPSPEEDTEST == 1
ui->text_Terms->appendPlainText("");
#endif
#if SKIPAUTOMATIONFORM == 1
ui->text_Terms->appendPlainText("[Built without Automation support]");
#endif
#if SKIPERRORCODEFORM == 1
ui->text_Terms->appendPlainText("[Built without Error code form]");
#endif
#if SKIPSCRIPTINGFORM == 1
ui->text_Terms->appendPlainText("[Built without Scripting support]");
#endif
#if SKIPSPEEDTEST == 1
ui->text_Terms->appendPlainText("[Built without Speed test support]");
#endif
#ifdef 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(740, 400);
//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
//Disable local XCompiler information button
ui->btn_Local_XCompilers->setEnabled(false);
ui->btn_Local_XCompilers->deleteLater();
#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;
#if SKIPSPEEDTEST != 1
gtmrSpeedTestDelayTimer = 0;
gbSpeedTestRunning = false;
#endif
gupdUpdateCheck = UpdateCheckTypes::TypeNone;
gstrUpdateCheckString = 0;
#ifndef SKIPAUTOMATIONFORM
guaAutomationForm = 0;
#endif
gupcPredefinedCommandsForm = 0;
#ifndef SKIPERRORCODEFORM
gecErrorCodeForm = 0;
#else
ui->btn_Error->deleteLater();
#endif
#ifndef SKIPSCRIPTINGFORM
gbScriptingRunning = false;
gusScriptingForm = 0;
#endif
gbAppStarted = false;
//Clear display buffer byte array and reserve 128KB of RAM to reduce mallocs (should allow faster speed testing at 1M baud)
gbaDisplayBuffer.clear();
gbaDisplayBuffer.reserve(131072);
//Load settings from configuration files
LoadSettings();
//Create logging handle
gpMainLog = new LrdLogger();
//Move to 'About' tab
ui->selector_Tab->setCurrentIndex(ui->selector_Tab->indexOf(ui->tab_About));
//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)));
connect(&gprocCompileProcess, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(process_error(QProcess::ProcessError)));
#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(int,QChar)), this, SLOT(KeyPressed(int,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();
#if SKIPSPEEDTEST != 1
//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()));
#endif
//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 UseSSL
#ifdef TARGET_OS_MAC
.append(", ").append(QString(QSslSocket::sslLibraryBuildVersionString()).replace(",", ":"))
#else
.append(", ").append(QString(QSslSocket::sslLibraryBuildVersionString()).left(QSslSocket::sslLibraryBuildVersionString().indexOf(" ", 9)))
#endif
#endif
#ifdef QT_DEBUG
.append(" [DEBUG BUILD]")
#endif
);
setWindowTitle(QString("UwTerminalX (v").append(UwVersion).append(")"));
//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);
gpSMenu4 = gpMenu->addMenu("Customisation");
gpSMenu4->addAction("Font")->setData(MenuActionFont);
gpSMenu4->addAction("Text Colour")->setData(MenuActionTextColour);
gpSMenu4->addAction("Background Colour")->setData(MenuActionBackground);
gpSMenu4->addAction("Restore Defaults")->setData(MenuActionRestoreDefaults);
gpMenu->addAction("Run")->setData(MenuActionRun2);
gpMenu->addAction("Predefined Commands")->setData(MenuActionPredefinedCommands);
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);
#if SKIPSPEEDTEST != 1
//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);
#endif
//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
#if defined(TARGET_OS_MAC) || (defined(SKIPUSBRECOVERY) && SKIPUSBRECOVERY == 1)
//Remove exit autorun button on mac
ui->btn_ExitAutorun->deleteLater();
#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);
#if SKIPSPEEDTEST != 1
connect(gpSpeedMenu, SIGNAL(triggered(QAction*)), this, SLOT(SpeedMenuSelected(QAction*)), Qt::AutoConnection);
#endif
//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(errorOccurred(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()));
#if SKIPSPEEDTEST != 1
//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()));
#endif
//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());
//Set license checking option
ui->check_CheckLicense->setChecked(gpTermSettings->value("LicenseCheck", DefaultLicenceCheckMode).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());
//Set window size saving
ui->check_EnableTerminalSizeSaving->setChecked(gpTermSettings->value("SaveSize", DefaultSaveSize).toBool());
if (ui->check_EnableTerminalSizeSaving->isChecked() && gpTermSettings->contains("WindowWidth") && gpTermSettings->contains("WindowHeight"))
{
//Restore window size
this->resize(gpTermSettings->value("WindowWidth", this->width()).toUInt(), gpTermSettings->value("WindowHeight", this->height()).toUInt());
}
//Check if default devices were created
if (gpPredefinedDevice->value("DoneSetup").isNull())
{
//Create default device configurations... BL65x
uint8_t nCurrentDevice = 1;
QString strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "BL65x");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "115200");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "1");
++nCurrentDevice;
//Lyra
strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "Lyra");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "115200");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "1");
++nCurrentDevice;
//Pinnacle 100
strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "Pinnacle 100");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "115200");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "1");
++nCurrentDevice;
//RM1xx
strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "RM1xx");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "115200");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "1");
++nCurrentDevice;
//BT900
strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "BT900");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "115200");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "1");
++nCurrentDevice;
//BL600/BL620
strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "BL600/BL620");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "9600");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "1");
++nCurrentDevice;
//BL620-US
strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "BL620-US");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "9600");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "0");
++nCurrentDevice;
//Vela IF820
strPrefix = QString("Port").append(QString::number(nCurrentDevice));
gpPredefinedDevice->setValue(QString(strPrefix).append("Name"), "Vela IF820");
gpPredefinedDevice->setValue(QString(strPrefix).append("Baud"), "115200");
gpPredefinedDevice->setValue(QString(strPrefix).append("Parity"), "0");
gpPredefinedDevice->setValue(QString(strPrefix).append("Stop"), "1");
gpPredefinedDevice->setValue(QString(strPrefix).append("Data"), "8");
gpPredefinedDevice->setValue(QString(strPrefix).append("Flow"), "0");
++nCurrentDevice;
//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());
}
//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->setToolTip(QString("UwTerminalX v").append(UwVersion));
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 Connectivity server. Uploaded file data is not stored by Laird Connectivity but IP addresses are stored in access logs which are used for security purposes only.");
#else
//Mac or Linux
ui->label_OnlineXCompInfo->setText("By enabling Online XCompilation support, when compiling an application, the source data will be uploaded and compiled remotely on a Laird Connectivity server. Uploaded file data is not stored by Laird Connectivity but IP addresses are stored in access logs which are used for security purposes only.");
#endif
ui->check_OnlineXComp->setChecked(gpTermSettings->value("OnlineXComp", DefaultOnlineXComp).toBool());
//Load last directory path
gstrLastFilename[FilenameIndexApplication] = gpTermSettings->value("LastFileDirectory", "").toString();
gstrLastFilename[FilenameIndexScripting] = gpTermSettings->value("LastScriptFileDirectory", "").toString();
gstrLastFilename[FilenameIndexOthers] = gpTermSettings->value("LastOtherFileDirectory", "").toString();
//Refresh list of log files
on_btn_LogRefresh_clicked();
QFont fntTmpFnt2;
if (gpTermSettings->contains("CustomFont") && gpTermSettings->contains("CustomPalette"))
{
//Load saved settings
fntTmpFnt2 = QFont(gpTermSettings->value("CustomFont").value<QFont>());
QPalette palTmp = gpTermSettings->value("CustomPalette").value<QPalette>();
ui->text_TermEditData->setPalette(palTmp);
ui->text_LogData->setPalette(palTmp);
#if SKIPSPEEDTEST != 1
ui->text_SpeedEditData->setPalette(palTmp);
#endif
}
else
{
//Use monospaced font for terminal
fntTmpFnt2 = QFontDatabase::systemFont(QFontDatabase::FixedFont);
}
//Setup font
ui->text_TermEditData->setFont(fntTmpFnt2);
ui->text_LogData->setFont(fntTmpFnt2);
#if SKIPSPEEDTEST != 1
ui->text_SpeedEditData->setFont(fntTmpFnt2);
#endif
//Setup font spacing
QFontMetrics tmTmpFM(fntTmpFnt2);
ui->text_SpeedEditData->setTabStopDistance(tmTmpFM.horizontalAdvance(" ")*6);
ui->text_TermEditData->setTabStopDistance(tmTmpFM.horizontalAdvance(" ")*6);
ui->text_LogData->setTabStopDistance(tmTmpFM.horizontalAdvance(" ")*6);
#ifdef RESOLVEIPSEPARATELY
//Set resolved hostname to be empty
gstrResolvedServer = "";
#endif
#ifdef UseSSL
//Load SSL certificate
QFile certFile(":/certificates/UwTerminalX_new.crt");
if (certFile.open(QIODevice::ReadOnly))
{
//Load certificate data
QSslConfiguration sslcConfig;
sslcLairdSSLNew = new QSslCertificate(certFile.readAll());
sslcConfig.addCaCertificate(*sslcLairdSSLNew);
certFile.close();
}
#endif
//Setup the terminal scrollback buffer size
ui->text_TermEditData->SetupScrollback(gpTermSettings->value("ScrollbackBufferSize", DefaultScrollbackBufferSize).toUInt());
//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() == "DUPLICATE")
{
//Duplicate window so move to the top
this->activateWindow();
this->raise();
}
if (slArgs[chi].toUpper() == "ACCEPT")
{
//Skip the front panel
on_btn_Accept_clicked();
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(QByteArray,bool,bool)), this, SLOT(MessagePass(QByteArray,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(QByteArray,bool,bool)), this, SLOT(MessagePass(QByteArray,bool,bool)));
}
//Load file
guaAutomationForm->LoadFile(slArgs[chi].right(slArgs[chi].size()-15));
}
#endif
else if (slArgs[chi].toUpper() == "PREDEFINED COMMANDS" && bArgAccept == true)
{
//Show predefined commands window
if (gupcPredefinedCommandsForm == 0)
{
//Initialise predefined commands popup
gupcPredefinedCommandsForm = new UwxPredefinedCommands(this);
//Populate window handles for predefined commands object
gupcPredefinedCommandsForm->SetPopupHandle(gpmErrorForm);
//Update predefined commands form with connection status
gupcPredefinedCommandsForm->ConnectionChange(gspSerialPort.isOpen());
//Connect signals
connect(gupcPredefinedCommandsForm, SIGNAL(SendData(QByteArray,bool,bool)), this, SLOT(MessagePass(QByteArray,bool,bool)));
//Show form
gupcPredefinedCommandsForm->show();
}
}
else if (slArgs[chi].left(15).toUpper() == "PREDEFINED COMM")
{
//Load predefined commands file
if (gupcPredefinedCommandsForm == 0)
{
//Initialise predefined commands popup
gupcPredefinedCommandsForm = new UwxPredefinedCommands(this);
//Populate window handles for predefined commands object
gupcPredefinedCommandsForm->SetPopupHandle(gpmErrorForm);
//Update predefined commands form with connection status
gupcPredefinedCommandsForm->ConnectionChange(gspSerialPort.isOpen());
//Connect signals
connect(gupcPredefinedCommandsForm, SIGNAL(SendData(QByteArray,bool,bool)), this, SLOT(MessagePass(QByteArray,bool,bool)));
}
//Load file
gupcPredefinedCommandsForm->LoadFile(slArgs[chi].right(slArgs[chi].size()-15));
}
#ifndef SKIPSCRIPTINGFORM
else if (slArgs[chi].toUpper() == "SCRIPTING" && bArgAccept == true)
{
//Show scripting window
if (gusScriptingForm == 0)
{