replace last references to device by module
Change-Id: I2b7099715c356054aad21895f11b13547f104a88 Reviewed-on: https://forge.frm2.tum.de/review/17126 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
parent
8538659b22
commit
8e7908f9b7
@ -101,7 +101,7 @@ import mlzlog
|
|||||||
|
|
||||||
from secop.protocol.encoding import ENCODERS
|
from secop.protocol.encoding import ENCODERS
|
||||||
from secop.protocol.framing import FRAMERS
|
from secop.protocol.framing import FRAMERS
|
||||||
from secop.protocol.messages import *
|
from secop.protocol.messages import EventMessage, DescribeRequest
|
||||||
|
|
||||||
|
|
||||||
class TCPConnection(object):
|
class TCPConnection(object):
|
||||||
@ -146,20 +146,20 @@ class TCPConnection(object):
|
|||||||
self.handle(msg)
|
self.handle(msg)
|
||||||
|
|
||||||
def handle(self, msg):
|
def handle(self, msg):
|
||||||
if isinstance(msg, AsyncDataUnit):
|
if isinstance(msg, EventMessage):
|
||||||
self.log.info("got Async: %r" % msg)
|
self.log.info("got Async: %r" % msg)
|
||||||
for cb in self.callbacks:
|
for cb in self.callbacks:
|
||||||
try:
|
try:
|
||||||
cb(msg)
|
cb(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
"handle_async: got exception %r" % e, exception=true)
|
"handle_async: got exception %r" % e, exception=True)
|
||||||
else:
|
else:
|
||||||
self.queue.append(msg)
|
self.queue.append(msg)
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
while not len(self.queue):
|
while not self.queue:
|
||||||
pass
|
pass # XXX: remove BUSY polling
|
||||||
return self.queue.popleft()
|
return self.queue.popleft()
|
||||||
|
|
||||||
def register_callback(self, callback):
|
def register_callback(self, callback):
|
||||||
@ -181,15 +181,15 @@ class Client(object):
|
|||||||
|
|
||||||
def handle_async(self, msg):
|
def handle_async(self, msg):
|
||||||
self.log.info("Got async update %r" % msg)
|
self.log.info("Got async update %r" % msg)
|
||||||
device = msg.device
|
module = msg.module
|
||||||
param = msg.param
|
param = msg.param
|
||||||
value = msg.value
|
value = msg.value
|
||||||
self._cache.getdefault(device, {})[param] = value
|
self._cache.getdefault(module, {})[param] = value
|
||||||
# XXX: further notification-callbacks needed ???
|
# XXX: further notification-callbacks needed ???
|
||||||
|
|
||||||
def populateNamespace(self, namespace):
|
def populateNamespace(self, namespace):
|
||||||
self.connection.send(ListModulesRequest())
|
self.connection.send(DescribeRequest())
|
||||||
# reply = self.connection.read()
|
# reply = self.connection.read()
|
||||||
# self.log.info("found devices %r" % reply)
|
# self.log.info("found modules %r" % reply)
|
||||||
# create proxies, populate cache....
|
# create proxies, populate cache....
|
||||||
namespace.setconst('connection', self.connection)
|
namespace.setconst('connection', self.connection)
|
||||||
|
@ -181,9 +181,9 @@ class Client(object):
|
|||||||
exception = info
|
exception = info
|
||||||
self.log = logStub()
|
self.log = logStub()
|
||||||
self._cache = dict()
|
self._cache = dict()
|
||||||
if 'device' in opts:
|
if 'module' in opts:
|
||||||
# serial port
|
# serial port
|
||||||
devport = opts.pop('device')
|
devport = opts.pop('module')
|
||||||
baudrate = int(opts.pop('baudrate', 115200))
|
baudrate = int(opts.pop('baudrate', 115200))
|
||||||
self.contactPoint = "serial://%s:%s" % (devport, baudrate)
|
self.contactPoint = "serial://%s:%s" % (devport, baudrate)
|
||||||
self.connection = serial.Serial(
|
self.connection = serial.Serial(
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#
|
#
|
||||||
# *****************************************************************************
|
# *****************************************************************************
|
||||||
|
|
||||||
"""Utilities for devices that require sequenced actions on value change."""
|
"""Utilities for modules that require sequenced actions on value change."""
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
@ -98,11 +98,11 @@ class SequencerMixin(object):
|
|||||||
**Error handling**
|
**Error handling**
|
||||||
|
|
||||||
If *fault_on_error* in ``init_sequencer`` is true and an exception is
|
If *fault_on_error* in ``init_sequencer`` is true and an exception is
|
||||||
raised during an atomic step, the device goes into an ERROR state
|
raised during an atomic step, the module goes into an ERROR state
|
||||||
because it cannot be ensured that further actions will be safe to
|
because it cannot be ensured that further actions will be safe to
|
||||||
execute. A manual reset is required.
|
execute. A manual reset is required.
|
||||||
|
|
||||||
Otherwise, the device goes into the WARN state and can be started
|
Otherwise, the module goes into the WARN state and can be started
|
||||||
again normally.
|
again normally.
|
||||||
|
|
||||||
**Stop handling**
|
**Stop handling**
|
||||||
@ -111,7 +111,7 @@ class SequencerMixin(object):
|
|||||||
which is set by the mixin's ``Stop`` method.
|
which is set by the mixin's ``Stop`` method.
|
||||||
|
|
||||||
The *fault_on_stop* argument in ``init_sequencer`` controls which state
|
The *fault_on_stop* argument in ``init_sequencer`` controls which state
|
||||||
the device enters when the sequence is interrupted by a stop. Here,
|
the module enters when the sequence is interrupted by a stop. Here,
|
||||||
the default is to only go into ALARM.
|
the default is to only go into ALARM.
|
||||||
"""
|
"""
|
||||||
if self.seq_is_alive():
|
if self.seq_is_alive():
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
import os
|
import os
|
||||||
import ast
|
import ast
|
||||||
import time
|
import time
|
||||||
import psutil
|
|
||||||
import threading
|
import threading
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
@ -105,15 +104,15 @@ class Server(object):
|
|||||||
|
|
||||||
self._interfaces = []
|
self._interfaces = []
|
||||||
|
|
||||||
deviceopts = []
|
moduleopts = []
|
||||||
interfaceopts = []
|
interfaceopts = []
|
||||||
equipment_id = None
|
equipment_id = None
|
||||||
nodeopts = []
|
nodeopts = []
|
||||||
for section in parser.sections():
|
for section in parser.sections():
|
||||||
if section.lower().startswith('device '):
|
if section.lower().startswith('module '):
|
||||||
# device section
|
# module section
|
||||||
# omit leading 'device ' string
|
# omit leading 'module ' string
|
||||||
devname = section[len('device '):]
|
devname = section[len('module '):]
|
||||||
devopts = dict(item for item in parser.items(section))
|
devopts = dict(item for item in parser.items(section))
|
||||||
if 'class' not in devopts:
|
if 'class' not in devopts:
|
||||||
self.log.error('Module %s needs a class option!')
|
self.log.error('Module %s needs a class option!')
|
||||||
@ -123,7 +122,7 @@ class Server(object):
|
|||||||
# try to import the class, raise if this fails
|
# try to import the class, raise if this fails
|
||||||
devopts['class'] = get_class(devopts['class'])
|
devopts['class'] = get_class(devopts['class'])
|
||||||
# all went well so far
|
# all went well so far
|
||||||
deviceopts.append([devname, devopts])
|
moduleopts.append([devname, devopts])
|
||||||
if section.lower().startswith('interface '):
|
if section.lower().startswith('interface '):
|
||||||
# interface section
|
# interface section
|
||||||
# omit leading 'interface ' string
|
# omit leading 'interface ' string
|
||||||
@ -161,14 +160,14 @@ class Server(object):
|
|||||||
self._dispatcher = self._buildObject(
|
self._dispatcher = self._buildObject(
|
||||||
'Dispatcher', Dispatcher, nodeopts)
|
'Dispatcher', Dispatcher, nodeopts)
|
||||||
self._processInterfaceOptions(interfaceopts)
|
self._processInterfaceOptions(interfaceopts)
|
||||||
self._processModuleOptions(deviceopts)
|
self._processModuleOptions(moduleopts)
|
||||||
|
|
||||||
def _processModuleOptions(self, deviceopts):
|
def _processModuleOptions(self, moduleopts):
|
||||||
# check devices opts by creating them
|
# check modules opts by creating them
|
||||||
devs = []
|
devs = []
|
||||||
for devname, devopts in deviceopts:
|
for devname, devopts in moduleopts:
|
||||||
devclass = devopts.pop('class')
|
devclass = devopts.pop('class')
|
||||||
# create device
|
# create module
|
||||||
self.log.debug('Creating Module %r' % devname)
|
self.log.debug('Creating Module %r' % devname)
|
||||||
export = devopts.pop('export', '1')
|
export = devopts.pop('export', '1')
|
||||||
export = export.lower() in ('1', 'on', 'true', 'yes')
|
export = export.lower() in ('1', 'on', 'true', 'yes')
|
||||||
@ -184,13 +183,13 @@ class Server(object):
|
|||||||
self.log.getChild(devname), devopts, devname, self._dispatcher)
|
self.log.getChild(devname), devopts, devname, self._dispatcher)
|
||||||
devs.append([devname, devobj, export])
|
devs.append([devname, devobj, export])
|
||||||
|
|
||||||
# connect devices with dispatcher
|
# connect modules with dispatcher
|
||||||
for devname, devobj, export in devs:
|
for devname, devobj, export in devs:
|
||||||
self.log.info('registering device %r' % devname)
|
self.log.info('registering module %r' % devname)
|
||||||
self._dispatcher.register_module(devobj, devname, export)
|
self._dispatcher.register_module(devobj, devname, export)
|
||||||
# also call init on the devices
|
# also call init on the modules
|
||||||
devobj.init()
|
devobj.init()
|
||||||
# call a possibly empty postinit on each device after registering all
|
# call a possibly empty postinit on each module after registering all
|
||||||
for _devname, devobj, _export in devs:
|
for _devname, devobj, _export in devs:
|
||||||
postinit = getattr(devobj, 'postinit', None)
|
postinit = getattr(devobj, 'postinit', None)
|
||||||
if postinit:
|
if postinit:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user