예제 #1
0
    def create_attribute_models(self):
        """MethodModel that should provide Attribute instances for Block

        Yields:
            tuple: (string name, Attribute, callable put_function).
        """
        for y in super(StatefulController, self).create_attribute_models():
            yield y
        # Create read-only attribute for current state string
        meta = ChoiceMeta(
            "State of Block", self.stateSet.possible_states, label="State")
        self.state = meta.create_attribute_model(ss.DISABLING)
        yield "state", self.state, None
예제 #2
0
def make_meta(subtyp, description, tags, writeable=True, labels=None):
    if subtyp == "enum":
        if writeable:
            widget_type = "combo"
        else:
            widget_type = "textupdate"
        tags.append(widget(widget_type))
        meta = ChoiceMeta(description, labels, tags)
    elif subtyp == "bit":
        if writeable:
            widget_type = "checkbox"
        else:
            widget_type = "led"
        tags.append(widget(widget_type))
        meta = BooleanMeta(description, tags)
    else:
        if writeable:
            widget_type = "textinput"
        else:
            widget_type = "textupdate"
        tags.append(widget(widget_type))
        if subtyp == "uint":
            meta = NumberMeta("uint32", description, tags)
        elif subtyp == "int":
            meta = NumberMeta("int32", description, tags)
        elif subtyp == "scalar":
            meta = NumberMeta("float64", description, tags)
        elif subtyp == "lut":
            meta = StringMeta(description, tags)
        elif subtyp in ("pos", "relative_pos"):
            meta = NumberMeta("float64", description, tags)
        else:
            raise ValueError("Unknown subtype %r" % subtyp)
    return meta
예제 #3
0
 def test_from_dict(self):
     bm = ChoiceMeta.from_dict(self.serialized)
     assert type(bm) == ChoiceMeta
     assert bm.description == "desc"
     assert bm.choices == ("a", "b")
     assert bm.tags == ()
     assert not bm.writeable
     assert bm.label == "name"
예제 #4
0
 def create_attribute_models(self):
     for data in super(ManagerController, self).create_attribute_models():
         yield data
     assert os.path.isdir(self.params.configDir), \
         "%s is not a directory" % self.params.configDir
     if not os.path.isdir(os.path.join(self.params.configDir, ".git")):
         # Try and make it a git repo, don't care if it fails
         self._run_git_cmd("init")
         self._run_git_cmd("commit", "--allow-empty", "-m", "Created repo")
     # Create writeable attribute table for the layout info we need
     elements = OrderedDict()
     elements["name"] = StringArrayMeta("Name of layout part")
     elements["mri"] = StringArrayMeta("Malcolm full name of child block")
     elements["x"] = NumberArrayMeta(
         "float64", "X Coordinate of child block")
     elements["y"] = NumberArrayMeta(
         "float64", "Y Coordinate of child block")
     elements["visible"] = BooleanArrayMeta("Whether child block is visible")
     layout_table_meta = TableMeta(
         "Layout of child blocks", elements=elements,
         tags=[widget("flowgraph")])
     layout_table_meta.set_writeable_in(ss.READY)
     self.layout = layout_table_meta.create_attribute_model()
     yield "layout", self.layout, self.set_layout
     # Create writeable attribute for loading an existing layout
     design_meta = ChoiceMeta(
         "Design name to load", tags=[config(), widget("combo")])
     design_meta.set_writeable_in(ss.READY)
     self.design = design_meta.create_attribute_model()
     yield "design", self.design, self.set_design
     # Create writeable attribute table for the exported fields
     elements = OrderedDict()
     elements["name"] = ChoiceArrayMeta("Name of exported block.field")
     elements["exportName"] = StringArrayMeta(
         "Name of the field within current block")
     exports_table_meta = TableMeta(
         "Exported fields of child blocks", tags=[widget("table")],
         elements=elements)
     exports_table_meta.set_writeable_in(ss.READY)
     self.exports = exports_table_meta.create_attribute_model()
     yield "exports", self.exports, self.set_exports
     # Create read-only indicator for when things are modified
     modified_meta = BooleanMeta(
         "Whether the design is modified", tags=[widget("led")])
     self.modified = modified_meta.create_attribute_model()
     yield "modified", self.modified, None
예제 #5
0
 def _make_time_parts(self, field_name, field_data, writeable):
     description = field_data.description
     if writeable:
         widget_tag = widget("textupdate")
         group_tag = self._make_group("parameters")
     else:
         widget_tag = widget("textinput")
         group_tag = self._make_group("readbacks")
     meta = NumberMeta("float64", description, [group_tag, widget_tag])
     self._make_field_part(field_name, meta, writeable)
     meta = ChoiceMeta(description + " time units", ["s", "ms", "us"],
                       tags=[group_tag, widget("combo")])
     self._make_field_part(field_name + ".UNITS", meta, writeable=True)
예제 #6
0
 def _make_mux(self, field_name, field_data, typ):
     group_tag = self._make_group("inputs")
     if typ == "bit":
         inport_type = "bool"
     else:
         inport_type = "int32"
     meta = ChoiceMeta(
         field_data.description,
         field_data.labels,
         tags=[group_tag,
               inport(inport_type, "ZERO"),
               widget("combo")])
     self._make_field_part(field_name, meta, writeable=True)
     meta = make_meta(typ,
                      "%s current value" % field_name,
                      tags=[group_tag],
                      writeable=False)
     self._make_field_part(field_name + ".CURRENT", meta, writeable=False)
예제 #7
0
class TestValidate(unittest.TestCase):
    def setUp(self):
        self.choice_meta = ChoiceMeta("test description", ["a", "b"])

    def test_given_valid_value_then_return(self):
        response = self.choice_meta.validate("a")
        assert "a" == response

    def test_int_validate(self):
        response = self.choice_meta.validate(1)
        assert "b" == response

    def test_None_valid(self):
        response = self.choice_meta.validate(None)
        assert "a" == response

    def test_given_invalid_value_then_raises(self):
        with self.assertRaises(ValueError):
            self.choice_meta.validate('badname')

    def test_set_choices(self):
        self.choice_meta.set_choices(["4"])

        assert ("4", ) == self.choice_meta.choices
예제 #8
0
from malcolm.core import Part, method_takes, REQUIRED
from malcolm.tags import widget_types, widget, config, group
from malcolm.modules.builtin.vmetas import StringMeta, BooleanMeta, ChoiceMeta


@method_takes("name", StringMeta("Name of the created attribute"), REQUIRED,
              "description",
              StringMeta("Desc of created attribute"), REQUIRED, "widget",
              ChoiceMeta("Widget type", [""] + widget_types), "", "writeable",
              BooleanMeta("Is the attribute writeable?"), False, "group",
              StringMeta("If given, which GUI group should we attach to"), "",
              "config",
              BooleanMeta("If writeable, should this field be loaded/saved?"),
              True)
class AttributePart(Part):
    def __init__(self, params):
        # The created attribute
        self.attr = None
        # Store params
        self.params = params
        super(AttributePart, self).__init__(params.name)

    def create_attribute_models(self):
        # Find the tags
        tags = self.create_tags()
        # Make a meta object for our attribute
        meta = self.create_meta(self.params.description, tags)
        # The attribute we will be publishing
        initial_value = self.get_initial_value()
        self.attr = meta.create_attribute_model(initial_value)
        if self.is_writeable():
예제 #9
0
 def _make_out_capture(self, field_name, field_data):
     group_tag = self._make_group("outputs")
     meta = ChoiceMeta("Capture %s in PCAP?" % field_name,
                       field_data.labels,
                       tags=[group_tag, widget("combo")])
     self._make_field_part(field_name + ".CAPTURE", meta, writeable=True)
예제 #10
0
 def test_init(self):
     self.choice_meta = ChoiceMeta("test description", ["a", "b"])
     assert ("test description") == self.choice_meta.description
     assert (self.choice_meta.typeid) == "malcolm:core/ChoiceMeta:1.0"
     assert (self.choice_meta.label) == ""
     assert (self.choice_meta.choices) == ("a", "b")
예제 #11
0
 def test_to_dict(self):
     bm = ChoiceMeta("desc", ["a", "b"], label="name")
     assert bm.to_dict() == self.serialized
예제 #12
0
 def setUp(self):
     self.choice_meta = ChoiceMeta("test description", ["a", "b"])
예제 #13
0
 def create_meta(self, description, tags):
     return ChoiceMeta(
         choices=self.params.choices, description=description, tags=tags)
예제 #14
0
 def create_meta(self, description, tags):
     return ChoiceMeta(
         choices=["expanded", "collapsed"],
         description=description, tags=tags)
예제 #15
0
statistics = OrderedDict()

statistics["min"] = "MIN_VALUE"  # Minimum counts in any element
statistics["min_x"] = "MIN_X"  # X position of minimum counts
statistics["min_y"] = "MIN_Y"  # Y position of minimum counts
statistics["max"] = "MAX_VALUE"  # Maximum counts in any element
statistics["max_x"] = "MAX_X"  # X position of maximum counts
statistics["max_y"] = "MAX_Y"  # Y position of maximum counts
statistics["mean"] = "MEAN_VALUE"  # Mean counts of all elements
statistics["sigma"] = "SIGMA_VALUE"  # Sigma of all elements
statistics["sum"] = "TOTAL"  # Sum of all elements
statistics["net"] = "NET"  # Sum of all elements not in background region


@method_also_takes("statistic",
                   ChoiceMeta("Which statistic to capture", statistics), "sum")
class StatsPluginPart(StatefulChildPart):
    """Part for controlling a `stats_plugin_block` in a Device"""
    # The NDAttributes file we write to say what to capture
    attributes_filename = None

    @RunnableController.ReportStatus
    def report_info(self, _):
        statistic, _, attr = self._get_statistic_source_attr()
        return [CalculatedNDAttributeDatasetInfo(name=statistic, attr=attr)]

    def _get_statistic_source_attr(self):
        statistic = self.params.statistic
        source = statistics[statistic]
        attr = "STATS_%s" % source
        return statistic, source, attr
예제 #16
0
from malcolm.modules.builtin.controllers import StatefulController
from malcolm.core import method_takes, REQUIRED
from malcolm.modules.ca.parts import CAStringPart
from malcolm.tags import port_types, outport, widget
from malcolm.modules.builtin.vmetas import StringMeta, ChoiceMeta


@method_takes("name", StringMeta("Name of the created attribute"), REQUIRED,
              "description", StringMeta("Desc of created attribute"),
              REQUIRED, "rbv",
              StringMeta("Full pv of demand and default for rbv"), REQUIRED,
              "outport", ChoiceMeta("Outport type", port_types), REQUIRED)
class AsynOutportPart(CAStringPart):
    def __init__(self, params):
        args = CAStringPart.MethodModel.prepare_call_args(
            name=params.name, description=params.description, rbv=params.rbv)
        super(AsynOutportPart, self).__init__(*args)

    def create_tags(self):
        tags = super(AsynOutportPart, self).create_tags()
        tags.append(widget("textupdate"))
        return tags

    @StatefulController.Reset
    def reset(self, context=None):
        super(AsynOutportPart, self).reset(context)
        # Add the outport tags
        tags = [t for t in self.attr.meta.tags if not t.startswith("outport:")]
        tags.append(outport(self.outport_type, self.attr.value))
        self.attr.meta.set_tags(tags)
예제 #17
0
from malcolm.core import method_takes, REQUIRED, Alarm, AlarmStatus, TimeStamp
from malcolm.modules.builtin.parts.attributepart import AttributePart
from malcolm.tags import widget_types, inport, port_types
from malcolm.modules.builtin.vmetas import StringMeta, ChoiceMeta, \
    BooleanMeta, NumberMeta
from .catoolshelper import CaToolsHelper


@method_takes(
    "name",
    StringMeta("Name of the created attribute"), REQUIRED, "description",
    StringMeta("Description of created attribute"), REQUIRED, "pv",
    StringMeta("Full pv of demand and default for rbv"), "", "rbv",
    StringMeta("Override for rbv"), "", "rbvSuff",
    StringMeta("Set rbv to pv + rbv_suff"), "", "widget",
    ChoiceMeta("Widget type", [""] + widget_types), "", "inport",
    ChoiceMeta("Inport type", [""] + port_types), "", "group",
    StringMeta("If given, which GUI group should we attach to"), "", "config",
    BooleanMeta("Should this field be loaded/saved?"), True, "minDelta",
    NumberMeta("float64", "Minimum time between attribute updates in seconds"),
    0.05, "timeout",
    NumberMeta("float64",
               "Max time to wait for puts to complete, <0 is forever"), 5.0)
class CAPart(AttributePart):
    """Abstract class for exposing PVs as `Attribute` instances"""
    def __init__(self, params):
        if not params.rbv and not params.pv:
            raise ValueError('Must pass pv or rbv')
        if not params.rbv:
            if params.rbvSuff:
                params.rbv = params.pv + params.rbvSuff
예제 #18
0
 def create_meta(self, description, tags):
     return ChoiceMeta(description=description, tags=tags)