From c5671dd26edab468bedf84313c0469e8f98cd0aa Mon Sep 17 00:00:00 2001 From: Enrico Faulhaber Date: Wed, 13 Sep 2017 09:32:59 +0200 Subject: [PATCH] implement Writable as specified. Change-Id: I8a1b192dcfba91ae1828a2b2e0e2e8bd24538c08 --- etc/test.cfg | 4 ++++ secop/modules.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- secop_demo/test.py | 8 +++++++- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/etc/test.cfg b/etc/test.cfg index f8616de..7f9aa5d 100644 --- a/etc/test.cfg +++ b/etc/test.cfg @@ -36,3 +36,7 @@ sensor="X34598T8" class=secop_demo.modules.CoilTemp sensor="X34598T9" + +[device Lower] +class=secop_demo.test.Lower + diff --git a/secop/modules.py b/secop/modules.py index 7dcd3a1..66149f2 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -431,7 +431,7 @@ class Readable(Module): datatype=TupleOf( EnumType(**{ 'IDLE': status.OK, - 'BUSY': status.BUSY, +# 'BUSY': status.BUSY, 'WARN': status.WARN, 'UNSTABLE': status.UNSTABLE, 'ERROR': status.ERROR, @@ -481,15 +481,15 @@ class Readable(Module): rfunc = getattr(self, 'read_' + pname, None) if rfunc: try: - # self.log.info('polling read_%s -> %r' % (pname, rfunc())) + # self.log.info('polling read_%s -> %r' % (pname, rfunc())) rfunc() except Exception: # really all! pass return fastpoll -class Drivable(Readable): - """Basic Drivable Module +class Writable(Readable): + """Basic Writable Module providing a settable 'target' parameter to those of a Readable """ @@ -503,3 +503,41 @@ class Drivable(Readable): } # XXX: CMDS ???? auto deriving working well enough? + +class Drivable(Writable): + """Basic Drivable Module + + provides a stop command to interrupt actions. + Also status gets extended with a BUSY state indicating a running action. + """ + + OVERRIDES = { + "status" : OVERRIDE(datatype=TupleOf( + EnumType(**{ + 'IDLE': status.OK, + 'BUSY': status.BUSY, + 'WARN': status.WARN, + 'UNSTABLE': status.UNSTABLE, + 'ERROR': status.ERROR, + 'UNKNOWN': status.UNKNOWN + }), StringType())), + } + + def do_stop(self): + """default implementation of the stop command + + by default does nothing.""" + + +class Communicator(Module): + """Basic communication Module + + providing no parameters, but a 'communicate' command. + """ + + CMDS = { + "communicate" : CMD("provides the simplest mean to communication", + arguments=[StringType()], + result=StringType() + ), + } diff --git a/secop_demo/test.py b/secop_demo/test.py index 40e385c..befec99 100644 --- a/secop_demo/test.py +++ b/secop_demo/test.py @@ -22,7 +22,7 @@ import random -from secop.modules import Readable, Drivable, PARAM +from secop.modules import Readable, Drivable, Communicator, PARAM from secop.datatypes import FloatRange, StringType @@ -84,3 +84,9 @@ class Temp(Drivable): def write_target(self, target): pass + + +class Lower(Communicator): + """Communicator returning a lowercase version of the request""" + def do_communicate(self, request): + return str(request).lower()