[WIP] fixes for gas10ka / varioxB

treat proxy for io correctly
This commit is contained in:
l_samenv
2024-06-10 10:11:03 +02:00
parent b1f9c74269
commit 67fa50a9e0
10 changed files with 855 additions and 59 deletions

View File

@@ -260,6 +260,7 @@ class ProxyClient:
cblist = self.callbacks[cbname].get(key, [])
for cbfunc in list(cblist):
try:
# print("CALLBACK", cbname, repr(key), *args)
cbfunc(*args)
except UnregisterCallback:
cblist.remove(cbfunc)
@@ -370,9 +371,10 @@ class SecopClient(ProxyClient):
# pylint: disable=unsubscriptable-object
self._init_descriptive_data(self.request(DESCRIPTIONREQUEST)[2])
self.nodename = self.properties.get('equipment_id', self.uri)
self._set_state(True, 'connected')
if self.activate:
self._set_state(True, 'activating')
self.request(ENABLEEVENTSREQUEST)
self._set_state(True, 'connected')
break
except Exception:
# print(formatExtendedTraceback())
@@ -493,6 +495,8 @@ class SecopClient(ProxyClient):
return
if self.activate:
self.log.info('try to reconnect to %s', self.uri)
if self._connthread:
print('WARN connthread is still there')
self._connthread = mkthread(self._reconnect)
else:
self.log.warning('%s disconnected', self.uri)
@@ -509,11 +513,15 @@ class SecopClient(ProxyClient):
def _reconnect(self, connected_callback=None):
while not self._shutdown.is_set():
try:
# print('_reconnect_connect')
self.connect()
# print('_reconnect_success')
if connected_callback:
connected_callback()
# print('_reconnect_break')
break
except Exception as e:
# print('_reconnect_exc', e)
txt = str(e).split('\n', 1)[0]
if txt != self._last_error:
self._last_error = txt

View File

@@ -218,6 +218,8 @@ class AsynTcp(AsynConn):
except (socket.timeout, TimeoutError):
# timeout while waiting
return b''
except ConnectionResetError:
pass # treat the same as gracefully disconnected peer
# note that when no data is sent on a connection, an interruption might
# not be detected within a reasonable time. sending a heartbeat should
# help in this case.

View File

@@ -56,6 +56,20 @@ class HasControlledBy:
for deactivate_control in self.inputCallbacks.values():
deactivate_control(self.name)
def update_target(self, module, value):
"""update internal target value
as write_target would switch to manual mode, the controlling module
has to use this method to update the value
override and super call, if other actions are needed
"""
if self.controlled_by != module:
deactivate_control = self.inputCallbacks.get(self.controlled_by)
if deactivate_control:
deactivate_control(module)
self.target = value
class HasOutputModule:
"""mixin for modules having an output module

View File

@@ -30,6 +30,12 @@ from frappy.properties import Property
from frappy.io import HasIO
DISCONNECTED = Readable.Status.ERROR, 'disconnected'
ACTIVATING = Readable.Status.IDLE, 'activating'
CONNECTED = Readable.Status.IDLE, 'connected'
CONN_STATI = {DISCONNECTED, ACTIVATING, CONNECTED}
class ProxyModule(HasIO, Module):
module = Property('remote module name', datatype=StringType(), default='')
status = Parameter('connection status', Readable.status.datatype) # add status even when not a Readable
@@ -108,19 +114,22 @@ class ProxyModule(HasIO, Module):
# for now, the error message must be enough
def nodeStateChange(self, online, state):
disconnected = Readable.Status.ERROR, 'disconnected'
if online:
if not self._consistency_check_done:
self._check_descriptive_data()
self._consistency_check_done = True
if self.status == disconnected:
self.status = Readable.Status.IDLE, 'connected'
if state == 'activating':
self.status = ACTIVATING
else:
if not self._consistency_check_done:
self._check_descriptive_data()
self._consistency_check_done = True
if self.status[0] in CONN_STATI:
# avoid overriding remote status
self.status = CONNECTED
else:
readerror = CommunicationFailedError('disconnected')
if self.status != disconnected:
if self.status != DISCONNECTED:
for pname in set(self.parameters) - set(('module', 'status')):
self.announceUpdate(pname, None, readerror)
self.status = disconnected
self.status = DISCONNECTED
def checkProperties(self):
pass # skip