update doc

- add properties, parameters and commands to the doc string autoatically
- change names to "Frappy"
- started tutorial
- changed doc structure slightly

Change-Id: I87bef91384d138c738d12ddcf3a1de7f758a0973
This commit is contained in:
2021-01-19 17:20:53 +01:00
parent 2d310bc612
commit bc33933a1a
35 changed files with 655 additions and 275 deletions

View File

@@ -53,8 +53,8 @@ UNLIMITED = 1 << 64 # internal limit for integers, is probably high enough for
Parser = Parser()
# base class for all DataTypes
class DataType(HasProperties):
"""base class for all data types"""
IS_COMMAND = False
unit = ''
default = None
@@ -157,8 +157,14 @@ class Stub(DataType):
# SECoP types:
class FloatRange(DataType):
"""Restricted float type"""
"""(restricted) float type
:param minval: (property **min**)
:param maxval: (property **max**)
"""
properties = {
'min': Property('low limit', Stub('FloatRange'), extname='min', default=-sys.float_info.max),
'max': Property('high limit', Stub('FloatRange'), extname='max', default=sys.float_info.max),
@@ -170,11 +176,11 @@ class FloatRange(DataType):
extname='relative_resolution', default=1.2e-7),
}
def __init__(self, minval=None, maxval=None, **kwds):
def __init__(self, minval=None, maxval=None, **properties):
super().__init__()
kwds['min'] = minval if minval is not None else -sys.float_info.max
kwds['max'] = maxval if maxval is not None else sys.float_info.max
self.set_properties(**kwds)
properties['min'] = minval if minval is not None else -sys.float_info.max
properties['max'] = maxval if maxval is not None else sys.float_info.max
self.set_properties(**properties)
def checkProperties(self):
self.default = 0 if self.min <= 0 <= self.max else self.min
@@ -236,7 +242,11 @@ class FloatRange(DataType):
class IntRange(DataType):
"""Restricted int type"""
"""restricted int type
:param minval: (property **min**)
:param maxval: (property **max**)
"""
properties = {
'min': Property('minimum value', Stub('IntRange', -UNLIMITED, UNLIMITED), extname='min', mandatory=True),
'max': Property('maximum value', Stub('IntRange', -UNLIMITED, UNLIMITED), extname='max', mandatory=True),
@@ -296,10 +306,14 @@ class IntRange(DataType):
class ScaledInteger(DataType):
"""Scaled integer int type
"""scaled integer (= fixed resolution float) type
note: limits are for the scaled value (i.e. the internal value)
the scale is only used for calculating to/from transport serialisation"""
:param minval: (property **min**)
:param maxval: (property **max**)
note: limits are for the scaled float value
the scale is only used for calculating to/from transport serialisation
"""
properties = {
'scale': Property('scale factor', FloatRange(sys.float_info.min), extname='scale', mandatory=True),
'min': Property('low limit', FloatRange(), extname='min', mandatory=True),
@@ -312,7 +326,7 @@ class ScaledInteger(DataType):
extname='relative_resolution', default=1.2e-7),
}
def __init__(self, scale, minval=None, maxval=None, absolute_resolution=None, **kwds):
def __init__(self, scale, minval=None, maxval=None, absolute_resolution=None, **properties):
super().__init__()
scale = float(scale)
if absolute_resolution is None:
@@ -321,7 +335,7 @@ class ScaledInteger(DataType):
min=DEFAULT_MIN_INT * scale if minval is None else float(minval),
max=DEFAULT_MAX_INT * scale if maxval is None else float(maxval),
absolute_resolution=absolute_resolution,
**kwds)
**properties)
def checkProperties(self):
self.default = 0 if self.min <= 0 <= self.max else self.min
@@ -401,14 +415,20 @@ class ScaledInteger(DataType):
class EnumType(DataType):
"""enumeration
def __init__(self, enum_or_name='', **kwds):
:param enum_or_name: the name of the Enum or an Enum to inherit from
:param members: members=<members dict>
other keywords: (additional) members
"""
def __init__(self, enum_or_name='', **members):
super().__init__()
if 'members' in kwds:
kwds = dict(kwds)
kwds.update(kwds['members'])
kwds.pop('members')
self._enum = Enum(enum_or_name, **kwds)
if 'members' in members:
members = dict(members)
members.update(members['members'])
members.pop('members')
self._enum = Enum(enum_or_name, **members)
self.default = self._enum[self._enum.members[0]]
def copy(self):
@@ -448,6 +468,10 @@ class EnumType(DataType):
class BLOBType(DataType):
"""binary large object
internally treated as bytes
"""
properties = {
'minbytes': Property('minimum number of bytes', IntRange(0), extname='minbytes',
default=0),
@@ -511,6 +535,9 @@ class BLOBType(DataType):
class StringType(DataType):
"""string
"""
properties = {
'minchars': Property('minimum number of character points', IntRange(0, UNLIMITED),
extname='minchars', default=0),
@@ -520,11 +547,11 @@ class StringType(DataType):
Stub('BoolType'), extname='isUTF8', default=False),
}
def __init__(self, minchars=0, maxchars=None, **kwds):
def __init__(self, minchars=0, maxchars=None, **properties):
super().__init__()
if maxchars is None:
maxchars = minchars or UNLIMITED
self.set_properties(minchars=minchars, maxchars=maxchars, **kwds)
self.set_properties(minchars=minchars, maxchars=maxchars, **properties)
def checkProperties(self):
self.default = ' ' * self.minchars
@@ -602,6 +629,9 @@ class TextType(StringType):
class BoolType(DataType):
"""boolean
"""
default = False
def export_datatype(self):
@@ -646,6 +676,9 @@ Stub.fix_datatypes()
class ArrayOf(DataType):
"""data structure with fields of homogeneous type
"""
properties = {
'minlen': Property('minimum number of elements', IntRange(0), extname='minlen',
default=0),
@@ -743,6 +776,9 @@ class ArrayOf(DataType):
class TupleOf(DataType):
"""data structure with fields of inhomogeneous type
"""
def __init__(self, *members):
super().__init__()
@@ -813,7 +849,9 @@ class ImmutableDict(dict):
class StructOf(DataType):
"""data structure with named fields
"""
def __init__(self, optional=None, **members):
super().__init__()
self.members = members
@@ -890,6 +928,10 @@ class StructOf(DataType):
class CommandType(DataType):
"""command
a pseudo datatype for commands with arguments and return values
"""
IS_COMMAND = True
def __init__(self, argument=None, result=None):
@@ -948,8 +990,8 @@ class CommandType(DataType):
raise BadValueError('incompatible datatypes')
# internally used datatypes (i.e. only for programming the SEC-node)
class DataTypeType(DataType):
def __call__(self, value):
"""check if given value (a python obj) is a valid datatype
@@ -1111,7 +1153,10 @@ def get_datatype(json, pname=''):
"""returns a DataType object from description
inverse of <DataType>.export_datatype()
the pname argument, if given, is used to name EnumTypes from the parameter name
:param json: the datainfo object as returned from json.loads
:param pname: if given, used to name EnumTypes from the parameter name
:return: the datatype (instance of DataType)
"""
if json is None:
return json