-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
2258 lines (1994 loc) · 107 KB
/
Copy pathmain.py
File metadata and controls
2258 lines (1994 loc) · 107 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
from PyQt5.QtWidgets import QDialog, QApplication, QHBoxLayout, QCheckBox, QLabel, QPlainTextEdit, QSizePolicy, QFrame, \
QGridLayout
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot, QTimer, QSize, Qt
from PyQt5.uic import loadUi
import serial
import serial.tools.list_ports as port
import time
import pandas as pd
import os
import datetime
from time import gmtime, strftime
import jinja2
import tpl
'''
WELCOME TO BOARD TESTING CODE :)
Author: PARNIKA GUPTA
Date: August 1st 2020, September 27th 2020
Project: GAIA Testing-Automation GUI
Version: 5.1
Technology: Qt (Windows, MAC, Linux)
Features: Multiple project (AAI | Insight) with seperate look-up tables
1. Latest libraries upgraded
2. GAIA png logo added
3. Copyright included - COPYRIGHT © 2020 Gaia Smart Cities Solutions Pvt. Ltd
4. Re-designed- In horizontal View
5. 23 get commands (Validation check for all 13 get response commands | Updatable)
6. 25 set commands (Validation check for all | Updatable)
Total Functions: 22 functions installed
1. 'Info' Instruction
2. 'Disconnected'/'Connected' Connection error or not
3. 'Send' & 4. 'Receive' Single GET command
5. 'Check' Quick single GET command
6. 'Auto Send' & 7. 'Auto Receive' Multiple GET commands
8. 'Repeat Sent-Receive' Repetitive multiple GET commands
9. 'SET Device Id' Only set device id of multiple devices
10. 'Select All' Toggle selection on SET command
11. 'SET' Only SET commands
12. 'SET Check' SET commands with validation
13. 'Repeat SET Check' Repetitive multiple SET commands with validation
14. 'SET-GET Response' Runs whole GUI (SET and then GET)
15. 'Analyse GET Data' & 16. 'Analyse SET Data' Data analysis of GET or SET Records
17. 'Empty GET Data' & 18. 'Empty SET Data' Renew GET or SET Records
19. 'Show' & 20. 'Delete' Show or Delete all msgs of GSM module
21. 'Clear Screen' Clear Command Response screen
22. 'Quit' Close App
Additional Features:
1. Finds the serial port automatically.
2. Tells sms is unsuccessful if "ERROR" is found and "+CMGS: " is not found
Upgrade in 5.0:
1. Device ID has receiving feature too
In App: CLI- python Setup.py build-> Compress UI Folder-> Upload in NSIS App-> Setup Ready
'''
# for clearing the terminal screen from a Python script in case executed on terminal
def clear():
# _ = os.system('cls') if os.name == 'nt' else os.system('clear')
os.system('cls' if os.name == 'nt' else 'clear')
# class for the GUI functions with send and receive features
class Widget(QDialog):
@pyqtSlot()
def __init__(self):
super(Widget, self).__init__()
# load the GUI designed from QT Designer
loadUi('gui._designui', self)
# app title and icon
self.setWindowTitle("Testing Automation GUI")
self.iconName = "company_logo.png"
self.setWindowIcon(QIcon(self.iconName))
# excel sheets updating initialisation
self.Database = 'DATABASE.xlsx'
self.Record_File = 'GET Response.xlsx'
self.Record_File_Common_Sheet = 'RECORD'
self.set_Record_File = 'SET Response.xlsx'
# info definition
self.output_te.clear()
self.output_te.append("")
self.output_te.append("<b>WELCOME TO BOARD TESTING :) </b>")
self.info()
# excel sheet Gaia project database
self.file_default_values = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['DEFAULT VALUES'])
.dropna(how="any")['DEFAULT VALUES'])
GAIA_Project = self.file_default_values[10]
print("GAIA Project Used: " + GAIA_Project)
try:
if GAIA_Project!="_":
self.Database = 'DATABASE_' + GAIA_Project + '.xlsx'
self.Record_File = 'GET Response_' + GAIA_Project + '.xlsx'
self.Record_File_Common_Sheet = 'RECORD_' + GAIA_Project
self.set_Record_File = 'SET Response_' + GAIA_Project + '.xlsx'
else:
print("GAIA Project Used: Common")
print("Database: " + self.Database)
print("Record_File: " + self.Record_File)
print("Record_File_Common_Sheet: " + self.Record_File_Common_Sheet)
print("set_Record_File: " + self.set_Record_File)
print("Database altered :)")
print("\n")
self.output_te.append("<b>Database: </b>" + self.Database)
self.output_te.append("<b>Record_File: </b>" + self.Record_File)
self.output_te.append("<b>Record_File_Common_Sheet: </b>" + self.Record_File_Common_Sheet)
self.output_te.append("<b>set_Record_File: </b>" + self.set_Record_File)
self.output_te.append("<b>Database altered :)</b>")
self.output_te.append("\n")
except Exception as e:
print('Error in send', e)
self.output_te.append('<b>\nError in select_database: ' + str(e))
self.common_dir_parameter = ['NUMBER', 'TIME', 'COMMANDS', 'COMMAND RESPONSE', 'COMMAND PARAMETER']
self.writer_Record_File = pd.ExcelWriter(self.Record_File, engine='openpyxl')
self.writer_set_Record_File = pd.ExcelWriter(self.set_Record_File, engine='openpyxl')
self.ind = 0
self.list_sms_para = []
self.list_sms_rsp = []
# default number of the device
self.number.setPlainText(list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['NUMBER'])
.dropna(how="any")['NUMBER'])[0])
# Main Database columns
self.file_s_no = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['S No.'])
.dropna(how="any")['S No.'])
self.file_commands = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['COMMAND'])
.dropna(how="any")['COMMAND'])
self.file_timing = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['TIME'])
.dropna(how="any")['TIME'])
self.file_response_no = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['RESPONSE NUMBER'])
.dropna(how="any")['RESPONSE NUMBER'])
self.file_com_parameter = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['COMMAND PARAMETER'])
.dropna(how="any")['COMMAND PARAMETER'])
self.file_com_response = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['COMMAND RESPONSE'])
.dropna(how="any")['COMMAND RESPONSE'])
self.set_checkboxx = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['EXTRA CHECKBOX'])
.dropna(how="any")['EXTRA CHECKBOX'])
self.set_checkbox = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['CHECKBOX'])
.dropna(how="any")['CHECKBOX'])
self.set_textboxx = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['EXTRA TEXTBOX'])
.dropna(how="any")['EXTRA TEXTBOX'])
self.set_textbox = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['TEXTBOX'])
.dropna(how="any")['TEXTBOX'])
self.file_set_dir_parameter = list(
pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['SET DIR PARAMETER'])
.dropna(how="any")['SET DIR PARAMETER'])
self.file_set_dir_extra_parameter = list(
pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['SET DIR EXTRA PARAMETER'])
.dropna(how="any")['SET DIR EXTRA PARAMETER'])
self.file_var_parameter = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['VARIABLE PARAMETER'])
.dropna(how="any")['VARIABLE PARAMETER'])
self.file_default_text = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['DEFAULT TEXT'])
.dropna(how="any")['DEFAULT TEXT'])
self.file_set_rx_list = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['SET RX LIST'])
.dropna(how="any")['SET RX LIST'])
self.file_set_rx_index = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['SET RX INDEX'])
.dropna(how="any")['SET RX INDEX'])
self.file_extra_com = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['EXTRA COMMAND'])
.dropna(how="any")['EXTRA COMMAND'])
self.file_default_extra_text = list(
pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['DEFAULT EXTRA TEXT'])
.dropna(how="any")['DEFAULT EXTRA TEXT'])
self.file_set_rx_extra_list = list(
pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['SET RX EXTRA LIST'])
.dropna(how="any")['SET RX EXTRA LIST'])
self.file_set_rx_extra_index = list(
pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['SET RX EXTRA INDEX'])
.dropna(how="any")['SET RX EXTRA INDEX'])
self.file_set_default_mcn = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['SET DEFAULT MCN'])
.dropna(how="any")['SET DEFAULT MCN'])
self.file_default_values = list(pd.read_excel(self.Database, 'Sheet1', dtype=str, usecols=['DEFAULT VALUES'])
.dropna(how="any")['DEFAULT VALUES'])
self.set_response_parameters = self.file_set_dir_parameter[0:1] + self.file_set_dir_extra_parameter[0:1] + \
self.file_set_dir_extra_parameter[2:3] + self.file_set_dir_parameter[1:]
# auto send values initialisation
self.send_list = []
self.check_time.setPlainText(self.file_default_values[0])
self.Index_from.setPlainText(self.file_default_values[1])
self.Index_to.setPlainText(self.file_default_values[2])
self.Wait_time_to_rx.setPlainText(self.file_default_values[3])
self.No_of_repetitions.setPlainText(self.file_default_values[4])
self.Delay_in_repetition.setPlainText(self.file_default_values[5])
self.set_No_of_repetitions.setPlainText(self.file_default_values[6])
self.set_Delay_in_repetition.setPlainText(self.file_default_values[7])
self.Set_send_time.setPlainText(self.file_default_values[8])
self.Set_receive_time.setPlainText(self.file_default_values[9])
self.GAIA_Project.setPlainText(self.file_default_values[10])
# filling the commands combo box
for i in self.file_commands:
self.message_le.addItem(i)
# set values initialisation
self.lis = []
self.default_texts = self.file_default_text[0:1] + self.file_default_extra_text[:] + self.file_default_text[1:]
self.checkboxes = self.set_checkbox[0:1] + self.set_checkboxx[:] + self.set_checkbox[1:]
self.labels = self.file_set_dir_parameter[0:1] + self.file_set_dir_extra_parameter[:] + \
self.file_set_dir_parameter[1:]
self.file_set_dir_parameter = self.labels
self.textboxes = self.set_textbox[0:1] + self.set_textboxx[:] + self.set_textbox[1:]
z = zip(self.checkboxes, self.labels, self.textboxes, self.default_texts)
self.checkbox_list = []
self.set_command_value = []
self.set_command_val = []
i = 0
for c, l, t, d in z:
# print(i, c, l, t, d)
self.Frame = QFrame(self.Update)
self.Frame.setMinimumSize(QSize(0, 60))
self.Frame.setFrameShape(QFrame.StyledPanel)
self.Frame.setFrameShadow(QFrame.Raised)
self.Frame.setObjectName("Frame" + str(i))
self.GridLayout = QGridLayout(self.Frame)
self.GridLayout.setContentsMargins(2, -1, 2, -1)
self.GridLayout.setObjectName("GridLayout" + str(i))
self.panel = QHBoxLayout()
self.panel.setObjectName("panel" + str(i))
if c == "_":
self.checkbox = QFrame(self.Frame)
self.checkbox.setObjectName(c)
else:
self.checkbox = QCheckBox(self.Frame)
self.checkbox.setMaximumSize(QSize(17, 31))
self.checkbox.setTabletTracking(True)
self.checkbox.setChecked(False)
self.checkbox.setObjectName(c)
self.checkbox_list.append(self.checkbox)
self.panel.addWidget(self.checkbox)
self.label = QLabel(self.Frame)
self.label.setFocusPolicy(Qt.ClickFocus)
self.label.setObjectName(l)
self.label.setText(
"<html><head/><body><p><span style=\" font-size:10pt;\">" + l + "</span></p></body></html>")
self.panel.addWidget(self.label)
self.text = QPlainTextEdit(self.Frame)
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.text.sizePolicy().hasHeightForWidth())
self.text.setSizePolicy(sizePolicy)
self.text.setMinimumSize(QSize(100, 0))
self.text.setMaximumSize(QSize(320, 50))
self.text.setFocusPolicy(Qt.ClickFocus)
self.text.setStyleSheet("color: rgb(91, 91, 91) ;\n""font: 11pt \"MS Shell Dlg 2\";")
self.text.setFrameShape(QFrame.WinPanel)
self.text.setFrameShadow(QFrame.Sunken)
self.text.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.text.setOverwriteMode(False)
self.text.setObjectName(t)
self.text.setPlainText(d)
self.set_command_val.append(self.text)
self.panel.addWidget(self.text)
self.GridLayout.addLayout(self.panel, 0, 0, 1, 1)
self.verticalLayout_11.addWidget(self.Frame)
i += 1
self.Updating.setWidget(self.Update)
self.set_rx_resp_no = [0] * (len(self.file_set_rx_list + self.file_set_rx_extra_list))
self.set_rx_resp_ind = [0] * (len(self.file_set_rx_list + self.file_set_rx_extra_list))
self.set_list = []
self.set_rx_list = self.file_set_rx_list[0:1] + self.file_set_rx_extra_list + self.file_set_rx_list[1:]
self.set_rx_index = self.file_set_rx_index[0:1] + self.file_set_rx_extra_index[0:2] + self.file_set_rx_index[1:]
for j in range(len(self.set_rx_list)):
for i in range(len(self.file_commands)):
if str(self.set_rx_list[j]) == str(self.file_commands[i]):
self.set_rx_resp_no[j] = int(self.file_response_no[i])
self.set_rx_resp_ind[j] = i
self.checked_list = []
self.set_not_rx_list = []
for i in range(len(self.set_rx_list)):
if self.set_rx_list[i] == "_":
self.set_not_rx_list.append(i)
self.set_rx_check_list = []
for index, set_rx_list_element in enumerate(self.set_rx_list):
x = []
for index1, set_rx_list_element_element in enumerate(self.set_rx_list[:index]):
if set_rx_list_element == set_rx_list_element_element:
x.append(index1)
self.set_rx_check_list.append(x)
# clicked buttons initialisation
self.button.clicked.connect(self.on_toggled)
self.info_btn.clicked.connect(self.info)
self.Send_btn.clicked.connect(self.send_start)
self.Receive_btn.clicked.connect(self.receive_start)
self.clear_screen_btn.clicked.connect(self.clear_screen)
self.quit_btn.clicked.connect(QApplication.quit)
self.check_btn.clicked.connect(self.check_start)
self.Get_response_data_btn.clicked.connect(self.get_response_data)
self.Set_response_data_btn.clicked.connect(self.set_response_data)
self.Delete_btn.clicked.connect(self.delete_all_sms)
self.Show_btn.clicked.connect(self.show_all_sms)
self.Empty_btn.clicked.connect(self.Empty_excel)
self.Empty_set_btn.clicked.connect(self.set_Empty_excel)
self.auto_send_btn.clicked.connect(self.sequence_send_start)
self.auto_receive_btn.clicked.connect(self.sequence_send_custom_receive)
self.repeat_auto_send_btn.clicked.connect(self.repetitive_sequence_send_start)
self.set_get_response_btn.clicked.connect(self.set_get_response_start)
self.set_btn.clicked.connect(self.set)
self.set_send_rx_btn.clicked.connect(self.set_send_rx_start)
self.repeat_auto_set_btn.clicked.connect(self.repetitive_sequence_set_start)
self.set_dvc_id_btn.clicked.connect(self.set_dvc_id)
self.select_all_btn.clicked.connect(self.select_all)
# receive values initialisation
self.data = ''
self.receive_list = []
self.response_number = 0
self.sms_needed_list = []
self.all_sms = ''
self.all_sms_list = []
# timers threads initialisation
self.timer = QTimer()
self.timer1 = QTimer()
self.timer1.setInterval(3000)
self.timer1.timeout.connect(self.set_commands_sending)
self.timer2 = QTimer()
self.timer2.setInterval(3000)
self.timer2.timeout.connect(self.send_multiple)
self.timer3 = QTimer()
self.timer3.setInterval(3000)
self.timer3.timeout.connect(self.receive_only)
self.timer4 = QTimer()
self.timer4.setInterval(3000)
self.timer4.timeout.connect(self.sequence_send_multiple)
self.timer5 = QTimer()
self.timer5.setInterval(3000)
self.timer5.timeout.connect(self.repetitions)
self.timer6 = QTimer()
self.timer6.setInterval(3000)
self.timer6.timeout.connect(self.set_send_rx_multiple)
self.timer7 = QTimer()
self.timer7.setInterval(3000)
self.timer7.timeout.connect(self.set_repetitions)
self.timer8 = QTimer()
self.timer8.setInterval(3000)
self.timer8.timeout.connect(self.set_get_response)
self.timer9 = QTimer()
self.timer9.setInterval(3000)
self.timer9.timeout.connect(self.check)
self.recipient = None
self.content = None
# port initialisation
self.comPort = None
self.on_toggled()
self.serial = serial.Serial(self.comPort,
9600,
timeout=5,
xonxoff=False,
rtscts=False,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE)
# Check Closing Excels
self.load_get()
self.load_set()
# ----------------------------------COMMON-------------------------------------------------------------------------#
@pyqtSlot()
def info(self):
self.output_te.append("")
self.output_te.append("1...<b>Instruction</b>: <I>'Info'</I>")
self.output_te.append("2...<b>Connection error or not</b>: <i>'Disconnected'/'Connected'</i>")
self.output_te.append("3...<b>Single GET command</b>: <i>'Send' or 'Receive'</i>")
self.output_te.append("4...<b>Quick single GET command</b>: <i>'Check'</i>")
self.output_te.append("5...<b>Multiple GET commands</b>: <i>'Auto Send' or 'Auto Receive'</i>")
self.output_te.append("6...<b>Repetitive multiple GET commands</b>: <i>'Repeat Sent-Receive'</i>")
self.output_te.append("7...<b>Only set device id of multiple devices</b>: <i>'SET Device Id'</i>")
self.output_te.append("8...<b>Toggle selection on SET command</b>: <i>'Select All'</i>")
self.output_te.append("9...<b>Only SET commands</b>: <i>'SET'</i>")
self.output_te.append("10..<b>SET commands with validation</b>: <i> 'SET Check' </i>")
self.output_te.append("11..<b>Repetitive multiple SET commands with validation</b>: <i>'Repeat SET Check'</i>")
self.output_te.append("12..<b>Runs whole GUI (SET and then GET)</b>: <i>'SET - GET Response'</i>")
self.output_te.append("13..<b>Data analysis of GET or SET Records</b>: <i>'Analyse GET Data' or 'Analyse SET "
"Data'</i>")
self.output_te.append("14..<b>Renew GET or SET Records</b>: <i>'Empty GET Data' or 'Empty SET Data'</i>")
self.output_te.append("15..<b>Show or Delete all msgs of GSM module</b>: <i>'Show' or 'Delete'</i>")
self.output_te.append("16..<b>Clear Command Response screen</b>: <i>'Clear Screen'</i>")
self.output_te.append("17..<b>Close App</b>: <i>'Quit'</i>")
self.output_te.append("\n")
@pyqtSlot(bool)
def on_toggled(self):
# port initialisation
for i in port.comports():
if 'USB-SERIAL CH340' in str(i):
self.comPort = str(i).split(' ')[0]
if not self.comPort:
self.button.setText("Disconnected")
print('Error in hardware connection')
self.output_te.append('\n<b>Error in hardware connection...')
else:
self.button.setText("Connected")
self.output_te.append('\n' + '<b>Connected...')
@pyqtSlot()
def clear_screen(self):
self.output_te.clear()
@pyqtSlot()
def delete_all_sms(self):
try:
self.output_te.append("<b>\nAll SMS in inbox deleting...")
self.send_list = ["AT\r", 'AT+CMGD=1,4\r']
print("VALUE TAKEN")
self.sendMessage()
time.sleep(10)
print("Msgs Deleted !\n")
self.output_te.append("<b>Deleted")
except Exception as e:
print('Error in delete_all_sms', e)
self.output_te.append('<b>\nError in delete_all_sms: ' + str(e))
@pyqtSlot()
def show_all_sms(self):
self.output_te.append("<b>All SMS in inbox collecting...")
self.send_list = ['AT+CMGL="ALL"\r']
print("VALUE TAKEN")
try:
for i in self.send_list:
self.serial.write(i.encode())
time.sleep(1)
self.output_te.append(i)
x = self.serial.readall()
print(x)
for j in str(x.decode('utf-8')).split('\n'):
self.output_te.append(j)
except Exception as e:
print('Error in show_all_msgs', e)
self.output_te.append('<b>\nError in show_all_msgs: ' + str(e))
print("MESSAGE SENT")
self.disconnectPhone()
self.output_te.append("<b>Collected all messages :)")
@pyqtSlot()
def check_start(self):
self.output_te.append("\n<b>Checking...")
self.timer9.start()
@pyqtSlot()
def check(self):
if 'Choose Command' in self.message_le.currentText():
self.output_te.append("<b>Un-select CHOOSE COMMAND :(")
else:
numbers = self.number.toPlainText().split(',')
print("\nNumbers:", numbers)
for i in numbers:
try:
i = i.strip()
print("\nNumber:", i)
self.delete_all_sms()
self.send(i, self.message_le.currentText())
print("\nReceive in:", self.check_time.toPlainText())
time.sleep(int(self.check_time.toPlainText()))
self.GetAllSMS(i)
if not numbers[-1] == i:
print("\nNext number in: 5")
time.sleep(5)
except Exception as e:
print('Error in check', e)
self.output_te.append('<b>\nError in check: ' + str(e) + " at number " + str(i))
self.output_te.append("\n<b>Checking completed :)")
self.timer9.stop()
@pyqtSlot()
def Empty_excel(self):
self.writer_Record_File = pd.ExcelWriter(self.Record_File, engine='openpyxl')
try:
data_frame = [''] * len(self.file_response_no)
sms_parameter = [[]] * len(self.file_response_no)
for i in range(len(self.file_response_no)):
if int(self.file_response_no[i]) > 0:
sms_parameter[i] = self.file_com_parameter[i].split(',')
common_data_frame = pd.DataFrame(columns=self.common_dir_parameter) # blank common data frame
common_data_frame.to_excel(self.writer_Record_File, sheet_name=self.Record_File_Common_Sheet)
data_frame[i] = pd.DataFrame(columns=['NUMBER', 'TIME'] + sms_parameter[i]) # blank data frame
data_frame[i].to_excel(self.writer_Record_File, sheet_name=self.file_commands[i])
self.writer_Record_File.save()
print("Update Done")
self.output_te.append("\n<b>GET Excel Empty Update Successful :)")
except Exception as e:
print('Error in Empty_excel', e)
self.output_te.append("\n" + str(e) + "<b>...Close the Get File to proceed :(")
@pyqtSlot()
def set_Empty_excel(self):
self.writer_set_Record_File = pd.ExcelWriter(self.set_Record_File, engine='openpyxl')
try:
file_set_dir_parameter = ['NUMBER', 'TIME'] + self.set_response_parameters
data_frame = pd.DataFrame(columns=file_set_dir_parameter)
data_frame.to_excel(self.writer_set_Record_File, columns=file_set_dir_parameter)
self.writer_set_Record_File.save()
print("Update Done")
self.output_te.append("\n<b>SET Excel Empty update successful :)")
except Exception as e:
print('Error in set_Empty_excel', e)
self.output_te.append("\n" + str(e) + "<b>...Close the Set File to proceed :(")
@pyqtSlot()
def select_all(self):
try:
for i in self.checkbox_list:
if i.isChecked():
i.setCheckState(False)
elif not i.isChecked():
i.setCheckState(True)
self.output_te.append("<b>All the SET options toggled :)</b>")
except Exception as e:
print('Error in send', e)
self.output_te.append('<b>\nError in select_all: ' + str(e))
# --------------------------------END COMMON-----------------------------------------------------------------------#
# --------------------------------SEND MESSAGE---------------------------------------------------------------------#
@pyqtSlot()
def send_start(self):
self.output_te.append("\n<b>Sending...")
self.timer2.start()
@pyqtSlot()
def send_multiple(self):
if 'Choose Command' in self.message_le.currentText():
print("<b>Un-select CHOOSE COMMAND :(")
self.output_te.append("<b>Un-select CHOOSE COMMAND :(")
self.timer2.stop()
else:
numbers = self.number.toPlainText().split(',')
print("\nNumbers:", numbers)
for i in numbers:
try:
i = i.strip()
print("\nNumber:", i)
self.delete_all_sms()
self.send(i, self.message_le.currentText())
if not numbers[-1] == i:
print("\nNext number in: 5")
time.sleep(5)
except Exception as e:
print('Error in sendMessage', e)
self.output_te.append('<b>\nError in sendMessage: ' + str(e) + " at number " + str(i))
self.timer2.stop()
@pyqtSlot(str, str)
def send(self, number, set_content):
try:
self.send_list = ["AT\r", 'AT+CMGF=1\r', '''AT+CMGS="''' + number + '''"\r''',
set_content, chr(26)]
print("VALUE TAKEN")
self.sendMessage()
except Exception as e:
print('Error in send', e)
self.output_te.append('<b>\nError in send: ' + str(e) + " at number " + number)
@pyqtSlot()
def sendMessage(self):
try:
for i in self.send_list:
self.serial.write(i.encode())
time.sleep(1.5)
if i in self.send_list[:-1]:
print(self.serial.readline())
else:
self.all_sms = self.serial.readall()
print("MESSAGE SENT")
self.disconnectPhone()
except Exception as e:
print('Error in sendMessage:', str(e))
self.output_te.append('<b>\nError in sendMessage: ' + str(e))
@pyqtSlot()
def disconnectPhone(self):
self.all_sms = str(self.all_sms.decode('utf-8'))
print("\nResponse:", self.all_sms.strip())
self.output_te.append(self.all_sms)
if self.all_sms.find("+CMGS: ") > -1 or self.all_sms.find("ERROR") == -1:
print("\nSent successful :) ")
self.output_te.append("<b>\nSent successful :)\n")
else:
print("\nSent unsuccessful :( ")
self.output_te.append("<b>\nSent unsuccessful :(\n")
print("DISCONNECT")
# ----------------------------------END SEND MESSAGE---------------------------------------------------------------#
# -----------------------------------RECEIVE MESSAGE---------------------------------------------------------------#
@pyqtSlot()
def receive_start(self):
self.output_te.append("\n<b>Receiving...")
self.timer3.start()
@pyqtSlot()
def receive_only(self):
try:
self.GetAllSMS(self.number.toPlainText().split(",")[-1])
self.timer3.stop()
except Exception as e:
print('Error in receive_only', str(e))
self.output_te.append('<b>\nError in receive_only: ' + str(e))
@pyqtSlot()
def GetAllSMS(self, number):
try:
for i in range(len(self.file_commands)):
if str(self.message_le.currentText()) == str(self.file_commands[i]):
self.response_number = int(self.file_response_no[i])
self.ind = i
print("\nRECEIVE:", self.message_le.currentText())
break
self.receiving(number)
self.timer3.stop()
except Exception as e:
print('Error in GetAllSMS:', str(e))
self.output_te.append('<b>\nError in GetAllSMS: ' + str(e))
@pyqtSlot(str)
def receiving(self, number):
try:
self.receive()
self.receive_1(number)
except Exception as e:
print('Error in receiving:', str(e))
self.output_te.append('<b>\nError in receiving: ' + str(e))
@pyqtSlot()
def receive(self):
try:
self.receive_list = ['AT+CMGF=1\r', "AT\r", '''AT+CMGL="ALL"\r''']
print("Searching...\n")
self.sms_needed_list = []
for i in self.receive_list:
self.serial.write(i.encode())
time.sleep(1)
if i in self.receive_list[:-1]:
print(self.serial.readline())
else:
self.all_sms = self.serial.readall()
print(self.all_sms)
self.output_te.append(i)
self.all_sms_list = self.all_sms.decode('utf-8').split('\n')
except Exception as e:
print('Error in receive:', str(e))
self.output_te.append('<b>Error in receive: ' + str(e))
@pyqtSlot(str)
def receive_1(self, number):
try:
print("\nReceiving:", self.file_commands[self.ind], self.response_number)
for index in range(len(self.all_sms_list)):
if ('GAIA ' + str(self.GAIA_Project.toPlainText()) + ',' + str(
self.file_response_no[self.ind]) + ',') in self.all_sms_list[index]:
self.sms_needed_list = self.all_sms_list[
index: int(index + len(list(self.file_com_parameter[self.ind].split(','))))]
if len(self.sms_needed_list) > 1:
self.list_sms_para = list(self.file_com_parameter[self.ind].split(','))
self.list_sms_rsp = ''.join(self.sms_needed_list).split(',')
for sms_parameter, sms_response in zip(self.list_sms_para, self.list_sms_rsp):
print(f'{sms_parameter.strip()} : {sms_response.strip()}')
self.output_te.append(f'<b>{sms_parameter.strip()}</b> : <i>{sms_response.strip()}</i>')
print(self.list_sms_para, "\n", self.list_sms_rsp)
self.Save_excel(self.ind, number, self.response_number, self.list_sms_para, self.list_sms_rsp)
self.output_te.append("<b>Response successful :)\n")
print("Response successful :)\n")
else:
self.output_te.append("<b>Response unsuccessful :(\n")
print("Response unsuccessful :(\n")
print("Done Receive")
self.disconnect_Phone()
except Exception as e:
print('Error in receive_1:', str(e))
self.output_te.append('<b>\nError in receive_1: ' + str(e))
@pyqtSlot(int, str, int, str, str)
def Save_excel(self, ind, number, response_no, sms_parameter, sms_response):
print("\nSaving in excel...")
response_no = int(response_no)
if int(response_no) > 0:
print(response_no, "Response checked: ", ind)
previous_record = []
try:
current_time = datetime.datetime.now()
common_previous_record = pd.read_excel(self.Record_File, sheet_name=self.Record_File_Common_Sheet,
index_col=[0]).dropna(how="all")
common_count_new = len(list(common_previous_record[self.common_dir_parameter[0]]))
common_data_frame = pd.DataFrame([[str(number), str(current_time), str(self.file_commands[ind]),
str(sms_response), str(sms_parameter)]],
columns=self.common_dir_parameter, index=[common_count_new])
common_new_record = common_previous_record.append(common_data_frame, verify_integrity=True, sort=False)
common_new_record.to_excel(self.writer_Record_File, sheet_name=self.Record_File_Common_Sheet,
columns=self.common_dir_parameter)
for i in range(len(self.file_response_no)):
previous_record.append(' ')
if int(self.file_response_no[i]) > 0:
previous_record[i] = pd.read_excel(self.Record_File, sheet_name=self.file_commands[i],
index_col=[0]).dropna(how="all")
previous_record[i].to_excel(self.writer_Record_File, sheet_name=self.file_commands[i])
counter_new = len(list(previous_record[ind][sms_parameter[0]]))
print(ind, "counter_new and common_count_new", counter_new, common_count_new, "record done")
print(ind, "Common record generated: ", common_new_record)
if len(self.list_sms_rsp) == len(self.list_sms_para):
current_time = datetime.datetime.now()
data_frame = pd.DataFrame([[number, current_time] + sms_response],
columns=['NUMBER', 'TIME'] + sms_parameter, index=[counter_new])
new_record = previous_record[ind].append(data_frame, verify_integrity=True, sort=False)
new_record.to_excel(self.writer_Record_File, sheet_name=self.file_commands[ind],
columns=['NUMBER', 'TIME'] + sms_parameter)
print(ind, "Specific record generated: ", data_frame, new_record)
else:
self.output_te.append("Incomplete message received :(")
except Exception as e:
print("Exception save_excel:", str(e))
self.output_te.append("<b>Exception save_excel: " + str(e))
self.writer_Record_File.save()
print("Update Done")
self.output_te.append("\n<b>Excel update successful :)")
@pyqtSlot()
def disconnect_Phone(self):
self.timer3.stop()
# ---------------------------------END RECEIVE MESSAGE-------------------------------------------------------------#
# --------------------------------AUTO SEND MESSAGE----------------------------------------------------------------#
@pyqtSlot()
def sequence_send_start(self):
self.output_te.append("\n<b>Sequential sending started...")
self.timer4.start()
@pyqtSlot()
def sequence_send_multiple(self):
numbers = self.number.toPlainText().split(',')
print("\nNumbers:", numbers)
for i in numbers:
try:
i = i.strip()
print("\nNumber:", i)
self.delete_all_sms()
self.sequence_send(i)
if not numbers[-1] == i:
print("\nNext number in: 5")
time.sleep(5)
except Exception as e:
print("Exception sequence_send_multiple:", str(e))
self.output_te.append("<b>\nException sequence_send_multiple: " + str(e) + " at number " + str(i + 1))
@pyqtSlot(str)
def sequence_send(self, number):
try:
index_from = int(self.Index_from.toPlainText())
index_to = int(self.Index_to.toPlainText())
response_no_list = []
for i in range(index_from, index_to + 1):
print("Sending: ", self.file_commands[i])
self.response_number = int(self.file_response_no[i])
print("Response No:", self.response_number)
self.send(number, self.file_commands[i])
if int(self.response_number) > 0:
response_no_list.append(i)
print("Updated response list: ", response_no_list)
print("\nNext msg in: ", int(self.file_timing[i]))
time.sleep(int(self.file_timing[i]))
if response_no_list:
time.sleep(int(self.Wait_time_to_rx.toPlainText()))
print("\nReceive in:", int(self.Wait_time_to_rx.toPlainText()))
self.sequence_send_receive(response_no_list, number)
except Exception as e:
print("Exception sequence_send:", str(e))
self.output_te.append("<b>\nException sequence_send: " + str(e))
self.timer4.stop()
@pyqtSlot(str, str)
def sequence_send_receive(self, response_no_list, number):
try:
for i in response_no_list:
self.ind = i
self.auto_GetAllSMS(i, number)
self.output_te.append("<b>All the responses received :)\n")
except Exception as e:
print("Exception sequence_send_receive:", str(e))
self.output_te.append("<b>\nException sequence_send_receive: " + str(e))
@pyqtSlot()
def sequence_send_custom_receive(self):
try:
number = self.number.toPlainText()
index_from = int(self.Index_from.toPlainText())
index_to = int(self.Index_to.toPlainText())
response_no_list = []
for i in range(index_from, index_to + 1):
response_no_list.append(i)
self.ind = i
self.auto_GetAllSMS(i, number)
self.output_te.append("<b>All the responses received :)\n")
except Exception as e:
print("Exception sequence_send_custom_receive:", str(e))
self.output_te.append("<b>\nException sequence_send_custom_receive: " + str(e))
@pyqtSlot(int)
def auto_GetAllSMS(self, response_no, number):
try:
self.response_number = response_no
self.receiving(number)
except Exception as e:
print("Exception auto_GetAllSMS:", str(e))
self.output_te.append("<b>Exception auto_GetAllSMS: " + str(e))
@pyqtSlot()
def repetitive_sequence_send_start(self):
self.output_te.append("\n<b>Repetitive sequential sending started...")
self.timer5.start()
@pyqtSlot()
def repetitions(self):
try:
for i in range(int(self.No_of_repetitions.toPlainText())):
self.sequence_send_multiple()
time.sleep(int(self.Delay_in_repetition.toPlainText()))
self.output_te.append("<b>Repetitive sequential sending complete :)")
except Exception as e:
print("Exception repetitions:", str(e))
self.output_te.append("<b>\nException repetitions: " + str(e) + " at repetition " + str(i + 1))
self.timer5.stop()
# --------------------------------END AUTO SEND MESSAGE------------------------------------------------------------#
# --------------------------------SET CONFIGURATION----------------------------------------------------------------#
@pyqtSlot()
def set(self):
self.output_te.append("\n<b>Setting Configurations...")
self.timer1.start()
@pyqtSlot()
def set_commands_sending(self):
try:
self.set_commands_send()
self.set_multiple()
self.output_te.append("<b>Set configuration successful :)\n")
except Exception as e:
print("Exception sequence_send_custom_receive:", e)
self.output_te.append("<b>\nException sequence_send_custom_receive: " + str(e))
self.timer1.stop()
@pyqtSlot()
def set_commands_send(self):
try:
self.set_command_value = []
for i in self.set_command_val[0:1] + self.set_command_val[6:]:
self.set_command_value.append(i.toPlainText().strip())
self.set_list = []
for set_command, set_command_value in zip(self.file_var_parameter[0:1], self.set_command_value[0:1]):
if set_command_value != '':
self.set_list.append(f'{set_command[ : set_command.index("[")]}{set_command_value}')
if self.set_command_val[1].toPlainText() != '' and self.set_command_val[2].toPlainText() != '':
self.set_list.append(
f'DEFAULT_MCN_{self.set_command_val[1].toPlainText().strip()},{self.set_command_val[2].toPlainText().strip()}')
if (self.set_command_val[3].toPlainText() != '' and self.set_command_val[4].toPlainText() != ''
and self.set_command_val[5].toPlainText() != ''):
self.set_list.append(f'SET_DVC_MCN_{self.set_command_val[3].toPlainText().strip()},'
f'{self.set_command_val[4].toPlainText().strip()},{self.set_command_val[5].toPlainText().strip()}')
for set_command, set_command_value in zip(self.file_var_parameter[1:], self.set_command_value[1:]):
if set_command_value != '':
self.set_list.append(f'{set_command[ : set_command.index("[")]}{set_command_value}')
self.lis = []
print("Following commands set:")
for i in range(len(self.set_list)):
if self.checkbox_list[i].isChecked():
self.lis.append(self.set_list[i])
print(f'{i+1}. {self.set_list[i]}')
self.checked_list.append(i)
except Exception as e:
print("Exception set_commands_send:", e)
self.output_te.append("<b>\nException set_commands_send: " + str(e))
@pyqtSlot()
def set_multiple(self):
numbers = self.number.toPlainText().split(',')
print("\nNumbers:",numbers)
for i in numbers:
try:
i = i.strip()
print("Number: ", i)
if len(self.lis) == 1:
for j in self.lis:
print(j, "\nExecuted\n")
self.send(i, j)
if not numbers[-1] == i:
print("\nNext number in: 20")
time.sleep(20)
else:
for j in self.lis:
print(j, "\nExecuted\n")
self.send(i, j)
print("\nNext set_send in: ", self.Set_send_time.toPlainText())
time.sleep(int(self.Set_send_time.toPlainText()))
if not numbers[-1] == i:
print("\nNext number in: 15")
time.sleep(15)
except Exception as e:
print("Exception set_multiple:", e)
self.output_te.append("<b>\nException set_multiple: " + str(e) + " at number " + str(i + 1))
self.output_te.append("Following commands set:")
for k in range(len(self.lis)):
self.output_te.append(f'{k+1}. {self.lis[k]}')
# --------------------------------END SET CONF---------------------------------------------------------------------#
# ----------------------------------SET & RECEIVE MESSAGE----------------------------------------------------------#
@pyqtSlot()
def set_send_rx_start(self):
self.output_te.append("\n<b>Setting Configurations...")
self.timer6.start()
@pyqtSlot()
def repetitive_sequence_set_start(self):
self.output_te.append("\n<b>Repetitive sequential sending started...")
self.timer7.start()
@pyqtSlot()