Skip to content

Commit

Permalink
autod was moved from each device to main
Browse files Browse the repository at this point in the history
so made it work with on thread
  • Loading branch information
jinwon0325kim committed May 2, 2023
1 parent 685dffd commit 13b5c87
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 97 deletions.
84 changes: 47 additions & 37 deletions src/auto_onboarding/auto_onboardingmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def printResult(self):

class auto_onboardingWindow(QMainWindow):
dialog_closed = pyqtSignal(str)
force_close = pyqtSignal()

def __init__(self, parent):
super(auto_onboardingWindow, self).__init__()
Expand Down Expand Up @@ -261,13 +260,13 @@ def auto_multi_onboarding(self):
continue
self.order.insert(0, self.objs[i].comport)
self.load_device_window(i)
QTest.qWait(200)
if checked:
try:
comport = self.order.pop()
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
if comport in self.parent.dialog:
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
except IndexError:
err = simpleDlg("No device is selected",
"Check the device for onboarding")
Expand All @@ -283,17 +282,18 @@ def auto_multi_removing(self):
checked = False
for i in range(len(self.objs)):
if self.objs[i].chkbox.isChecked():
checked = True
if not self.objs[i].comport in self.parent.dialog:
print(f"{self.objs[i].comport} is not onboarded")
continue
checked = True
self.order.insert(0, self.objs[i].comport)
if checked:
try:
comport = self.order.pop()
if self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
if comport in self.parent.dialog:
if self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
except IndexError:
err = simpleDlg("No device is selected",
"Check the device for removing")
Expand All @@ -318,9 +318,10 @@ def auto_single_repeat(self):
comport = self.objs[checkedIndex].comport
self.report.try_count += 1
print(f"{self.report.try_count}th try...")
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
if comport in self.parent.dialog:
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
else:
err = simpleDlg(
"Wrong input", "Only one device can use Auto onboarding repeat test!!")
Expand All @@ -337,8 +338,6 @@ def load_device_window(self, i):
self.device_name.insert(i, f'{device_type}-{deviceNum}')

if self.parent.create_device_window(deviceNum, discriminator, threadType, comPort, debugLevel, device_type):
self.parent.dialog[comPort].get_window(
).update_onboarding.connect(self.update_status)
if not self.parent.dialog[comPort].get_window().chkbox_auto.isChecked():
self.parent.dialog[comPort].get_window().chkbox_auto.toggle()

Expand All @@ -358,17 +357,20 @@ def multi_device_process(self, index, value, comport, device_num):
time.sleep(1)
if len(self.order) > 0 and value < 2: # keep proceed multi onboarding
next = self.order.pop()
if not self.parent.dialog[next].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[next].get_window(
).pushButtonDevicePower.toggle()
if next in self.parent.dialog:
if not self.parent.dialog[next].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[next].get_window(
).pushButtonDevicePower.toggle()
elif len(self.order) > 0 and value >= 2: # keep proceed multi removing
self.parent.dialog[comport].get_window().force_closeEvent()
next = self.order.pop()
if self.parent.dialog[next].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[next].get_window(
).pushButtonDevicePower.toggle()
if next in self.parent.dialog:
if self.parent.dialog[next].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[next].get_window(
).pushButtonDevicePower.toggle()
elif value >= 2: # keep proceed multi removing
self.parent.dialog[comport].get_window().force_closeEvent()
if comport in self.parent.dialog:
self.parent.dialog[comport].get_window().force_closeEvent()

def single_repeat_process(self, index, value, comport, device_num):
# onboarding
Expand All @@ -377,9 +379,10 @@ def single_repeat_process(self, index, value, comport, device_num):
self.report.success += 1
# time.sleep(3)
QCoreApplication.processEvents()
if self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
if comport in self.parent.dialog:
if self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
# self.parent.dialog[comport].get_window().auto_remove()
elif value == ONBOARDING_FAILURE: # failed
self.objs[index].status.setText("failed")
Expand All @@ -388,18 +391,21 @@ def single_repeat_process(self, index, value, comport, device_num):
self.report.try_count += 1
print(
f"{self.report.onboarding_failure} onboarding failed.. \n{self.report.try_count}th try...")
self.parent.dialog[comport].get_window().force_closeEvent()
if comport in self.parent.dialog:
self.parent.dialog[comport].get_window().force_closeEvent()
QTest.qWait(5000)
self.load_device_window(index)
# time.sleep(1)
QCoreApplication.processEvents()
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
if comport in self.parent.dialog:
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
# removing
elif value == REMOVING_SUCCESS: # success
self.objs[index].status.setText("ready")
self.parent.dialog[comport].get_window().force_closeEvent()
if comport in self.parent.dialog:
self.parent.dialog[comport].get_window().force_closeEvent()
self.report.remove += 1
# self.report.try_count += 1
if self.report.try_count >= self.report.total_count:
Expand All @@ -411,17 +417,19 @@ def single_repeat_process(self, index, value, comport, device_num):
self.load_device_window(index)
# time.sleep(1)
QCoreApplication.processEvents()
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
if comport in self.parent.dialog:
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
elif value == REMOVING_FAILURE: # failed
self.objs[index].status.setText(f'{self.device_name[index]}')
self.report.retry_remove += 1
if (self.report.retry_remove >= 3): # ignore removing failure and proceed next step
self.report.retry_remove = 0
self.report.removing_failure += 1
# self.report.try_count += 1
self.parent.dialog[comport].get_window().force_closeEvent()
if comport in self.parent.dialog:
self.parent.dialog[comport].get_window().force_closeEvent()
# self.parent.dialog[comport].get_window().dialog_closed.emit(self.parent.dialog[comport].get_window().device_info.com_port)
if self.report.try_count > self.report.total_count:
self.report.printResult()
Expand All @@ -431,11 +439,13 @@ def single_repeat_process(self, index, value, comport, device_num):
print(f"{self.report.try_count}th try...")
QTest.qWait(5000)
self.load_device_window(index)
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
if comport in self.parent.dialog:
if not self.parent.dialog[comport].get_window().pushButtonDevicePower.isChecked():
self.parent.dialog[comport].get_window(
).pushButtonDevicePower.toggle()
else:
self.parent.dialog[comport].get_window().auto_remove()
if comport in self.parent.dialog:
self.parent.dialog[comport].get_window().auto_remove()

@pyqtSlot(int, str, str)
def update_status(self, value, comport, device_num):
Expand Down
Loading

0 comments on commit 13b5c87

Please sign in to comment.