Giter VIP home page Giter VIP logo

tango-simlib's Introduction

tango-simlib: Easily generate TANGO device simulators

Main website: http://tango-simlib.readthedocs.io

Introduction

tango-simlib is a library that aids the data-driven development of TANGO device simulators. It aims to make it easy to develop basic simulators while making it possible to implement more complex simulators. In addition to the simulated device interface, a separate TANGO simulation-control interface is generated, allowing the simulator to be manipulated via a back-channel to simulate e.g. failure conditions on the simulated device interface.

Using only the basic TANGO interface description captured via a POGO generated XMI file, a basic simulator with randomly varying attributes and no-op command handlers can be generated with no further coding. Attribute simulation parameters and simple command behaviour can be specified using a Simulator Description Datafile (SimDD). The format of this file is currently a working proposal and subject to change. A more formal format specification is being worked on.

Note that tango-simlib does not generate simulator code. Rather, the simulator's behaviour is driven by the description data at run-time using Python's dynamic programming features. If the description files (XMI or SimDD) are modified, the simulator device server only needs to be restarted for the changes to take effect.

Basic Usage

Installation

Please Note

  • tango-simlib is compatible with Python2.7 and Python>=3.5.
  • Installation requires the TANGOBINARY prerequisites to be installed.
$ sudo apt-get install -y --no-install-recommends $(grep -vE "^\s*#" apt-build-requirements.txt | tr "\n" " ")

If you cannot install the PyTango package you will not be able to install tango-simlib. For more, documentation.

Installation from source, working directory where source is checked out

$ pythonX -m pip install . # Where 'x' is the version of Python

This package is available on PYPI, allowing

$ pip install tango-simlib

Tango-YAML

After installing tango_simlib, the tango-yaml script will be available to use

$ tango-yaml -h

usage: tango_yaml [-h] {xmi,fandango,tango_device,validate} ...

This program translates various file formats that describe Tango devices to
YAML. Or validates the conformance of a device against a specification.

positional arguments:
{xmi,fandango,tango_device,validate}
                        sub command help
    xmi                 Build YAML from a XMI file
    fandango            Build YAML from a fandango file
    tango_device        Build YAML from a running Tango device
    validate            Check conformance of a Tango device against a
                        specification in YAML format

optional arguments:
-h, --help            show this help message and exit

Documentation

Check out the documentation for more information. Download Manual: https://media.readthedocs.org/pdf/tango-simlib/latest/tango-simlib.pdf

License

This project is licensed under the BSD 3-Clause License - see license for details.

Contribute

Contributions are always welcome! Please ensure that you adhere to our coding standards CAM_Style_guide.

tango-simlib's People

Contributors

ajoubertza avatar amakhaba avatar athanaseus avatar brickza avatar kmadisa avatar lvdheever avatar mmphego avatar samueltwum1 avatar skajohanventer avatar sw00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

juandesant

tango-simlib's Issues

attribute of SPECTRUM and IMAGE data format in SimDD file

There is no example of SPECTRUM and IMAGE data format attribute. as i add attributes of SPECTRUM and IMAGE data format in SimDD file like:

  [
    {
      "basicAttributeData": {
        "name": "double_spectrum",
        "label": "double_spectrum",
        "description": "double spectrum",
        "data_type": "Double",
        "data_format": "Spectrum",
        "data_shape": {
          "max_dim_x": 8,
          "max_dim_y": 0
        },
        "attributeErrorChecking": {
          "min_value": -100.0,
          "max_value": 100.0,
          "min_alarm": -95.0,
          "max_alarm": 95.0,
          "min_warning": -80.0,
          "max_warning": 80
        },
        "dataSimulationParameters": {
          "quantity_simulation_type": "GaussianSlewLimited",
          "min_bound": -255,
          "max_bound": 255,
          "mean": 10,
          "max_slew_rate": 1,
          "update_period": 1000,
          "std_dev": 10
        },
        "attributeControlSystem": {
          "display_level": "OPERATOR",
          "period": 1000
        }
      }
    },
    {
      "basicAttributeData": {
        "name": "double_image",
        "label": "double_image",
        "description": "double image",
        "data_type": "Double",
        "data_format": "Image",
        "data_shape": {
          "max_dim_x": 4,
          "max_dim_y": 4
        },
        "attributeErrorChecking": {
          "min_value": -100.0,
          "max_value": 100.0,
          "min_alarm": -95.0,
          "max_alarm": 95.0,
          "min_warning": -80.0,
          "max_warning": 80
        },
        "dataSimulationParameters": {
          "quantity_simulation_type": "ConstantQuantity",
          "initial_value": 10.0
        },
        "attributeControlSystem": {
          "display_level": "OPERATOR",
          "period": 1000
        }
      }
    }
  ]

But the generated simulate device's attribute (double_image and double_spectrum) is SCALAR data format.

can tango-simlib support attributes of SPECTRUM and IMAGE data format in SimDD file? or maybe i need to derive a class from class Quantity to process SPECTRUM and IMAGE data format's quantities?

Unicode Encode Error from POGO xmi

Traceback (most recent call last):
 File "/usr/local/bin/SrvPDU-simlib", line 16, in <module>
   main()
 File "/usr/local/bin/SrvPDU-simlib", line 12, in main
   TangoDeviceServers = get_tango_device_server(model, sim_data_files)
 File "/usr/local/lib/python2.7/dist-packages/tango_simlib/tango_sim_generator.py", line 236, in get_tango_device_server
   quantity.meta)
 File "/usr/local/lib/python2.7/dist-packages/tango_simlib/tango_sim_generator.py", line 164, in add_static_attribute
   access=getattr(AttrWriteType, attr_meta['writable']))
 File "/usr/local/lib/python2.7/dist-packages/tango/server.py", line 806, in __init__
   self.build_from_dict(kwargs)
 File "/usr/local/lib/python2.7/dist-packages/tango/attr_data.py", line 132, in build_from_dict
   self.att_prop = self.__create_user_default_attr_prop(attr_dict)
 File "/usr/local/lib/python2.7/dist-packages/tango/attr_data.py", line 172, in __create_user_default_attr_prop
   method(str(v))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 79: ordinal not in range(128)```

Support "Int" data_type in SimDD.schema?

In https://github.com/ska-sa/tango-simlib/blob/master/tango_simlib/utilities/SimDD.schema#L31 , the data_type only support "Boolean", "String", "Double", "VarStringArray", "VarDoubleArray” (For python maybe “Float” is more suitable than "Double"), why not support "Int” type (which can map to tango’s DevShort, DevUShort, DevLong, DevULong, DevLong64, DevULong64 type. etc.) as data types.

Secondly, if we can support "Int" data type, at same time we should add "VarBooleanArray" and "VarIntArray" in data_type enum.

Commands overriding in sim device and control device seem to be mutually exclusive, respectively

Problem Description

I had a look at the weather simulator we have in tango-simlib. It seems there is a bug related to overriding the commands in both the sim device and the control device, respectively.
What I noted is that it only overrides the commands for only one of the devices but not both.

Could be related to

# TODO (KM 17-02-2018) Follow up on this issue:

Noted in this example simulator https://github.com/ska-sa/tango-simlib/blob/master/tango_simlib/examples/weather3.py.

read and write Spectrum/Image attribute problem

Now tango-simlib can support SPECTRUM and IMAGE attribute addition correctly. but read and write attribute value have some problems.

  1. In Spectrum_SimDD.json file, if we change doubleSpectrum attribute's "quantity_simulation_type" from "ConstantQuantity" to "GaussianSlewLimited" (with mean, std_dev, max_slew_rate, min_bound, max_bound set), then we can not read doubleSpectrum attribute of simulator device, the exception description is: Wrong Python type for attribute doubleSpectrum of type DevDouble. Expected a sequence;
  2. If we set value for the attribute of SPECTRUM and IMAGE data format through sim control device's attribute (by attribute_name and last_val), then the simulator device's attribute of SPECTRUM and IMAGE data format can not read, the exception description is: Wrong Python type for attribute XXX of type DevDouble. Expected a sequence. This may be caused by that last_val is SCALAR format forever, we can only write a scalar value to it. May solution is that if the data format of attribute set by attribute_name is SPECTRUM or IMAGE, we should disable write last_val attribute of sim control device?

tango-simlib: Several device(s)

I would like to create several simulated devices with one sim control device per simulated devices in one device server process.To do so, I have created in database two devices of my simulated Modbus classand I have also created two devices of the ModbusSimControl class.Unfortunately, the device server does not start. Here are the outputs

Exiting: Server exited with tango.DevFailed:
DevFailed[
DevError[
    desc = RuntimeError: Could not find model with device name or key et/modbus/02. Set the "model_key" device property to the correct value.
  origin =   File "/home/taurel/.local/lib/python2.7/site-packages/tango/device_class.py", line 553, in __DeviceClass__device_factory`
    device = self._new_device(deviceImplClass, klass, dev_name)
  File "/home/taurel/.local/lib/python2.7/site-packages/tango/device_class.py", line 533, in __DeviceClass__new_device
    return klass(dev_class, dev_name)
  File "/home/taurel/.local/lib/python2.7/site-packages/tango_simlib/sim_test_interface.py", line 37, in __init__
    super(TangoTestDeviceServerBase, self).__init__(dev_class, name)
  File "/home/taurel/.local/lib/python2.7/site-packages/tango/server.py", line 551, in __init__
    self.init_device()
  File "/home/taurel/.local/lib/python2.7/site-packages/tango/server.py", line 349, in init_device
    return get_worker().execute(init_device_orig, self)
  File "/home/taurel/.local/lib/python2.7/site-packages/tango/server.py", line 1498, in execute
    return func(*args, **kwargs)
  File "/home/taurel/.local/lib/python2.7/site-packages/tango_simlib/tango_sim_generator.py", line 311, in init_device
    super(SimControl, self).init_device()
  File "/home/taurel/.local/lib/python2.7/site-packages/tango/server.py", line 349, in init_device
    return get_worker().execute(init_device_orig, self)
  File "/home/taurel/.local/lib/python2.7/site-packages/tango/server.py", line 1498, in execute
    return func(*args, **kwargs)
  File "/home/taurel/.local/lib/python2.7/site-packages/tango_simlib/sim_test_interface.py", line 58, in init_device
    'correct value.'.format(self.model_key))

  reason = PyDs_PythonError
severity = ERR]
]

Exited

TANGO-FORUM

Enable the device server push events manually

Problem Description

At the moment the generated device server requires that polling be set for attribute(s) so that the client(s) can be able to subscribe to the attribute events. Depending on how many attributes the device might have, this might also degrade the performance of the server.
One proposed solution to this would be to have the device server push events to clients, which is more efficient than polling.

Two possible solutions (there can be more) are proposed:

Solution 1. Specify the flag(s) as part of the attribute configuration

In this scenario we add a property/properties in each attribute configuration to flag whether we want the device server to push either change/archive event for each individual attribute. The nice thing about this approach is that we can set it up for a specific attribute.
The proper place for this would be to use the SimDD.json configuration file to add this extra properties. This means we might also have to update the parser, but it shouldn't be difficult, and then when initialising the device, we would get these properties from the model and configure it accordingly.

Code snippet: tango_sim_generator.py

def initialize_dynamic_attributes(self):
    model_sim_quants = self.model.sim_quantities
    attribute_list = set([attr for attr in model_sim_quants.keys()])
    for attribute_name in attribute_list:
        meta_data = model_sim_quants[attribute_name].meta
        # Dynamically add all attributes except those with DevEnum data type,
        # and SPECTRUM data format since they are added statically to the device
        # class prior to start-up. Also exclude attributes with a data format
        # 'IMAGE' as we currently do not handle them.
        if not self._is_attribute_addable_dynamically(meta_data):
            if model_sim_quantities[attribute_name].meta['push_change_event']:
                self.set_change_event(attribute_name, True, True)

            if model_sim_quantities[attribute_name].meta['push_archive_event']:
                self.set_change_event(attribute_name, True, True)

             continue
        ....

        self._add_dynamic_attribute(attr, rw_type)
        MODULE_LOGGER.debug("Added dynamic {} attribute".format(attribute_name))

        if model_sim_quantities[attribute_name].meta['push_change_event']:
            self.set_change_event(attribute_name, True, True)

        if model_sim_quantities[attribute_name].meta['push_archive_event']:
            self.set_change_event(attribute_name, True, True)

Solution 2. Pass the flags as command line arguments

In this scenario, we pass a flag(s) in the terminal to signal whether to manually push events or not. With this approach, there won't be an easier way to specify as to for which attribute we want the event to be pushed for. We will have to just push for all attributes.

Code snippet: bash

$ tango-simlib-generator --sim-data-file <xmi/fgo/json>\
                         --dserver-name <server-name>\
                         --directory <output filepath>\
                         --push-change-events <True/False>\
                         --push-archive-events <True/False>

Code snippet: tango_sim_generator.py

....

def generate_device_server(
    server_name,
    sim_data_files,
    directory="",
    push_change_events=False,
    push_archive_events=False
):
....
    lines = [
        ....
        "    TangoDeviceServers = get_tango_device_server("
        "        models,"
        "        sim_data_files,"
        "        push_change_events={},".format(push_change_events)
        "        push_archive_events={}".format(push_archive_events)
        "     )"
....

def get_tango_device_server(
    models,
    sim_data_files,
    push_change_events=False,
    push_archive_events=False
):
....

def initialize_dynamic_attributes(self):
    model_sim_quants = self.model.sim_quantities
    attribute_list = set([attr for attr in model_sim_quants.keys()])
    for attribute_name in attribute_list:
        meta_data = model_sim_quants[attribute_name].meta
        # Dynamically add all attributes except those with DevEnum data type,
        # and SPECTRUM data format since they are added statically to the device
        # class prior to start-up. Also exclude attributes with a data format
        # 'IMAGE' as we currently do not handle them.
        if not self._is_attribute_addable_dynamically(meta_data):
            if push_archive_events:
                self.set_archive_event(attribute_name, True, True)

            if push_change_events:
                self.set_change_event(attribute_name, True, True)

             continue
        ....

        self._add_dynamic_attribute(attr, rw_type)
        MODULE_LOGGER.debug("Added dynamic {} attribute".format(attribute_name))

        if push_archive_events:
            self.set_archive_event(attribute_name, True, True)

        if push_change_event:
            self.set_change_event(attribute_name, True, True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.