Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/mirror_device_8py_source.html
Дата изменения: Tue Sep 15 02:25:37 2015
Дата индексирования: Sun Apr 10 02:40:51 2016
Кодировка:

Поисковые слова: clouds
lsst.tcc: python/tcc/mir/mirrorDevice.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mirrorDevice.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 """Mirror device.
3 """
4 from twistedActor import ActorDevice, log, expandUserCmd
5 
6 __all__ = ["MirrorDevice"]
7 
8 # list of mirror keywords the TCC cares about;
9 # warning: case must match the case in the mirror model
10 tccKWs = (
11  "desOrient",
12  "orient",
13  "state",
14  "status",
15  "desOrientAge",
16  "cmdMount",
17  "actMount",
18  "desEncMount",
19  "encMount",
20  "modelMount",
21  "maxIter",
22  "netMountOffset",
23  "mountErr",
24  "text",
25 )
26 
27 class MirrorDevice(ActorDevice):
28  """!A Mirror Device
29  """
30  DefaultTimeLim = None # a poor choice, but the best we can do until commands pay attention to predicted duration
31  def __init__(self,
32  name,
33  host,
34  port,
35  modelName = "mirror",
36  ):
37  """!Construct a MirrorDevice
38 
39  @param[in] name mirror name, one of "prim", "sec" or "tert"
40  @param[in] host mirror controller host
41  @param[in] port mirror controller port
42  @param[in] modelName name of mirror controller keyword dictionary; usually "mirror"
43  """
44  ActorDevice.__init__(self,
45  name=name,
46  host=host,
47  port=port,
48  modelName=modelName,
49  )
50 
51  def init(self, userCmd=None, timeLim=2, getStatus=True):
52  """!Initialize the device and cancel all pending commands
53 
54  @param[in] userCmd user command that tracks this command, if any
55  @param[in] timeLim maximum time before command expires, in sec; None for no limit
56  @param[in] getStatus IGNORED (status is automatically output sometime after stop)
57  @return userCmd (a new one if the provided userCmd is None)
58  """
59  userCmd = expandUserCmd(userCmd)
60  self.startCmd(cmdStr="stop", userCmd=userCmd, timeLim=timeLim)
61  return userCmd
62 
63  def startKWForwarding(self):
64  """!Method to begin keyword forwarding for keywords of interest,
65  if self.writeToUsers has been added by the actor.
66  """
67  def forwardKW(value, isCurrent, keyVar):
68  """!KeyVar callback on KeyVar objects that the TCC cares about
69  simply forwards on the keyword with a mirror name prepended
70  """
71  # if this is text, don't prepend the mirror name, just forward as is
72  msgCode = keyVar.reply.header.code if keyVar.reply else "i"
73  if keyVar.name.lower() == "text":
74  # only forward if it is a warning or higher
75  if msgCode in ["e", "w"]:
76  mirNameUp = ""
77  keyVarNameUp = keyVar.name
78  msgStr = "Text=" + "\"" + str(keyVar.valueList[0]) + "\""
79  # import pdb; pdb.set_trace()
80  else:
81  # do nothing
82  return
83  else:
84  # get uppercase name, eg Tert (not tert)
85  mirNameUp = self.name[0].capitalize() + self.name[1:]
86  keyVarNameUp = keyVar.name[0].capitalize() + keyVar.name[1:]
87  # print 'callback value', keyVar, str(value), str(keyVar.valueList)
88  strValList = []
89  for value in keyVar.valueList:
90  strValList.append(str(value) if value!=None else "NaN")
91  # prepend name to msg keyword
92  msgStr = '%s=%s' % (''.join([mirNameUp, keyVarNameUp]), ','.join(strValList))
93  self.writeToUsers(msgCode=msgCode, msgStr=msgStr)
94 
95  for kw in tccKWs:
96  getattr(self.dispatcher.model, kw).addValueCallback(forwardKW, callNow = True)
97 
98  def handleReply(self, reply):
99  """!Called each time a reply comes through the line
100  """
101  # print "%s.handleReply(reply=%r)" % (self, reply)
102  log.info("%s read %r" % (self, reply))
103 
104  @property
105  def timeLimKeyVar(self):
106  """!Return a tuple containing the time limit keyvar and index for use in setting automatically
107  updating time limits
108  """
109  return (self.dispatcher.model.state, 4)
110 
111  def startCmd(self,
112  cmdStr,
113  callFunc = None,
114  userCmd = None,
115  timeLim = 0,
116  timeLimKeyVar = None,
117  timeLimKeyInd = 0,
118  abortCmdStr = None,
119  keyVars = None,
120  showReplies = False,
121  ):
122  """!Queue or start a new command.
123 
124  If timeLimKeyVar not specified, use the state keyword.
125 
126  @param[in] cmdStr the command; no terminating \n wanted
127  @param[in] callFunc callback function: function to call when command succeeds or fails, or None;
128  if specified it receives one argument: an opscore.actor.CmdVar object
129  @param[in] userCmd user command that tracks this command, if any
130  @param[in] callFunc a callback function; it receives one argument: a CmdVar object
131  @param[in] userCmd user command that tracks this command, if any
132  @param[in] timeLim maximum time before command expires, in sec; 0 for no limit
133  @param[in] timeLimKeyVar a KeyVar specifying a delta-time by which the command must finish
134  this KeyVar must be registered with the message dispatcher.
135  @param[in] timeLimKeyInd the index of the time limit value in timeLimKeyVar; defaults to 0;
136  ignored if timeLimKeyVar is None.
137  @param[in] abortCmdStr a command string that will abort the command.
138  Sent to the actor if abort is called and if the command is executing.
139  @param[in] keyVars a sequence of 0 or more keyword variables to monitor for this command.
140  Any data for those variables that arrives IN RESPONSE TO THIS COMMAND is saved
141  and can be retrieved using cmdVar.getKeyVarData or cmdVar.getLastKeyVarData.
142  @param[in] showReplies show all replies as plain text?
143 
144  @return devCmd: the device command that was started (and may already have failed)
145 
146  @note: if callFunc and userCmd are both specified callFunc is called before userCmd is updated.
147  """
148  if not timeLimKeyVar:
149  timeLimKeyVar, timeLimKeyInd = self.model.state, 3
150  return ActorDevice.startCmd(self,
151  cmdStr = cmdStr,
152  callFunc = callFunc,
153  userCmd = userCmd,
154  timeLim = timeLim,
155  timeLimKeyVar = timeLimKeyVar,
156  timeLimKeyInd = timeLimKeyInd,
157  abortCmdStr = abortCmdStr,
158  keyVars = keyVars,
159  showReplies = showReplies,
160  )
def handleReply
Called each time a reply comes through the line.
Definition: mirrorDevice.py:98
def startKWForwarding
Method to begin keyword forwarding for keywords of interest, if self.writeToUsers has been added by t...
Definition: mirrorDevice.py:63
def init
Initialize the device and cancel all pending commands.
Definition: mirrorDevice.py:51
def __init__
Construct a MirrorDevice.
Definition: mirrorDevice.py:36
def startCmd
Queue or start a new command.
def timeLimKeyVar
Return a tuple containing the time limit keyvar and index for use in setting automatically updating t...