Added default socket timeout/poll time in settings

This commit is contained in:
Ken Roberts 2014-10-13 17:07:54 -07:00
parent 39e574dba7
commit e5743462e2
4 changed files with 58 additions and 10 deletions

View File

@ -302,7 +302,8 @@ class Settings(QtCore.QSettings):
'projector/connect on start': False,
'projector/last directory import': '',
'projector/last directory export': '',
'projector/query time': 20 # PJLink socket timeout is 30 seconds
'projector/poll time': 20, # PJLink timeout is 30 seconds
'projector/socket timeout': 5 # 5 second socket timeout
}
__file_path__ = ''
__obsolete_settings__ = [

View File

@ -119,6 +119,15 @@ class PJLink1(QTcpSocket):
self.new_wizard = True
else:
self.new_wizard = False
if 'poll_time' in kwargs:
# Convert seconds to milliseconds
self.poll_time = kwargs['poll_time'] * 1000
else:
# Default
self.poll_time = 20000
if 'socket_timeout' in kwargs:
# Convert seconds to milliseconds
self.socket_timeout = kwargs['socket_timeout'] * 1000
self.i_am_running = False
self.status_connect = S_NOT_CONNECTED
self.last_command = ''
@ -194,9 +203,9 @@ class PJLink1(QTcpSocket):
return
log.debug('(%s) Updating projector status' % self.ip)
# Reset timer in case we were called from a set command
if self.timer.interval() < 5000:
if self.timer.interval() < self.poll_time:
# Reset timer to 5 seconds
self.timer.setInterval(5000)
self.timer.setInterval(self.poll_time)
self.timer.start()
for command in ['POWR', 'ERST', 'LAMP', 'AVMT', 'INPT']:
# Changeable information
@ -271,7 +280,11 @@ class PJLink1(QTcpSocket):
log.debug('(%s) check_login(data="%s")' % (self.ip, data))
if data is None:
# Reconnected setup?
self.waitForReadyRead(5000) # 5 seconds should be more than enough
if not self.waitForReadyRead(2000):
# Possible timeout issue
log.error('(%s) Socket timeout waiting for login' % self.ip)
self.change_status(E_SOCKET_TIMEOUT)
return
read = self.readLine(self.maxSize)
dontcare = self.readLine(self.maxSize) # Clean out the trailing \r\n
if read is None:
@ -327,7 +340,7 @@ class PJLink1(QTcpSocket):
self.send_command(cmd='CLSS', salt=salt)
self.waitForReadyRead()
if not self.new_wizard and self.state() == self.ConnectedState:
self.timer.setInterval(1000) # Set 1 second for initial information
self.timer.setInterval(2000) # Set 2 seconds for initial information
self.timer.start()
def get_data(self):

View File

@ -274,6 +274,8 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa
settings = Settings()
settings.beginGroup(self.settings_section)
self.autostart = settings.value('connect on start')
self.poll_time = settings.value('poll time')
self.socket_timeout = settings.value('socket timeout')
settings.endGroup()
del(settings)
@ -761,7 +763,9 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa
name=projector.name,
location=projector.location,
notes=projector.notes,
pin=None if projector.pin == '' else projector.pin
pin=None if projector.pin == '' else projector.pin,
poll_time=self.poll_time,
socket_timeout=self.socket_timeout
)
def add_projector(self, opt1, opt2=None):
@ -809,7 +813,7 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa
item.link.projectorAuthentication.connect(self.authentication_error)
item.link.projectorNoAuthentication.connect(self.no_authentication_error)
timer = QtCore.QTimer(self)
timer.setInterval(20000) # 20 second poll interval
timer.setInterval(self.poll_time)
timer.timeout.connect(item.link.poll_loop)
item.timer = timer
thread.start()
@ -953,6 +957,8 @@ class ProjectorItem(QObject):
self.my_parent = None
self.timer = None
self.projectordb_item = None
self.poll_time = None
self.socket_timeout = None
super(ProjectorItem, self).__init__()

View File

@ -57,15 +57,33 @@ class ProjectorTab(SettingsTab):
self.setObjectName('ProjectorTab')
super(ProjectorTab, self).setupUi()
self.connect_box = QtGui.QGroupBox(self.left_column)
self.connect_box.setTitle('Communication Options')
self.connect_box.setObjectName('connect_box')
self.connect_box_layout = QtGui.QVBoxLayout(self.connect_box)
self.connect_box_layout = QtGui.QFormLayout(self.connect_box)
self.connect_box_layout.setObjectName('connect_box_layout')
# Start comms with projectors on startup
self.connect_on_startup = QtGui.QCheckBox(self.connect_box)
self.connect_on_startup.setObjectName('connect_on_startup')
self.connect_box_layout.addWidget(self.connect_on_startup)
self.connect_box_layout.addRow(self.connect_on_startup)
# Socket timeout
self.socket_timeout_label = QtGui.QLabel(self.connect_box)
self.socket_timeout_label.setObjectName('socket_timeout_label')
self.socket_timeout_spin_box = QtGui.QSpinBox(self.connect_box)
self.socket_timeout_spin_box.setObjectName('socket_timeout_spin_box')
self.socket_timeout_spin_box.setMinimum(2)
self.socket_timeout_spin_box.setMaximum(10)
self.connect_box_layout.addRow(self.socket_timeout_label, self.socket_timeout_spin_box)
# Poll interval
self.socket_poll_label = QtGui.QLabel(self.connect_box)
self.socket_poll_label.setObjectName('socket_poll.label')
self.socket_poll_spin_box = QtGui.QSpinBox(self.connect_box)
self.socket_poll_spin_box.setObjectName('socket_timeout_spin_box')
self.socket_poll_spin_box.setMinimum(5)
self.socket_poll_spin_box.setMaximum(60)
self.connect_box_layout.addRow(self.socket_poll_label, self.socket_poll_spin_box)
self.left_layout.addWidget(self.connect_box)
self.left_layout.addStretch()
def retranslateUi(self):
@ -73,8 +91,14 @@ class ProjectorTab(SettingsTab):
Translate the UI on the fly
"""
self.tab_title_visible = UiStrings().Projectors
self.connect_box.setTitle(
translate('OpenLP.ProjectorTab', 'Communication Options'))
self.connect_on_startup.setText(
translate('OpenLP.ProjectorTab', 'Connect to projectors on startup'))
self.socket_timeout_label.setText(
translate('OpenLP.ProjectorTab', 'Socket timeout (seconds)'))
self.socket_poll_label.setText(
translate('OpenLP.ProjectorTab', 'Poll time (seconds)'))
def load(self):
"""
@ -83,6 +107,8 @@ class ProjectorTab(SettingsTab):
settings = Settings()
settings.beginGroup(self.settings_section)
self.connect_on_startup.setChecked(settings.value('connect on start'))
self.socket_timeout_spin_box.setValue(settings.value('socket timeout'))
self.socket_poll_spin_box.setValue(settings.value('poll time'))
settings.endGroup()
def save(self):
@ -92,4 +118,6 @@ class ProjectorTab(SettingsTab):
settings = Settings()
settings.beginGroup(self.settings_section)
settings.setValue('connect on start', self.connect_on_startup.isChecked())
settings.setValue('socket timeout', self.socket_timeout_spin_box.value())
settings.setValue('poll time', self.socket_poll_spin_box.value())
settings.endGroup