tango_simlib modules

tango_simlib.main module

tango_simlib.main.simulator_main(sim_class, sim_control_class=<Mock spec='str' id='139924346603600'>)[source]

Main function for a simulator with class sim_class.

sim_class is a tango.server.Device subclass.

tango_simlib.model module

class tango_simlib.model.Model(name, start_time=None, min_update_period=0.99, time_func=<built-in function time>, logger=None)[source]

Bases: future.types.newobject.newobject

Tango Device main model with quantities and actions.

name : str
Model name identifier
start_time : float
Time at instantiation of the model
min_update_period : float
Minimum update period of the quantities in the model
time_func : time function
Function that return current time i.e. time.time
reset_model_state()[source]

Reset the model’s quantities’ adjustable attributes to their default values.

set_sim_action(name, handler)[source]

Add an action handler function.

name : str
Name of the action
handler : callable(model_instance, action_args)
Callable that handles action (name). Is called with the model instance as the first parameter.
set_sim_property(device_prop)[source]
set_test_sim_action(name, handler)[source]

Add an action handler function.

name : str
Name of the action
handler : callable(model_instance, action_args)
Callable that handles action (name). Is called with the model instance as the first parameter.
setup_sim_quantities()[source]

Set up self.sim_quantities with simulated quantities.

Subclasses should implement this method. Should place simulated quantities in self.sim_quantities dict. Keyed by name of quantity, value must be instances satisfying the quantities.Quantity interface.

  • Must use self.start_time to set initial time values.
  • Must call super method after setting up sim_quantities
update()[source]
class tango_simlib.model.PopulateModelActions(cmd_info, override_info, tango_device_name, model_instance=None)[source]

Bases: future.types.newobject.newobject

Used to populate/update model actions.

Populates the model actions using the data from the TANGO device information captured in the json file / POGO generated xmi / FANDANGO generated fgo file.

cmd_info : dict
A dictionary of all the device commands together with their metadata specified in the xmi, json or fgo file(s).
override_info : dict
A dictionary of device override info in specified the xmi, json or fgo file(s).
sim_model : Model instance
An instance of the Model class which is used for simulation of simple attributes and/or commands.
add_actions()[source]
generate_action_handler(action_name, action_output_type, actions=None)[source]

Generates and returns an action handler to manage tango commands.

action_name : str
Name of action handler to generate
action_output_type : PyTango._PyTango.CmdArgType
Tango command argument type
actions : list
List of actions that the handler will provide
action_handler : function
action handler, taking command input argument in case of tango commands with input arguments.
class tango_simlib.model.PopulateModelProperties(properties_info, tango_device_name, sim_model=None)[source]

Bases: future.types.newobject.newobject

Used to populate/update model properties.

Populates the model properties using the data from the TANGO device information captured in the json file / POGO generated xmi / FANDANGO generated fgo file.

properties_info : dict
A dictionary of device property configuration specified in the xmi, json or fgo file(s).
sim_model : Model instance
An instance of the Model class which is used for simulation of simple attributes.
setup_sim_properties()[source]

Set up self.sim_properties from Model with simulated quantities

Places simulated properties in sim_quantities dict. Keyed by name of property, value must be a string, number or array and it is optional.

class tango_simlib.model.PopulateModelQuantities(parser_instance, tango_device_name, sim_model=None)[source]

Bases: future.types.newobject.newobject

Used to populate/update model quantities.

Populates the model quantities using the data from the TANGO device information captured in the json file / POGO generated xmi / FANDANGO generated fgo file.

parser_instance : Parser instance
The Parser object which reads an xmi/xml/json file and parses it into device attributes, commands, and properties.
sim_model : Model instance
An instance of the Model class which is used for simulation of simple attributes.
setup_sim_quantities()[source]

Set up self.sim_quantities from Model with simulated quantities.

Places simulated quantities in sim_quantities dict. Keyed by name of quantity, value must be instances satisfying the quantities.Quantity interface

  • Must use self.start_time to set initial time values.
  • Must call super method after setting up sim_quantities
sim_attribute_quantities(min_bound, max_bound, max_slew_rate, mean, std_dev)[source]

Simulate attribute quantities with a Gaussian value distribution.

min_value : float
minimum attribute value to be simulated
max_value : float
maximum attribute value to be simulated
max_slew_rate : float
maximum changing rate of the simulated quantities between min and max values
mean : float
average value of the simulated quantity
std_dev : float
standard deviation value of the simulated quantity
sim_attribute_quantities : dict
Dict of Gaussian simulated quantities
exception tango_simlib.model.SimModelException(message)[source]

Bases: exceptions.Exception

tango_simlib.quantities module

class tango_simlib.quantities.ConstantQuantity(start_value=None, start_time=None, meta=None)[source]

Bases: tango_simlib.quantities.Quantity

A quantity that does not change unless explicitly set.

default_val(t)[source]

Set a default value of True to the quantity.

t : float
Time to update quantity
next_val(t)[source]

Returns the last value as the next simulated value.

t : float
Time to update quantity
class tango_simlib.quantities.GaussianSlewLimited(mean, std_dev, max_slew_rate=inf, meta=None, min_bound=-inf, max_bound=inf, start_value=None, start_time=None)[source]

Bases: tango_simlib.quantities.Quantity

A Gaussian random variable a slew-rate limit and clipping.

mean : float
Gaussian mean value
std_dev : float
Gaussian standard deviation
max_slew_rate : float
Maximum quantity slew rate in amount per second. Random values will be clipped to satisfy this condition.
min_bound : float
Minimum quantity value, random values will be clipped if needed.
max_bound : float
Maximum quantity value, random values will be clipped if needed.
adjustable_attributes = frozenset(['last_update_time', 'max_slew_rate', 'last_val', 'min_bound', 'max_bound', 'std_dev', 'mean'])
next_val(t)[source]

Returns the next value of the simulation.

t : float
Time to update quantity
class tango_simlib.quantities.Quantity(start_value=None, start_time=None, meta=None)[source]

Bases: future.types.newobject.newobject

Attributes that should be adjustable via a simulation control interface.

start_time : float
The initial time when a quantity is updated.
start_value : float
The initial value of a quantity.
meta : dict
This data structure must contain all the attribute description data of all quantities that represent tango device simulator attributes. List of all available tango attribute description data: abs_change, archive_abs_change, archive_period, archive_rel_change, label, max_alarm, max_value, max_warning, min_alarm, min_value, delta_t, delta_val, description, display_unit, format, min_warning, period, rel_change e.g. meta=dict(label=”Outside Temperature”, dtype=float) TODO (AR) 2016-07-27 : Ideally these properties should not be TANGO specific as is at the moment.

Subclasses should add all the attributes to this set that users should be able to adjust via a user interface at simulation runtime, also initialise the last_val attribute with the initial quantity value.

adjustable_attributes = frozenset(['last_update_time', 'last_val'])
default_val(t)[source]

Set a default value of 0 to the quantity.

t : float
Time to update quantity
next_val(t)[source]

Return the next simulated value for simulation time at t seconds.

Must update attributes last_val with the new value and last_update_time with the simulation time

t : float
Time to update quantity
set_val(val, t)[source]

Set a value to the quantity.

t : float
Time to update quantity
val : int/float/string
Value to update quantity
tango_simlib.quantities.register_quantity_class(cls)[source]

tango_simlib.sim_test_interface module

tango_simlib.tango_launcher module

Utility to help launch a TANGO device in a KATCP eco-system.

Helps by auto-registering a TANGO device if needed.

tango_simlib.tango_launcher.main()[source]
tango_simlib.tango_launcher.put_device_property(dev_name, property_name, property_value, db)[source]
tango_simlib.tango_launcher.register_device(name, device_class, server_name, instance, db)[source]
tango_simlib.tango_launcher.start_device(opts)[source]

tango_simlib.tango_sim_generator module

Simlib library generic simulator generator utility to be used to generate an actual TANGO device that exhibits the behaviour defined in the data description file.

tango_simlib.tango_sim_generator.add_static_attribute(tango_device_class, attr_name, attr_meta)[source]

Add any TANGO attribute of to the device server before start-up.

cls: class
class object that the device server will inherit from
attr_name: str
Tango attribute name
attr_meta: dict
Meta data that enables the creation of a well configured attribute

This is needed for DevEnum and spectrum type attributes

tango_simlib.tango_sim_generator.configure_device_model(sim_data_file=None, test_device_name=None, logger=None)[source]
tango_simlib.tango_sim_generator.configure_device_models(sim_data_file=None, test_device_name=None, logger=None)[source]

In essence this function should get the data descriptor file, parse it, take the attribute and command information, populate the model(s) quantities and actions to be simulated and return that model.

sim_datafile : list
A list of direct paths to either xmi/xml/json/fgo files.
test_device_name : str
A TANGO device name. This is used for running tests as we want the model instance and the device name to have the same name.
models : dict
A dictionary of model.Model instances
tango_simlib.tango_sim_generator.generate_device_server(server_name, sim_data_files, directory='')[source]

Create a tango device server python file.

server_name: str
Tango device server name
sim_data_files: list
A list of direct paths to either xmi/xml/json data files.
tango_simlib.tango_sim_generator.get_argparser()[source]
tango_simlib.tango_sim_generator.get_device_class(sim_data_files)[source]

Get device class name from specified xmi/simdd description file.

sim_data_files: list
A list of direct paths to either xmi/xml/json/fgo data files.
klass_name: str
Tango device class name
tango_simlib.tango_sim_generator.get_parser_instance(sim_datafile)[source]

This method returns an appropriate parser instance to generate a Tango device.

sim_datafile : str
A direct path to the xmi/xml/json/fgo file.
parser_instance: Parser instance
The Parser object which reads an xmi/xml/json/fgo file and parses it into device attributes, commands, and properties.
tango_simlib.tango_sim_generator.get_tango_device_server(models, sim_data_files)[source]

Declares a tango device class that inherits the Device class and then adds tango attributes (DevEnum and Spectrum type).

models: dict
A dictionary of model.Model instances. e.g. {‘model-name’: model.Model}
sim_data_files: list
A list of direct paths to either xmi/xml/json data files.
TangoDeviceServer : PyTango.Device
Tango device that has the commands dictionary populated.
tango_simlib.tango_sim_generator.main()[source]
tango_simlib.tango_sim_generator.write_device_properties_to_db(device_name, model, db_instance=None)[source]

Writes device properties, including optional default value, to tango DB.

device_name : str
A TANGO device name
model : model.Model instance
Device model instance
db_instance : tango._tango.Database instance
Tango database instance