Commit f19a1ca0 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

libicepap: remove libdeep and globals.

The communication is now managed with bliss tcp in
function _command and _askcommand in file system.py

changed also to default logging python module
parent 8c60f303
......@@ -6,13 +6,6 @@
#
import string
#-------------------------------------------------------------------------
# Library modules
#
import globals
#-------------------------------------------------------------------------
# Constant defintions
#
......@@ -33,57 +26,6 @@ def axis_to_name(axis):
except:
raise ValueError("invalid axis object")
def name_to_axis(name):
try:
return globals._known_axis[name]
except:
raise ValueError("invalid axis name \"%s\""%name)
def addr_to_axis(argin, addr):
"""Returns the axis object corresponding the system:addr given
The IcePAP system can be specified with its hostname or an object
"""
# The system could be specified as an object or a hostname string
if isinstance(argin, basestring):
return hostname_to_axis(argin, addr)
else:
return system_to_axis(argin, addr)
def hostname_to_axis(hostname, addr):
# Look for a matching axis in the global library resource
try:
for name in globals._known_axis:
axis = name_to_axis(name)
if axis.system().hostname() == hostname:
if axis.address() == addr:
return axis
except:
raise ValueError("invalid axis address")
# Abnormal end
raise ValueError("axis not found")
def system_to_axis(system, addr):
# Look for a matching axis in the global library resource
try:
for name in globals._known_axis:
axis = name_to_axis(name)
if axis.system() == system:
if axis.address() == addr:
return axis
except:
raise ValueError("invalid axis address")
# Abnormal end
raise ValueError("axis not found")
#-------------------------------------------------------------------------
# Inteface function
#
......@@ -339,13 +281,6 @@ class Axis(object):
self._flags["exclusive"] = False
self._used_in_groups = []
#
self._commands = globals._known_commandlist[hostname]
# Update the library global resource
globals._known_axis[self._name] = self
def name(self):
return(self._name)
......@@ -396,9 +331,6 @@ class Axis(object):
def set_debug_mode(self, dbgmode):
self._system.set_debug_mode(dbgmode)
def is_valid_command(self, comm):
return comm.split()[0].upper() in self._commands
def command(self, str_cmd, in_data=None):
# Minimum check on command syntax
......
"""IcePAP library"""
#-------------------------------------------------------------------------
# Module resources
#
_known_devices = {}
_known_commandlist = {}
_known_groups = {}
_known_axis = {}
#-------------------------------------------------------------------------
# Constant defintions
#
DEBUG1 = "verb=1"
DEBUG2 = "verb=2"
DEBUG3 = "verb=3"
......@@ -10,7 +10,6 @@ import string
#-------------------------------------------------------------------------
# Library modules
#
import globals
import axis as libaxis
import types as libtypes
......@@ -32,17 +31,6 @@ def group_to_name(grp):
except:
raise ValueError("invalid group object")
def name_to_group(name):
try:
return globals._known_groups[name]
except:
raise ValueError("invalid group name \"%s\""%name)
def group_exists(name):
return name in globals._known_groups
#-------------------------------------------------------------------------
# Inteface function
#
......@@ -144,13 +132,7 @@ class Group(object):
def __init__(self, name, axis_list=None, flags=""):
"""Object constructor"""
# Group names are unique over the library scope
try:
name_to_group(name)
except ValueError:
self._name = name
else:
raise ValueError("already defined group name \"%s\""%(name))
self._name = name
# Parse flags and get a dictionnary of booleans
self._flags = libaxis._parse_flags(flags)
......@@ -166,34 +148,12 @@ class Group(object):
for axis in axis_list:
self.add_axis(axis)
# Update the library global resource
#_known_groups[name] = weakref.ref(self,tagada)
globals._known_groups[name] = self
def ___del__(self):
"""Object destructor"""
# NOTE MP 13Oct3: avoid implementing the destrucor as this
# will impact the Python garbage collector.
# By the way, any code place here is not guaranteed to be
# execute when the "del" is used because it may remain
# references to a group object
#
def delete(self):
"""Remove the current group from the ones known by the library"""
# Inform all group axis that there are now free
self.delete_all_axis()
# Update the library global resource
try:
del globals._known_groups[self._name]
except:
pass
def delete_axis(self, axis):
# TODO
pass
......
......@@ -5,22 +5,8 @@ import sys
#-------------------------------------------------------------------------
# Library modules
#
import globals
#-------------------------------------------------------------------------
# Specific modules than must be in the PYTHONPATH
#
try:
from ..libdeep import device as deep_device
from ..libdeep import log as deep_log
except ImportError:
print 'ERROR: module "deep" not found'
print 'HINT : add to your PYTHONPATH the location of this module'
sys.exit(-1)
from bliss.comm.tcp import Command
from bliss.common.greenlet_utils import protect_from_kill
#-------------------------------------------------------------------------
# Class definition
......@@ -41,44 +27,12 @@ class System():
"""
def __init__(self, hostname, flags=""):
"""
Get a connection to an IcePAP device identified with its hostname
"""
# Save socket connections by keeping a non duplicated list
# of DeepDevice objects. Therefore this class can not inherit
# directly from DeepDevice one.
if hostname not in globals._known_devices:
# Mandatory libdeep argument for IcePAP devices
argin_str = ' '.join(["mode=icepap"]+[flags])
deepdevice = deep_device.DeepDevice(hostname, argin_str)
# Save communication payload doing the hypothesis that all
# axis of an IcePAP device have the same firmare version
globals._known_commandlist[hostname] = deepdevice.getcommandlist()
# Library global resource
globals._known_devices[hostname] = deepdevice
# Object initialization
self._hostname = hostname
self._deepdevice = globals._known_devices[hostname]
self._verbose = deep_log.DBG_ERROR
self._cnx = Command(hostname,5000,eol='\n')
def close(self):
"""Close communication links"""
if self._hostname in globals._known_devices:
self._deepdevice.close()
del globals._known_devices[self._hostname]
def set_verbose(self, val):
"""Change the verbose level"""
self._verbose = val
self._deepdevice.set_verbose(val)
def get_verbose(self):
"""Returns the current verbose level"""
return self._verbose
self._cnx.close()
def hostname(self):
"""Returns the IcePAP system hostname"""
......@@ -86,11 +40,37 @@ class System():
def command(self, str_cmd, in_data=None):
"""Send a command to the IcePAP system"""
return self._deepdevice.command(str_cmd, in_data)
return _command(self._cnx,str_cmd)
def ackcommand(self, str_cmd, in_data=None):
"""Send a command with acknowledge to the IcePAP system"""
return self._deepdevice.ackcommand(str_cmd, in_data)
return _ackcommand(self._cnx,str_cmd)
## Communication
def getcommandlist(cnx):
cmds = [x.strip() for x in _command(cnx,"?HELP").splitlines()]
print cmds
return cmds
@protect_from_kill
def _command(cnx,cmd):
transaction = cnx._write(cmd + '\n')
with cnx.Transaction(cnx,transaction) :
if cmd.startswith('?') or cmd.startswith('#') :
msg = cnx._readline(transaction=transaction,
clear_transaction=False)
cmd = cmd.strip('#').split(' ')[0]
msg = msg.replace(cmd + ' ','')
if msg.startswith('$'):
msg = cnx._readline(transaction=transaction,
clear_transaction=False,eol='$\n')
elif msg.startswith('ERROR'):
raise RuntimeError(msg.replace('ERROR ',''))
return msg
def _ackcommand(cnx,cmd):
if not cmd.startswith('#') and not cmd.startswith('?'):
cmd = '#' + cmd
return _command(cnx,cmd)
......@@ -11,13 +11,12 @@ import time
#-------------------------------------------------------------------------
# Library modules
#
import globals
import axis as libaxis
import groups as libgroups
import types as libtypes
import vdata as libvdata
from ..libdeep import log
import logging
#-------------------------------------------------------------------------
......@@ -182,7 +181,7 @@ class Trajectory(object):
def __init__(self, name, range_list=None):
"""Object constructor"""
self._log = logging.getLogger('Trajectory(%s)' % name)
# TODO: keep a library centralized list of trajectories
# TODO: keep a library centralized information on downloaded
# trajectories to DRIVERs
......@@ -547,7 +546,7 @@ class Trajectory(object):
# append an axis trajectory
if axis is None:
log.trace("updating parameter")
self._log.info("updating parameter")
# append mandatory parameter data
self._vdata.append(
......@@ -555,7 +554,7 @@ class Trajectory(object):
int(libvdata.ADDRUNSET),
libvdata.PARAMETER)
else:
log.trace("updating trajectory for axis: %s" % axis.name())
self._log.info("updating trajectory for axis: %s" % axis.name())
# append mandatory position data
self._vdata.append(
......
......@@ -10,7 +10,6 @@ import numpy
#-------------------------------------------------------------------------
# Library modules
#
import globals
import axis as libaxis
......
......@@ -7,13 +7,7 @@
import string
import struct
import numpy
#-------------------------------------------------------------------------
# Library modules
#
from ..libdeep import log
import logging
#-------------------------------------------------------------------------
# Global definitions
......@@ -204,8 +198,8 @@ class vdata(object):
# brute dump of bytes
# TODO: replace the test by a log.istrace()
if log.level() >= log.DBG_DATA:
log.trace("data vector contains:")
if log.level >= log.DBG_DATA:
log.debug("data vector contains:")
n = self.bin()
print ' '.join('0x{0:02x}'.format(x & 0xff) for x in n)
......@@ -236,15 +230,17 @@ class vdata(object):
full_sz *= 4
#
log.trace("#%d: data vector type: %s" %
log.debug("#%d: data vector type: %s" %
(cpt, self.type_to_str(flags)))
log.trace("#%d: destination addr: %d" %
log.debug("#%d: destination addr: %d" %
(cpt, self.addr_to_str(flags)))
log.trace("#%d: number of data : %d" %
log.debug("#%d: number of data : %d" %
(cpt, data_len))
log.trace("#%d: data vector size: %dbytes" %
log.debug("#%d: data vector size: %dbytes" %
(cpt, full_sz))
# jump to next slice
idx += full_sz
cpt += 1
log = logging.getLogger(str(vdata))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment