diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f768f7909ca84a190cd6d52a1522bf55d0a7e55d --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +.pydevproject +.project +.cproject +.settings +obj +bin +core* +*~ +*.pyc +*.so +*.so* +.pylintrc +.metadata +.idea +.cvsignore +.nse_depinfo +software +oldsrc +CVS diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d65aad319a3fa176f12db2c42bba16074e90382f --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +NAME = simulatede2bbaswitch-srv +MAIN = Simulatede2BbaSwitch.py +DIRNAME = $(NAME:-srv=) +MODNAME = $(MAIN:.py=) +PY_FILES += $(wildcard src/*.py) + +default: bin ${PY_FILES} + @cp ${PY_FILES} bin/${DIRNAME} + @echo "#!/usr/bin/env python3\nimport sys\nsys.path.append(sys.path[0]+'/${DIRNAME}')\nfrom ${MODNAME} import main\nif __name__ == '__main__':\n main()\n" > bin/${NAME} + @chmod +x bin/${NAME} bin/${DIRNAME}/${MAIN} + +bin: + @test -d $@ || mkdir -p $@/${DIRNAME} + +clean: + @rm -fr bin/ src/*~ + +.PHONY: clean + diff --git a/README.md b/README.md index 1891c8c437e6b93f2dc00bba9eb7d2ab8793fff8..eaea19bcf1f1af8bc65668485baf6ecd24bc6c86 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,6 @@ # simulatedE2BbaSwitch +Tango device server implementing the simulated BBA simulated BBA switch +The real BBA switch will be a boolean r/w attribute espoter d by the ELttra 2.0 MPS (PLC interlock) Tango interface -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.elettra.eu/dt/ds/simulatede2bbaswitch.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.elettra.eu/dt/ds/simulatede2bbaswitch/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/TODO b/TODO new file mode 100644 index 0000000000000000000000000000000000000000..01ede7629b5b2c5d86745ecc6d48e9dd3d50d52b --- /dev/null +++ b/TODO @@ -0,0 +1,3 @@ +- add the possibilty of creating many dynamic attributes with a simple configuration Useful for handling the whole simulator with a single server, like in the real case +- usro un dictiory (map) per salvare i valor accanto al nome dell' attributo. +Useroò un poroerty per la lista dei nomi degli attributi diff --git a/src/Simulatede2BbaSwitch.py b/src/Simulatede2BbaSwitch.py new file mode 100644 index 0000000000000000000000000000000000000000..2102fb869fbabcec9b33a9e780a488b34c0be85e --- /dev/null +++ b/src/Simulatede2BbaSwitch.py @@ -0,0 +1,123 @@ +# -*- coding: utf-8 -*- +# +# This file is part of the Simulatede2BbaSwitch project +# +# Elettra - Sincrotrone Trieste S.C.p.A. +# +# Distributed under the terms of the GPL license. +# See LICENSE.txt for more info. + +""" +Simulatede2BbaSwitch + +Simple boolen r/w variable. +The real thing will be a boolen attribute expoter by the Tango MPS interface +""" + +# PROTECTED REGION ID(Simulatede2BbaSwitch.system_imports) ENABLED START # +# PROTECTED REGION END # // Simulatede2BbaSwitch.system_imports + +# PyTango imports +import tango +from tango import DebugIt +from tango.server import run +from tango.server import Device +from tango.server import attribute, command +from tango import AttrQuality, DispLevel, DevState +from tango import AttrWriteType, PipeWriteType +# Additional import +# PROTECTED REGION ID(Simulatede2BbaSwitch.additionnal_import) ENABLED START # +# PROTECTED REGION END # // Simulatede2BbaSwitch.additionnal_import + +__all__ = ["Simulatede2BbaSwitch", "main"] + + +class Simulatede2BbaSwitch(Device): + """ + Simple boolen r/w variable. + The real thing will be a boolen attribute expoter by the Tango MPS interface + """ + # PROTECTED REGION ID(Simulatede2BbaSwitch.class_variable) ENABLED START # + # PROTECTED REGION END # // Simulatede2BbaSwitch.class_variable + + # ---------- + # Attributes + # ---------- + + enable = attribute( + dtype='DevBoolean', + access=AttrWriteType.READ_WRITE, + label="bba enable", + doc="true if enabled", + ) + + # --------------- + # General methods + # --------------- + + def init_device(self): + """Initializes the attributes and properties of the Simulatede2BbaSwitch.""" + Device.init_device(self) + self._enable = False + # PROTECTED REGION ID(Simulatede2BbaSwitch.init_device) ENABLED START # + dev_m_attr = self.get_device_attr() + wattr = dev_m_attr.get_w_attr_by_name("enable") + wattr.set_write_value(False) + self.set_state(tango.DevState.ON) + self.set_status("MPS BBA switches ready") + # PROTECTED REGION END # // Simulatede2BbaSwitch.init_device + + def always_executed_hook(self): + """Method always executed before any TANGO command is executed.""" + # PROTECTED REGION ID(Simulatede2BbaSwitch.always_executed_hook) ENABLED START # + # PROTECTED REGION END # // Simulatede2BbaSwitch.always_executed_hook + + def delete_device(self): + """Hook to delete resources allocated in init_device. + + This method allows for any memory or other resources allocated in the + init_device method to be released. This method is called by the device + destructor and by the device Init command. + """ + # PROTECTED REGION ID(Simulatede2BbaSwitch.delete_device) ENABLED START # + # PROTECTED REGION END # // Simulatede2BbaSwitch.delete_device + + # ------------------ + # Attributes methods + # ------------------ + + def read_enable(self): + # PROTECTED REGION ID(Simulatede2BbaSwitch.enable_read) ENABLED START # + """Return the enable attribute.""" + return self._enable + # PROTECTED REGION END # // Simulatede2BbaSwitch.enable_read + def write_enable(self, value): + # PROTECTED REGION ID(Simulatede2BbaSwitch.enable_write) ENABLED START # + """Set the enable attribute.""" + self._enable = value + # PROTECTED REGION END # // Simulatede2BbaSwitch.enable_write + # -------- + # Commands + # -------- + + +# ---------- +# Run server +# ---------- + +# PROTECTED REGION ID(Simulatede2BbaSwitch.custom_code) ENABLED START # +# PROTECTED REGION END # // Simulatede2BbaSwitch.custom_code + + +def main(args=None, **kwargs): + """Main function of the Simulatede2BbaSwitch module.""" + # PROTECTED REGION ID(Simulatede2BbaSwitch.main) ENABLED START # + return run((Simulatede2BbaSwitch,), args=args, **kwargs) + # PROTECTED REGION END # // Simulatede2BbaSwitch.main + +# PROTECTED REGION ID(Simulatede2BbaSwitch.custom_functions) ENABLED START # +# PROTECTED REGION END # // Simulatede2BbaSwitch.custom_functions + + +if __name__ == '__main__': + main() diff --git a/src/Simulatede2BbaSwitch.xmi b/src/Simulatede2BbaSwitch.xmi new file mode 100644 index 0000000000000000000000000000000000000000..3f9968e29cb7badce45dc68332838ff1422e560c --- /dev/null +++ b/src/Simulatede2BbaSwitch.xmi @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="ASCII"?> +<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://tango.org/pogo/PogoDsl"> + <classes name="Simulatede2BbaSwitch" pogoRevision="9.9"> + <description description="Simple boolen r/w variable.
The real thing will be a boolen attribute expoter by the Tango MPS interface" title="Simulatede2BbaSwitch" sourcePath="/home/claudio/src/gitlab/dt/ds/simulatede2bbaswitch/src" language="PythonHL" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="Elettra - Sincrotrone Trieste S.C.p.A." hasMandatoryProperty="false" hasConcreteProperty="false" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_Impl" sourcePath=""/> + <identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="Simulators" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference=""> + <keyWords>simulator</keyWords> + <keyWords>Eelttra 2.0</keyWords> + </identification> + </description> + <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device state"> + <type xsi:type="pogoDsl:StateType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="Status" description="This command gets the device status (stored in its device_status data member) and returns it to the caller." execMethod="dev_status" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device status"> + <type xsi:type="pogoDsl:ConstStringType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <attributes name="enable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="true if enabled" label="bba enable" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <preferences docHome="./doc_html" makefileHome="$(TANGO_HOME)"/> + </classes> +</pogoDsl:PogoSystem>