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/Cmm.py b/Cmm.py new file mode 100644 index 0000000000000000000000000000000000000000..b57e160fc55cd325967baf717e5bbf872eedbe29 --- /dev/null +++ b/Cmm.py @@ -0,0 +1,321 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- + + +# ############################################################################ +# license : +# ============================================================================ +# +# File : Cmm.py +# +# Project : Cmm server +# +# This file is part of Tango device class. +# +# Tango is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Tango is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Tango. If not, see <http://www.gnu.org/licenses/>. +# +# +# $Author : alessandro.olivo$ +# +# $Revision : $ +# +# $Date : $ +# +# $HeadUrl : $ +# ============================================================================ +# This file is generated by POGO +# (Program Obviously used to Generate tango Object) +# ############################################################################ + +__all__ = ["Cmm", "CmmClass", "main"] + +__docformat__ = 'restructuredtext' + +import PyTango +import sys +# Add additional import +#----- PROTECTED REGION ID(Cmm.additionnal_import) ENABLED START -----# +############################################################################## +# CVS strings automatically managed +# $Name: $ +# $Header: /home/cvsadm/cvsroot/fermi/servers/cmm/Cmm.py,v 1.3 2018-01-19 12:32:59 alessandro.olivo Exp $ +# $Log: Cmm.py,v $ +# Revision 1.3 2018-01-19 12:32:59 alessandro.olivo +# 1) Allow cvs to add source release on check out; +# 2) Improve exceptions managing; +# 3) Improve SysReset command feedback. +# +############################################################################## + +import socket +import re + +#----- PROTECTED REGION END -----# // Cmm.additionnal_import + +# Device States Description +# No states for this device + + +class Cmm (PyTango.Device_4Impl): + """""" + + # -------- Add you global variables here -------------------------- + #----- PROTECTED REGION ID(Cmm.global_variables) ENABLED START -----# + + #----- PROTECTED REGION END -----# // Cmm.global_variables + + def __init__(self, cl, name): + PyTango.Device_4Impl.__init__(self,cl,name) + self.debug_stream("In __init__()") + Cmm.init_device(self) + #----- PROTECTED REGION ID(Cmm.__init__) ENABLED START -----# + + #----- PROTECTED REGION END -----# // Cmm.__init__ + + def delete_device(self): + self.debug_stream("In delete_device()") + #----- PROTECTED REGION ID(Cmm.delete_device) ENABLED START -----# + + #----- PROTECTED REGION END -----# // Cmm.delete_device + + def init_device(self): + self.debug_stream("In init_device()") + self.get_device_properties(self.get_device_class()) + self.attr_ECHostname_read = [""] + #----- PROTECTED REGION ID(Cmm.init_device) ENABLED START -----# + self.mandatory_not_defined = False + self.property_not_correct = False + self.check_mandatory_property() + if self.mandatory_not_defined: + print self.get_status() + return + + try: + socket.gethostbyname(self.Hostname) + except socket.gaierror: + self.mandatory_not_defined = True + self.set_state(PyTango.DevState.FAULT) + self.set_status("The inserted hostname \"" + self.Hostname + "\"" + " doesn't exist") + print self.get_status() + return + + print "Ready to accept request" + #----- PROTECTED REGION END -----# // Cmm.init_device + + def always_executed_hook(self): + self.debug_stream("In always_excuted_hook()") + #----- PROTECTED REGION ID(Cmm.always_executed_hook) ENABLED START -----# + if self.mandatory_not_defined: + PyTango.Except.throw_exception("PROPERTY_NOT_SET", + self.get_status(), + "In always_excuted_hook()") + if self.property_not_correct: + PyTango.Except.throw_exception("PROPERTY_NOT_CORRECT", + self.get_status(), + "In always_excuted_hook()") + #----- PROTECTED REGION END -----# // Cmm.always_executed_hook + + # ------------------------------------------------------------------------- + # Cmm read/write attribute methods + # ------------------------------------------------------------------------- + + def read_ECHostname(self, attr): + self.debug_stream("In read_ECHostname()") + #----- PROTECTED REGION ID(Cmm.ECHostname_read) ENABLED START -----# + self.attr_ECHostname_read = self.ECHostname + attr.set_value(self.attr_ECHostname_read) + + #----- PROTECTED REGION END -----# // Cmm.ECHostname_read + + + + + def read_attr_hardware(self, data): + self.debug_stream("In read_attr_hardware()") + #----- PROTECTED REGION ID(Cmm.read_attr_hardware) ENABLED START -----# + + + #----- PROTECTED REGION END -----# // Cmm.read_attr_hardware + + + # ------------------------------------------------------------------------- + # Cmm command methods + # ------------------------------------------------------------------------- + + def dev_state(self): + """ This command gets the device state (stored in its device_state data member) and returns it to the caller. + :return: Device state + :rtype: PyTango.CmdArgType.DevState + """ + self.debug_stream("In dev_state()") + argout = PyTango.DevState.UNKNOWN + #----- PROTECTED REGION ID(Cmm.State) ENABLED START -----# + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(self.Timeout) + try: + s.connect((self.Hostname, 80)) + argout = PyTango.DevState.ON + except Exception as e: + argout = PyTango.DevState.FAULT + finally: + s.shutdown(socket.SHUT_RDWR) + s.close() + self.set_state(argout) + + #----- PROTECTED REGION END -----# // Cmm.State + if argout != PyTango.DevState.ALARM: + PyTango.Device_4Impl.dev_state(self) + return self.get_state() + + def dev_status(self): + """ This command gets the device status (stored in its device_status data member) and returns it to the caller. + :return: Device status + :rtype: PyTango.ConstDevString + """ + self.debug_stream("In dev_status()") + argout = "" + #----- PROTECTED REGION ID(Cmm.Status) ENABLED START -----# + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(self.Timeout) + try: + s.connect((self.Hostname, 80)) + argout = "TCP connection to the device is available" + except Exception as e: + argout = "Device web server is not reachable.\nError details:\n"\ + + str(e) + finally: + s.shutdown(socket.SHUT_RDWR) + s.close() + self.argout = argout + + #----- PROTECTED REGION END -----# // Cmm.Status + self.set_status(self.argout) + self.__status = PyTango.Device_4Impl.dev_status(self) + return self.__status + + def SysReset(self): + """ Reset the VMEbus system. + """ + self.debug_stream("In SysReset()") + #----- PROTECTED REGION ID(Cmm.SysReset) ENABLED START -----# + request_url = "/sysres.cgi?sysres=System+Reset" + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(self.Timeout) + resp = "" + try: + s.connect((self.Hostname, 80)) + s.sendall("GET " + request_url) + resp = s.recv(1024).splitlines()[0] + except Exception as e: + PyTango.Except.throw_exception( + "Problems occurred during TCP connection to the device web server" + " (Error: " + str(e) + " )", + "VME System may not have been reset", + "In SysReset()") + finally: + s.shutdown(socket.SHUT_RDWR) + s.close() + + if resp != "HTTP/1.0 200 OK": + PyTango.Except.throw_exception( + "Http response not expected (Error: " + resp + " )", + "VME System may not have been reset", + "In SysReset()") + + #----- PROTECTED REGION END -----# // Cmm.SysReset + + + #----- PROTECTED REGION ID(Cmm.programmer_methods) ENABLED START -----# + + # ------------------------------------------------------------------------- + # Cmm helper methods + # ------------------------------------------------------------------------- + + def check_mandatory_property(self): + self.debug_stream("In check_mandatory_property()") + + if not self.Hostname: + self.mandatory_not_defined = True + self.set_state(PyTango.DevState.FAULT) + self.set_status("\"Hostname\" is mandatory property" + + " but is not defined in database") + + #----- PROTECTED REGION END -----# // Cmm.programmer_methods + +class CmmClass(PyTango.DeviceClass): + # -------- Add you global class variables here -------------------------- + #----- PROTECTED REGION ID(Cmm.global_class_variables) ENABLED START -----# + + #----- PROTECTED REGION END -----# // Cmm.global_class_variables + + + # Class Properties + class_property_list = { + } + + + # Device Properties + device_property_list = { + 'Hostname': + [PyTango.DevString, + "Cmm hostname", + [] ], + 'ECHostname': + [PyTango.DevVarStringArray, + "Hostname of the EC(s) managed by the CMM", + [] ], + 'Timeout': + [PyTango.DevUShort, + "TCP connection timeout", + [1]], + } + + + # Command definitions + cmd_list = { + 'SysReset': + [[PyTango.DevVoid, "none"], + [PyTango.DevVoid, "none"]], + } + + + # Attribute definitions + attr_list = { + 'ECHostname': + [[PyTango.DevString, + PyTango.SPECTRUM, + PyTango.READ, 21]], + } + + +def main(): + try: + py = PyTango.Util(sys.argv) + py.add_class(CmmClass, Cmm, 'Cmm') + #----- PROTECTED REGION ID(Cmm.add_classes) ENABLED START -----# + + #----- PROTECTED REGION END -----# // Cmm.add_classes + + U = PyTango.Util.instance() + U.server_init() + U.server_run() + + except PyTango.DevFailed as e: + print ('-------> Received a DevFailed exception:', e) + except Exception as e: + print ('-------> An unforeseen exception occured....', e) + +if __name__ == '__main__': + main() diff --git a/Cmm.xmi b/Cmm.xmi new file mode 100644 index 0000000000000000000000000000000000000000..7f312f51dcb6821a3bf472480393b78d5568f3ac --- /dev/null +++ b/Cmm.xmi @@ -0,0 +1,58 @@ +<?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://www.esrf.fr/tango/pogo/PogoDsl"> + <classes name="Cmm" pogoRevision="9.4"> + <description description="" title="Cmm server" sourcePath="/home/alessandro.olivo/devel/fermi/servers/cmm" language="Python" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_Impl" sourcePath=""/> + <identification contact="at elettra.eu - alessandro.olivo" author="alessandro.olivo" emailDomain="elettra.eu" classFamily="MeasureInstruments" siteSpecific="" platform="All Platforms" bus="Ethernet" manufacturer="Elettra" reference=""/> + </description> + <deviceProperties name="Hostname" description="Cmm hostname"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="ECHostname" description="Hostname of the EC(s) managed by the CMM"> + <type xsi:type="pogoDsl:StringVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Timeout" description="TCP connection timeout"> + <type xsi:type="pogoDsl:UShortType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>1</DefaultPropValue> + </deviceProperties> + <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" isDynamic="false"> + <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" concreteHere="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" isDynamic="false"> + <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" concreteHere="true"/> + </commands> + <commands name="SysReset" description="Reset the VMEbus system." execMethod="sys_reset" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <attributes name="ECHostname" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="21" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:StringType"/> + <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="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <preferences docHome="./doc_html" makefileHome="/usr/local/tango-9.2.5a/share/pogo/preferences"/> + </classes> +</pogoDsl:PogoSystem> diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..65c5ca88a67c30becee01c5a8816d964b03862f9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md index 81d797f6a3942e1a994ef61c0eb4072a5022d765..322bcbddaabcca57b4adbe984b1b9f22dd10ccf8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,31 @@ -# cmm +# Project Name +cmm + +## Description + +Simple Tango device server for cmm: Schroff chassis monitoring module + +## Dependencies + +The device is written in python 2.7 and needs the tango python bindings + +## Installation & deployment + +install src/Cmm.py and src/cmm-srv in the execution directory of the target system + +## History + +2020-03-27 imported from CVS repo fermi/server/cmm release_03 + +## Credits + +developed by Alessando Olivo + +Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +Strada Statale 14 - km 163,5 in AREA Science Park +34149 Basovizza, Trieste ITALY + +## License + +GPL 3 diff --git a/doc/User_Manual.pdf b/doc/User_Manual.pdf new file mode 100644 index 0000000000000000000000000000000000000000..5fc81520614165d48e7667c6855c382dd1b59629 Binary files /dev/null and b/doc/User_Manual.pdf differ