-
Notifications
You must be signed in to change notification settings - Fork 11
/
main_gui.py
2630 lines (2274 loc) · 105 KB
/
main_gui.py
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
# -*- coding: utf-8 -*-
from wizsocket.TCPClient import TCPClient
from WIZMakeCMD import WIZMakeCMD, version_compare, ONE_PORT_DEV, TWO_PORT_DEV, SECURITY_DEVICE
from WIZUDPSock import WIZUDPSock
from FWUploadThread import FWUploadThread
from WIZMSGHandler import WIZMSGHandler, DataRefresh
from certificatethread import certificatethread
from wizcmdset import Wizcmdset
from constants import Opcode, SockState
from utils import logger, funclog, get_latest_release_version
import sys
import time
import re
import os
import subprocess
import webbrowser
import logging
import datetime
# Additional package
from PyQt5 import QtCore, QtGui, uic
from PyQt5.QtWidgets import QApplication, QMainWindow, QLineEdit, QMessageBox, QTableWidgetItem, QFileDialog, QMenu, QAction, QProgressBar, QInputDialog
import ifaddr
VERSION = 'V1.5.5'
def resource_path(relative_path):
# Get absolute path to resource, works for dev and for PyInstaller
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
# Load ui files
uic_logger = logging.getLogger('PyQt5.uic')
uic_logger.setLevel(logging.WARNING)
main_window = uic.loadUiType(resource_path('gui/wizconfig_gui.ui'))[0]
class WIZWindow(QMainWindow, main_window):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setWindowTitle(f'WIZnet S2E Configuration Tool {VERSION}')
self.logger = logger
if 'Dev' in VERSION:
self.logger.setLevel(logging.DEBUG)
self.logger.info(f'Start configuration tool (version: {VERSION})')
# GUI font size init
self.midfont = None
self.smallfont = None
self.btnfont = None
self.gui_init()
# Main icon
self.setWindowIcon(QtGui.QIcon(resource_path('gui/icon.ico')))
self.set_btn_icon()
# load default cmdset
self.cmdset = Wizcmdset('WIZ750SR')
self.wizmakecmd = WIZMakeCMD()
self.dev_profile = {}
self.searched_devnum = None
# init search option
self.retry_search_num = 1
self.search_wait_time = 3
# check if use setting password
self.use_setting_pw = False
# self.entered_set_pw = '' # setting pw bak
self.encoded_setting_pw = ''
self.curr_setting_pw = '' # setting pw value
# Certificate
self.rootca_filename = None
self.clientcert_filename = None
self.privatekey_filename = None
self.mac_list = []
self.mn_list = []
self.vr_list = []
self.st_list = []
self.threads = []
self.curr_mac = None
self.curr_dev = None
self.curr_ver = None
self.curr_st = None
self.search_pre_wait_time = 3
self.search_wait_time_each = 1.5
self.search_retry_flag = False
self.search_retrynum = 0
self.localip_addr = None
# last selected firmware file name/size (include path)
self.fw_filename = None
self.fw_filesize = None
self.saved_path = None
self.selected_eth = None
self.cli_sock = None
self.isConnected = False
self.set_reponse = None
self.wizmsghandler = None
self.datarefresh = None
# Initial UI object
self.init_ui_object()
# Initial factory reset toolbutton
self.init_btn_factory()
# device select event
self.list_device.itemClicked.connect(self.dev_clicked)
""" Button event """
try:
self.btn_search.clicked.connect(self.do_search_normal)
# WIZ2000: need setting password (setting, reset, upload, factory)
self.btn_setting.clicked.connect(self.event_setting_clicked)
self.btn_reset.clicked.connect(self.event_reset_clicked)
# factory reset
self.btn_factory.clicked.connect(self.event_factory_setting)
self.btn_factory.triggered[QAction].connect(self.event_factory_option_clicked)
# configuration save/load button
self.btn_saveconfig.clicked.connect(self.dialog_save_file)
self.btn_loadconfig.clicked.connect(self.dialog_load_file)
# self.btn_upload.clicked.connect(self.update_btn_clicked)
self.btn_upload.clicked.connect(self.event_upload_clicked)
self.btn_exit.clicked.connect(self.msg_exit)
except Exception as e:
self.logger.error(f'button event register error: {e}')
# State Changed Event
self.show_idcode.stateChanged.connect(self.event_idcode)
self.show_connectpw.stateChanged.connect(self.event_passwd)
self.show_idcodeinput.stateChanged.connect(self.event_input_idcode)
self.enable_connect_pw.stateChanged.connect(self.event_passwd_enable)
self.at_enable.stateChanged.connect(self.event_atmode)
self.ch1_keepalive_enable.stateChanged.connect(self.event_keepalive)
self.ch2_keepalive_enable.stateChanged.connect(self.event_keepalive)
self.ip_dhcp.clicked.connect(self.event_ip_alloc)
self.ip_static.clicked.connect(self.event_ip_alloc)
# Event: OP mode
self.ch1_tcpclient.clicked.connect(self.event_opmode)
self.ch1_tcpserver.clicked.connect(self.event_opmode)
self.ch1_tcpmixed.clicked.connect(self.event_opmode)
self.ch1_udp.clicked.connect(self.event_opmode)
self.ch1_ssl_tcpclient.clicked.connect(self.event_opmode)
self.ch1_mqttclient.clicked.connect(self.event_opmode)
self.ch1_mqtts_client.clicked.connect(self.event_opmode)
self.ch2_tcpclient.clicked.connect(self.event_opmode)
self.ch2_tcpserver.clicked.connect(self.event_opmode)
self.ch2_tcpmixed.clicked.connect(self.event_opmode)
self.ch2_udp.clicked.connect(self.event_opmode)
# Event: Search method
self.broadcast.clicked.connect(self.event_search_method)
self.unicast_ip.clicked.connect(self.event_search_method)
# self.unicast_mac.clicked.connect(self.event_search_method)
# Event: modbus
# self.unicast_mac.clicked.connect(self.event_search_method)
self.pgbar = QProgressBar()
self.statusbar.addPermanentWidget(self.pgbar)
# progress thread
self.search_progress_thread = ThreadProgress()
self.search_progress_thread.change_value.connect(self.value_changed)
# check if device selected
self.list_device.itemSelectionChanged.connect(self.dev_selected)
# Menu event - File
self.actionSave.triggered.connect(self.dialog_save_file)
self.actionLoad.triggered.connect(self.dialog_load_file)
self.actionExit.triggered.connect(self.msg_exit)
# Menu event - Help
self.about_wiz.triggered.connect(self.about_info)
self.action_document.triggered.connect(self.menu_document)
# Menu event - Option
self.net_adapter_info()
self.netconfig_menu.triggered[QAction].connect(self.net_ifs_selected)
# Menu event - Option - Search option
self.action_set_wait_time.triggered.connect(self.input_search_wait_time)
self.action_retry_search.triggered.connect(self.input_retry_search)
# network interface selection
self.combobox_net_interface.currentIndexChanged.connect(self.net_changed)
# Tab changed
self.generalTab.currentChanged.connect(self.tab_changed)
# data refresh
self.refresh_no.clicked.connect(self.get_refresh_time)
self.refresh_1s.clicked.connect(self.get_refresh_time)
self.refresh_5s.clicked.connect(self.get_refresh_time)
self.refresh_10s.clicked.connect(self.get_refresh_time)
self.refresh_30s.clicked.connect(self.get_refresh_time)
# gpio config
self.gpioa_config.currentIndexChanged.connect(self.gpio_check)
self.gpiob_config.currentIndexChanged.connect(self.gpio_check)
self.gpioc_config.currentIndexChanged.connect(self.gpio_check)
self.gpiod_config.currentIndexChanged.connect(self.gpio_check)
# Manage certificate for WIZ510SSL
self.btn_load_rootca.clicked.connect(lambda: self.load_cert_btn_clicked('OC'))
self.btn_load_client_cert.clicked.connect(lambda: self.load_cert_btn_clicked('LC'))
self.btn_load_privatekey.clicked.connect(lambda: self.load_cert_btn_clicked('PK'))
# self.btn_load_fwfile.clicked.connect(lambda: self.load_cert_btn_clicked('UP'))
self.btn_save_rootca.clicked.connect(lambda: self.save_cert_btn_clicked('OC'))
self.btn_save_client_cert.clicked.connect(lambda: self.save_cert_btn_clicked('LC'))
self.btn_save_privatekey.clicked.connect(lambda: self.save_cert_btn_clicked('PK'))
# self.btn_upload_fw.clicked.connect(lambda: self.save_cert_btn_clicked('UP'))
self.textedit_rootca.textChanged.connect(self.event_rootca_changed)
self.textedit_client_cert.textChanged.connect(self.event_client_cert_changed)
self.textedit_privatekey.textChanged.connect(self.event_privatekey_changed)
# self.textedit_upload_fw.textChanged.connect(self.event_uploadfw_changed)
# Init network interface
self.combobox_net_interface.setCurrentIndex(0)
self.cert_object_config()
@funclog(logger)
def init_ui_object(self):
"""
Initial config based WIZ750SR series
"""
# Tab information save
self.userio_tab_text = self.generalTab.tabText(2)
self.mqtt_tab_text = self.generalTab.tabText(3)
self.certificate_tab_text = self.generalTab.tabText(4)
self.ch1_tab_text = self.channel_tab.tabText(1)
# Initial tab
self.generalTab.removeTab(5)
self.generalTab.removeTab(4)
self.generalTab.removeTab(3)
self.generalTab.removeTab(2)
# default: one port device
self.channel_tab.removeTab(1)
# for WIZ510SSL (not default)
self.group_current_bank.hide()
self.group_dtrdsr.hide()
# for WIZ5XXSR-RP
self.groupbox_ch1_timeout.hide()
# self.groupbox_ch1_timeout.setEnabled(False)
# for WIZ5XXSR-RP and similar models like W55RP20-S2E, W232N
if self.curr_dev in ["WIZ5XXSR-RP", "W55RP20-S2E", "W232N"]:
self.groupbox_ch1_timeout.hide()
# Disable additional subtopics for MQTT
for i in range(3, 10):
lineedit_subtopic = getattr(self, f'lineedit_mqtt_subtopic_{i}')
lineedit_subtopic.setEnabled(False)
def init_btn_factory(self):
# factory_option = ['Factory default settings', 'Factory default firmware']
self.factory_setting_action = QAction('Factory default settings', self)
self.factory_firmware_action = QAction('Factory default firmware', self)
self.btn_factory.addAction(self.factory_setting_action)
self.btn_factory.addAction(self.factory_firmware_action)
#@funclog(logger)
def tab_changed(self):
"""
When tab changed
- check user IO tab
"""
if 'WIZ750' in self.curr_dev:
if self.generalTab.currentIndex() == 2:
self.logger.debug(f'Start DataRefresh: {self.curr_dev}, currentTab: {self.generalTab.currentIndex()}')
# Expansion GPIO tab
self.gpio_check()
self.get_refresh_time()
else:
try:
if self.datarefresh is not None:
self.logger.debug(f'Stop DataRefresh: {self.curr_dev}, currentTab: {self.generalTab.currentIndex()}')
if self.datarefresh.isRunning():
self.datarefresh.terminate()
except Exception as e:
self.logger.error(e)
@funclog(logger)
def net_ifs_selected(self, netifs):
ifs = netifs.text().split(':')
selected_ip = ifs[0]
selected_name = ifs[1]
self.logger.info('net_ifs_selected() %s: %s' % (selected_ip, selected_name))
self.statusbar.showMessage(' Selected: %s: %s' % (selected_ip, selected_name))
self.selected_eth = selected_ip
def value_changed(self, value):
self.pgbar.show()
self.pgbar.setValue(value)
def dev_selected(self):
if len(self.list_device.selectedItems()) == 0:
self.disable_object()
else:
self.object_config()
def net_changed(self, ifs):
self.logger.info(self.combobox_net_interface.currentText())
ifs = self.combobox_net_interface.currentText().split(':')
selected_ip = ifs[0]
selected_name = ifs[1]
self.statusbar.showMessage(' Selected eth: %s: %s' % (selected_ip, selected_name))
self.selected_eth = selected_ip
# Get network adapter & IP list
def net_adapter_info(self):
self.netconfig_menu = QMenu('Network Interface Config', self)
self.netconfig_menu.setFont(self.midfont)
self.menuOption.addMenu(self.netconfig_menu)
adapters = ifaddr.get_adapters()
self.net_list = []
for adapter in adapters:
self.logger.debug(f"Net Interface: {adapter.nice_name}")
for ip in adapter.ips:
if len(ip.ip) > 6:
ipv4_addr = ip.ip
if ipv4_addr == '127.0.0.1':
pass
else:
net_ifs = ipv4_addr + ':' + adapter.nice_name
# -- get network interface list
self.net_list.append(adapter.nice_name)
netconfig = QAction(net_ifs, self)
self.netconfig_menu.addAction(netconfig)
self.combobox_net_interface.addItem(net_ifs)
else:
# ipv6_addr = ip.ip
pass
# Default: not selected
self.combobox_net_interface.setCurrentIndex(-1)
# 힌트 텍스트 설정
# self.combobox_net_interface.setPlaceholderText('<Select Network Interface>')
def disable_object(self):
self.btn_reset.setEnabled(False)
self.btn_factory.setEnabled(False)
self.btn_upload.setEnabled(False)
self.btn_setting.setEnabled(False)
self.btn_saveconfig.setEnabled(False)
self.btn_loadconfig.setEnabled(False)
self.generalTab.setEnabled(False)
self.channel_tab.setEnabled(False)
def object_config(self):
self.selected_devinfo()
# Enable buttons
self.btn_reset.setEnabled(True)
self.btn_factory.setEnabled(True)
self.btn_upload.setEnabled(True)
self.btn_setting.setEnabled(True)
self.btn_saveconfig.setEnabled(True)
self.btn_loadconfig.setEnabled(True)
# Enable tab group
self.generalTab.setEnabled(True)
self.generalTab.setTabEnabled(0, True)
# tab config
self.general_tab_config()
self.channel_tab_config()
# object enable/disable
self.object_config_for_device()
self.refresh_grp.setEnabled(True)
self.exp_gpio.setEnabled(True)
self.channel_tab.setEnabled(True)
self.event_passwd_enable()
# enable menu
self.save_config.setEnabled(True)
self.load_config.setEnabled(True)
self.event_opmode()
self.event_search_method()
self.event_ip_alloc()
self.event_atmode()
self.event_keepalive()
# self.event_setting_pw()
# self.event_localport_fix()
# self.event_cert_changed()
self.gpio_check()
# Certificate manager tab events
def cert_object_config(self):
self.event_rootca_changed()
self.event_client_cert_changed()
self.event_privatekey_changed()
# self.event_uploadfw_changed()
def event_rootca_changed(self):
if (len(self.textedit_rootca.toPlainText()) > 0):
self.btn_save_rootca.setEnabled(True)
else:
self.btn_save_rootca.setEnabled(False)
def event_client_cert_changed(self):
if (len(self.textedit_client_cert.toPlainText()) > 0):
self.btn_save_client_cert.setEnabled(True)
else:
self.btn_save_client_cert.setEnabled(False)
def event_privatekey_changed(self):
if (len(self.textedit_privatekey.toPlainText()) > 0):
self.btn_save_privatekey.setEnabled(True)
else:
self.btn_save_privatekey.setEnabled(False)
# Button click events
def event_setting_clicked(self):
self.do_setting()
def event_reset_clicked(self):
self.do_reset()
def event_factory_setting(self):
self.msg_factory_setting()
def event_factory_firmware(self):
self.msg_factory_firmware()
# factory reset options
# option: factory button / menu 1, menu 2
def event_factory_option_clicked(self, option):
self.logger.info(option.text())
opt = option.text()
if 'settings' in opt:
self.event_factory_setting()
elif 'firmware' in opt:
self.event_factory_firmware()
def event_upload_clicked(self):
if self.localip_addr is not None:
self.update_btn_clicked()
else:
self.show_msgbox("Warning", "Local IP information could not be found. Check the Network configuration.", QMessageBox.Warning)
def gpio_check(self):
if 'WIZ5XX' in self.curr_dev:
gpio_list = ['a', 'b']
else:
gpio_list = ['a', 'b', 'c', 'd']
for name in gpio_list:
gpio_config = getattr(self, f'gpio{name}_config')
gpio_set = getattr(self, f'gpio{name}_set')
if gpio_config.currentIndex() == 1:
gpio_set.setEnabled(True)
else:
gpio_set.setEnabled(False)
# Object config for some Devices or F/W version
def object_config_for_device(self):
if 'WIZ750' in self.curr_dev:
if version_compare('1.2.0', self.curr_ver) <= 0:
# setcmd['TR'] = self.tcp_timeout.text()
self.tcp_timeout.setEnabled(True)
else:
self.tcp_timeout.setEnabled(False)
# 'OP' option
self.ch1_ssl_tcpclient.setEnabled(False)
self.ch1_mqttclient.setEnabled(False)
self.ch1_mqtts_client.setEnabled(False)
# 20221208 Modify baud rate temperarily
self.ch1_baud.removeItem(14)
else:
if self.ch1_baud.count() == 14:
self.ch1_baud.insertItem(14, "460800")
# SC: Status pin option
if 'WIZ107' in self.curr_dev or 'WIZ108' in self.curr_dev:
pass
else:
if self.curr_dev in SECURITY_DEVICE:
self.radiobtn_group_s0.hide()
self.radiobtn_group_s1.hide()
self.group_dtrdsr.show()
if 'WIZ5XXSR' in self.curr_dev or 'W55RP20-S2E' in self.curr_dev or 'W232N' in self.curr_dev:
self.groupbox_ch1_timeout.show()
self.groupbox_ch1_timeout.setEnabled(True)
else:
self.groupbox_ch1_timeout.hide()
self.groupbox_ch1_timeout.setEnabled(False)
else:
self.radiobtn_group_s0.show()
self.radiobtn_group_s1.show()
self.group_dtrdsr.hide()
self.groupbox_ch1_timeout.hide()
if self.curr_dev in SECURITY_DEVICE:
self.tcp_timeout.setEnabled(True)
self.factory_setting_action.setEnabled(True)
self.factory_firmware_action.setEnabled(True)
# 'OP' option
self.ch1_ssl_tcpclient.setEnabled(True)
self.ch1_mqttclient.setEnabled(True)
self.ch1_mqtts_client.setEnabled(True)
# Current bank (RO)
self.group_current_bank.show()
if 'WIZ5XXSR' in self.curr_dev or 'W55RP20-S2E' in self.curr_dev or 'W232N' in self.curr_dev:
self.group_current_bank.hide()
# self.combobox_current_bank.setEnabled(True)
else:
self.combobox_current_bank.setEnabled(False)
else:
self.factory_setting_action.setEnabled(True)
self.factory_firmware_action.setEnabled(False)
# 'OP' option
self.ch1_ssl_tcpclient.setEnabled(False)
self.ch1_mqttclient.setEnabled(False)
self.ch1_mqtts_client.setEnabled(False)
# Current bank (RO)
self.group_current_bank.hide()
# op channel#2 option
self.ch2_ssl_tcpclient.setEnabled(False)
self.ch2_mqttclient.setEnabled(False)
self.ch2_mqtts_client.setEnabled(False)
def general_tab_config(self):
# General tab ui setup by device
if self.curr_dev in SECURITY_DEVICE:
# self.logger.debug(f'general_tab_config() length: {len(self.generalTab)}')
if len(self.generalTab) < 4:
# self.generalTab.insertTab(3, self.wiz510ssl_tab, self.wiz510ssl_tab_text)
self.generalTab.insertTab(3, self.mqtt_tab, self.mqtt_tab_text)
self.generalTab.insertTab(4, self.certificate_tab, self.certificate_tab_text)
self.generalTab.setTabEnabled(3, True)
self.generalTab.setTabEnabled(4, True)
# self.generalTab.setTabEnabled(5, True)
# self.group_setting_pw.setEnabled(False)
else:
# self.generalTab.removeTab(5)
self.generalTab.removeTab(4)
self.generalTab.removeTab(3)
# User I/O tab
"""
- WIZ750SR
- WIZ750SR-100
- WIZ5XXSR-RP (only use A,B)
"""
# if 'WIZ750' in self.curr_dev or 'W7500' in self.curr_dev or 'WIZ5XX' in self.curr_dev:
if 'WIZ750' in self.curr_dev or 'W7500' in self.curr_dev:
# ! Check current tab length
# self.logger.debug(f'totalTab: {len(self.generalTab)}, currentTab: {self.generalTab.currentIndex()}')
# self.generalTab.insertTab(2, self.userio_tab, self.userio_tab_text)
# self.generalTab.setTabEnabled(2, True)
if 'WIZ5XXSR' in self.curr_dev or self.curr_dev in ['W55RP20-S2E', 'W232N']:
# if len(self.generalTab) == 4:
# # Basic settings / User I/O / Options / MQTT Options / Certificate manager
# self.generalTab.insertTab(2, self.userio_tab, self.userio_tab_text)
# self.generalTab.setTabEnabled(2, True)
# # Use IO A, B only
# self.frame_gpioc.setEnabled(False)
# self.frame_gpiod.setEnabled(False)
pass # Assuming 'WIZ5XXSR' includes 'W55RP20-S2E', 'W232N'
else:
if len(self.generalTab) == 2:
# Basic settings / User I/O / Options
self.generalTab.insertTab(2, self.userio_tab, self.userio_tab_text)
self.generalTab.setTabEnabled(2, True)
elif len(self.generalTab) == 3:
if self.generalTab.tabText(2) == self.userio_tab_text:
pass
else:
# Exception case: Basic settings / Options / MQTT Options
self.generalTab.removeTab(2)
self.generalTab.insertTab(2, self.userio_tab, self.userio_tab_text)
self.generalTab.setTabEnabled(2, True)
self.frame_gpioc.setEnabled(True)
self.frame_gpiod.setEnabled(True)
else:
if self.curr_dev in SECURITY_DEVICE:
if len(self.generalTab) == 5:
# Remove userio tab
self.generalTab.removeTab(2)
elif len(self.generalTab) == 4:
# Already removed userio tab
pass
# else:
# self.generalTab.removeTab(2)
def channel_tab_config(self):
# channel tab config
if self.curr_dev in ONE_PORT_DEV or 'WIZ750' in self.curr_dev or self.curr_dev in SECURITY_DEVICE:
self.channel_tab.removeTab(1)
self.channel_tab.setTabEnabled(0, True)
elif self.curr_dev in TWO_PORT_DEV or 'WIZ752' in self.curr_dev:
self.channel_tab.insertTab(1, self.tab_ch1, self.ch1_tab_text)
self.channel_tab.setTabEnabled(0, True)
self.channel_tab.setTabEnabled(1, True)
def event_localport_fix(self):
if self.ch1_localport_fix.isChecked():
self.ch1_localport.setEnabled(False)
else:
self.ch1_localport.setEnabled(True)
def event_ip_alloc(self):
if self.ip_dhcp.isChecked():
self.localip.setEnabled(False)
self.subnet.setEnabled(False)
self.gateway.setEnabled(False)
self.dns_addr.setEnabled(False)
else:
self.localip.setEnabled(True)
self.subnet.setEnabled(True)
self.gateway.setEnabled(True)
self.dns_addr.setEnabled(True)
def event_keepalive(self):
if self.ch1_keepalive_enable.isChecked():
self.ch1_keepalive_initial.setEnabled(True)
self.ch1_keepalive_retry.setEnabled(True)
else:
self.ch1_keepalive_initial.setEnabled(False)
self.ch1_keepalive_retry.setEnabled(False)
if self.ch2_keepalive_enable.isChecked():
self.ch2_keepalive_initial.setEnabled(True)
self.ch2_keepalive_retry.setEnabled(True)
else:
self.ch2_keepalive_initial.setEnabled(False)
self.ch2_keepalive_retry.setEnabled(False)
def event_atmode(self):
if self.at_enable.isChecked():
self.at_hex1.setEnabled(True)
self.at_hex2.setEnabled(True)
self.at_hex3.setEnabled(True)
else:
self.at_hex1.setEnabled(False)
self.at_hex2.setEnabled(False)
self.at_hex3.setEnabled(False)
def event_input_idcode(self):
if self.show_idcodeinput.isChecked():
self.searchcode_input.setEchoMode(QLineEdit.Normal)
else:
self.searchcode_input.setEchoMode(QLineEdit.Password)
def event_idcode(self):
if self.show_idcode.isChecked():
self.searchcode.setEchoMode(QLineEdit.Normal)
else:
self.searchcode.setEchoMode(QLineEdit.Password)
def event_passwd(self):
if self.show_connectpw.isChecked():
self.connect_pw.setEchoMode(QLineEdit.Normal)
else:
self.connect_pw.setEchoMode(QLineEdit.Password)
def event_passwd_enable(self):
if self.enable_connect_pw.isChecked():
self.connect_pw.setEnabled(True)
else:
self.connect_pw.setEnabled(False)
def event_opmode(self):
if self.ch1_tcpclient.isChecked():
self.ch1_remote.setEnabled(True)
self.group_packing_12.setEnabled(False)
self.modbus_protocol.setCurrentIndex(0)
elif self.ch1_tcpserver.isChecked():
self.ch1_remote.setEnabled(False)
self.group_packing_12.setEnabled(True)
elif self.ch1_tcpmixed.isChecked():
self.ch1_remote.setEnabled(True)
self.group_packing_12.setEnabled(False)
self.modbus_protocol.setCurrentIndex(0)
elif self.ch1_udp.isChecked():
self.ch1_remote.setEnabled(True)
self.group_packing_12.setEnabled(True)
elif self.ch1_ssl_tcpclient.isChecked():
self.ch1_remote.setEnabled(True)
self.group_packing_12.setEnabled(False)
self.modbus_protocol.setCurrentIndex(0)
elif self.ch1_mqttclient.isChecked():
self.ch1_remote.setEnabled(True)
self.group_packing_12.setEnabled(False)
self.modbus_protocol.setCurrentIndex(0)
elif self.ch1_mqtts_client.isChecked():
self.ch1_remote.setEnabled(True)
self.group_packing_12.setEnabled(False)
self.modbus_protocol.setCurrentIndex(0)
elif self.ch2_tcpclient.isChecked():
self.ch2_remote.setEnabled(True)
self.group_packing_12.setEnabled(False)
self.modbus_protocol.setCurrentIndex(0)
elif self.ch2_tcpserver.isChecked():
self.ch2_remote.setEnabled(False)
self.group_packing_12.setEnabled(True)
elif self.ch2_tcpmixed.isChecked():
self.ch2_remote.setEnabled(True)
self.group_packing_12.setEnabled(False)
self.modbus_protocol.setCurrentIndex(0)
elif self.ch2_udp.isChecked():
self.ch2_remote.setEnabled(True)
self.group_packing_12.setEnabled(True)
def event_search_method(self):
if self.broadcast.isChecked():
self.search_ipaddr.setEnabled(False)
self.search_port.setEnabled(False)
elif self.unicast_ip.isChecked():
self.search_ipaddr.setEnabled(True)
self.search_port.setEnabled(True)
def sock_close(self):
# 기존 연결 fin
if self.cli_sock is not None:
if self.cli_sock.state != SockState.SOCK_CLOSE:
self.cli_sock.shutdown()
def connect_over_tcp(self, serverip, port):
retrynum = 0
self.cli_sock = TCPClient(2, serverip, port)
# print('sock state: %r' % (self.cli_sock.state))
while True:
if retrynum > 6:
break
retrynum += 1
if self.cli_sock.state == SockState.SOCK_CLOSE:
self.cli_sock.shutdown()
try:
self.cli_sock.open()
if self.cli_sock.state == SockState.SOCK_OPEN:
self.logger.info('[%r] is OPEN' % (serverip))
time.sleep(0.2)
except Exception as e:
self.logger.error(e)
elif self.cli_sock.state == SockState.SOCK_OPEN:
try:
self.cli_sock.connect()
if self.cli_sock.state == SockState.SOCK_CONNECT:
self.logger.info('[%r] is CONNECTED' % (serverip))
except Exception as e:
self.logger.error(e)
elif self.cli_sock.state == SockState.SOCK_CONNECT:
break
if retrynum > 6:
self.logger.info('Device [%s] TCP connection failed.\r\n' % (serverip))
return None
else:
self.logger.info('Device [%s] TCP connected\r\n' % (serverip))
return self.cli_sock
def socket_config(self):
try:
# Broadcast
if self.broadcast.isChecked():
if self.selected_eth is None:
self.conf_sock = WIZUDPSock(5000, 50001, "")
else:
self.conf_sock = WIZUDPSock(5000, 50001, self.selected_eth)
self.logger.debug(self.selected_eth)
self.conf_sock.open()
# TCP unicast
elif self.unicast_ip.isChecked():
ip_addr = self.search_ipaddr.text()
port = int(self.search_port.text())
self.logger.info('unicast: ip: %r, port: %r' % (ip_addr, port))
# network check
net_response = self.net_check_ping(ip_addr)
if net_response == 0:
self.conf_sock = self.connect_over_tcp(ip_addr, port)
if self.conf_sock is None:
self.isConnected = False
self.logger.info('TCP connection failed!: %s' % self.conf_sock)
self.statusbar.showMessage(' TCP connection failed: %s' % ip_addr)
self.msg_connection_failed()
else:
self.isConnected = True
self.btn_search.setEnabled(True)
else:
self.statusbar.showMessage(' Network unreachable: %s' % ip_addr)
self.btn_search.setEnabled(True)
self.msg_not_connected(ip_addr)
except Exception as e:
self.logger.error(f'socket_config error: {e}')
# expansion GPIO config
def refresh_gpio(self, mac_addr):
if self.wizmsghandler is not None and self.wizmsghandler.isRunning():
self.wizmsghandler.wait()
else:
for thread in self.threads:
thread.terminate()
##
cmd_list = []
if self.isConnected or self.broadcast.isChecked():
# if len(self.searchcode_input.text()) == 0:
if not self.searchcode_input.text():
self.code = " "
else:
self.code = self.searchcode_input.text()
cmd_list = self.wizmakecmd.get_gpiovalue(mac_addr, self.code, self.curr_dev)
# print('refresh_gpio', cmd_list)
if self.unicast_ip.isChecked():
self.datarefresh = DataRefresh(self.conf_sock, cmd_list, 'tcp', self.intv_time)
else:
self.datarefresh = DataRefresh(self.conf_sock, cmd_list, 'udp', self.intv_time)
self.threads.append(self.datarefresh)
self.datarefresh.resp_check.connect(self.gpio_update)
self.datarefresh.start()
def get_refresh_time(self):
self.selected_devinfo()
if self.refresh_no.isChecked():
self.intv_time = 0
elif self.refresh_1s.isChecked():
self.intv_time = 1
elif self.refresh_5s.isChecked():
self.intv_time = 5
elif self.refresh_10s.isChecked():
self.intv_time = 10
elif self.refresh_30s.isChecked():
self.intv_time = 30
self.refresh_gpio(self.curr_mac)
def gpio_update(self, num):
if num == 0:
pass
else:
if not self.datarefresh.rcv_list:
pass
else:
resp = self.datarefresh.rcv_list[0]
# cmdset_list = resp.splitlines()
cmdset_list = resp.split(b"\r\n")
try:
# Expansion GPIO
for i in range(len(cmdset_list)):
if num < 2:
if b'CA' in cmdset_list[i]:
self.gpioa_config.setCurrentIndex(int(cmdset_list[i][2:]))
if b'CB' in cmdset_list[i]:
self.gpiob_config.setCurrentIndex(int(cmdset_list[i][2:]))
if b'CC' in cmdset_list[i]:
self.gpioc_config.setCurrentIndex(int(cmdset_list[i][2:]))
if b'CD' in cmdset_list[i]:
self.gpiod_config.setCurrentIndex(int(cmdset_list[i][2:]))
if b'GA' in cmdset_list[i]:
self.gpioa_get.setText(cmdset_list[i][2:].decode())
if b'GB' in cmdset_list[i]:
self.gpiob_get.setText(cmdset_list[i][2:].decode())
if b'GC' in cmdset_list[i]:
self.gpioc_get.setText(cmdset_list[i][2:].decode())
if b'GD' in cmdset_list[i]:
self.gpiod_get.setText(cmdset_list[i][2:].decode())
except Exception as e:
self.logger.error(e)
def do_search_retry(self, num):
try:
self.search_retry_flag = True
# search retry number
self.search_retrynum = num
self.logger.info(self.mac_list)
self.search_pre()
except Exception as e:
self.logger.error(f'do_search_normal error: {e}')
self.search_error_msgbox()
def do_search_normal(self):
try:
self.search_retry_flag = False
self.search_pre()
except Exception as e:
self.logger.error(f'do_search_normal error: {e}')
self.search_error_msgbox()
def search_error_msgbox(self):
self.show_msgbox(
"Device search failed",
"There was a problem searching the device.\nCheck and set the network adapter.",
QMessageBox.Warning
)
def search_pre(self):
if self.wizmsghandler is not None and self.wizmsghandler.isRunning():
self.wizmsghandler.wait()
# print('wait')
else:
# 기존 연결 close
self.sock_close()
cmd_list = []
# default search id code
self.code = " "
self.all_response = []
self.pgbar.setFormat('Search all devices...')
self.pgbar.setRange(0, 100)
self.search_progress_thread.start()
self.processing(self.search_pre_wait_time * 1000)
if self.search_retry_flag:
self.logger.info('keep searched list')
pass
else:
# List table initial (clear)
self.list_device.clear()
while self.list_device.rowCount() > 0:
self.list_device.removeRow(0)
item_mac = QTableWidgetItem()
item_mac.setText("Mac address")
item_mac.setFont(self.midfont)
self.list_device.setHorizontalHeaderItem(0, item_mac)
item_name = QTableWidgetItem()
item_name.setText("Name")
item_name.setFont(self.midfont)
self.list_device.setHorizontalHeaderItem(1, item_name)
# Set socket for search
self.socket_config()
self.logger.debug('search: conf_sock: %s' % self.conf_sock)