pyebus.msgdef module
Message Defintions.
- class pyebus.msgdef.MsgDef(circuit, name, children, read=False, prio=None, write=False, update=False, setprio=None)[source]
Bases:
_MsgDef
,NodeMixin
Message Definition.
A message is defined by circuit and name and has a fields
- Parameters:
circuit (str) – Circuit Name
name (str) – Message Name
children (tuple) – Field definitions.
FieldDef
andVirtFieldDef
.
- Keyword Arguments:
>>> from pyebus import MsgDef, types >>> m = MsgDef('circuit', 'name', [ ... FieldDef(0, 'temp', types.IntType(-127, 128)), ... FieldDef(1, 'name', types.StrType(10)), ... VirtFieldDef('virt', types.StrType(), lambda msg: f'{msg.name}: {msg.temp}'), ... ], read=True) >>> m MsgDef('circuit', 'name', (FieldDef(0, 'temp', IntType(... VirtFieldDef('virt', StrType())), read=True) >>> m.ident 'circuit/name' >>> m.children (FieldDef(0, 'temp', IntType(-127, 128)), FieldDef(1, 'name', StrType(length=10)), VirtFieldDef('virt', StrType())) >>> m.fields (FieldDef(0, 'temp', IntType(-127, 128)), FieldDef(1, 'name', StrType(length=10))) >>> m.virtfields (VirtFieldDef('virt', StrType()),) >>> m.access 'r----'
MsgDef
,FieldDef
andVirtFieldDef
form a tree structure>>> from anytree import RenderTree >>> print(RenderTree(m)) MsgDef('circuit', 'name', (FieldDef(0, 'temp', IntType(-127, 128)),..., StrType())), read=True) ├── FieldDef(0, 'temp', IntType(-127, 128)) ├── FieldDef(1, 'name', StrType(length=10)) └── VirtFieldDef('virt', StrType())
Similar object can be easily created by:
>>> m.replace(children=m.fields[1:2]) MsgDef('circuit', 'name', (FieldDef(1, 'name', StrType(length=10)),), read=True)
Create new instance of _MsgDef(circuit, name, read, prio, write, update, setprio)
- property fields
Fields.
- property virtfields
Calulated Fields.
- property ident
Identifier.
- property access
Message Access.
- class pyebus.msgdef.AbstractFieldDef(idx, name, type_, unit=None, comment=None)[source]
Bases:
_FieldDef
,NodeMixin
Abstract Field Definition.
- Parameters:
- Keyword Arguments:
Create new instance of _FieldDef(idx, name, type_, unit, comment)
- property msgdef
Message Definition.
- property ident
Identifier.
- class pyebus.msgdef.FieldDef(idx, name, type_, unit=None, comment=None)[source]
Bases:
AbstractFieldDef
Field Definition.
- Parameters:
- Keywords Args:
unit (str): Unit of the field value comment (str): Comment.
Create new instance of _FieldDef(idx, name, type_, unit, comment)
- class pyebus.msgdef.VirtFieldDef(name, type_, func, unit=None, comment=None)[source]
Bases:
AbstractFieldDef
Virtual Field Definition.
- Parameters:
- Keywords Args:
unit (str): Unit of the field value comment (str): Comment.
Create new instance of _FieldDef(idx, name, type_, unit, comment)
- pyebus.msgdef.resolve_prio(msgdef, setprio='A')[source]
Resolve priority specification.
Integer values are just passed through.
>>> resolve_prio(MsgDef('circuit', 'name', [], read=True), 1) 1 >>> resolve_prio(MsgDef('circuit', 'name', [], read=True), 9) 9
The AUTO option, sets read-only messages to prio 1.
>>> resolve_prio(MsgDef('circuit', 'name', [], read=True), AUTO) 1
All other readable messages get prio 2
>>> resolve_prio(MsgDef('circuit', 'name', [], read=True, write=True), AUTO) 2 >>> resolve_prio(MsgDef('circuit', 'name', [], read=True, update=True), AUTO) 2
Non-readable messages have no prio.
>>> resolve_prio(MsgDef('circuit', 'name', [], write=True), AUTO)