DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
felixRPCServer.py
Go to the documentation of this file.
1from SimpleXMLRPCServer import SimpleXMLRPCServer
2from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
3from subprocess import call, Popen, PIPE
4import re
5
6pathBase="<felix_dist_dir>"
7
8def shell_source(script):
9 """Sometime you want to emulate the action of "source" in bash,
10 settings some environment variables. Here is a way to do it."""
11 import subprocess, os
12 pipe = subprocess.Popen(". %s; env" % script, stdout=subprocess.PIPE, shell=True)
13 output = pipe.communicate()[0]
14 #print output
15 env = dict((line.split("=", 1) for line in output.splitlines()))
16 os.environ.update(env)
17
18def callSubp(appDict):
19 p = Popen(appDict, stdin=PIPE, stdout=PIPE, stderr=PIPE)
20 output, err = p.communicate(b"input data that is passed to subprocess' stdin")
21 return output, err, p.returncode
22
23shell_source("<felix_dist_dir>/setup.sh")
24
25# Restrict to a particular path.
26class RequestHandler(SimpleXMLRPCRequestHandler):
27 rpc_paths = ('/RPC2',)
28
29# Create server
30server = SimpleXMLRPCServer(("0.0.0.0", 9999),requestHandler=RequestHandler)
31server.register_introspection_functions()
32
34
35 def heartbeat(self):
36 return "OK"
37
38 def init(self, card=0):
39 card = "-d "+str(card)
40 ret1 = call([pathBase+"flxcard/flx-init", card])
41 ret2 = call([pathBase+"flxcard/flx-reset", card, "GTH"])
42 # automatic link recovery (sponzio)
43 ret3 = call([pathBase+"flxcard/flx-config", card, "set", "GBT_CHANNEL_DISABLE=0x7DF"])
44 return ret1, ret2, ret3
45
46 def driverRestart(self):
47 retStop = callSubp(["/etc/init.d/drivers_flx", "stop"])
48 retStart = callSubp(["/etc/init.d/drivers_flx", "start"])
49 return retStop, retStart
50
51# def setEmulator(self, ena=True):
52# if ena:
53# out, err, retC = callSubp([pathBase+"ftools/femu", "-e", "-d 0"])
54# else:
55# out, err, retC = callSubp([pathBase+"ftools/femu", "-n", "-d 0"])
56# return out, err, retC
57
58# def softReset(self, card=0):
59# card = "-d "+str(card)
60# out, err, retC = callSubp([pathBase+"flxcard/flx-reset", card, "SOFT_RESET"])
61# return out, err, retC
62
63# def driverStatus(self):
64# out, err, retC = callSubp(["/etc/init.d/drivers_flx", "status"])
65# return out, err, retC
66
67 def isAnyLinkDown(self, card=0):
68 card = "-d "+str(card)
69 out, err, ret = callSubp([pathBase+"flxcard/flx-info", card, "gbt"])
70 p = re.compile("YES|NO")
71 links = p.findall(out)
72 linkDown = False
73 for link in links[0:5]:
74 if link == 'NO':
75 linkDown = linkDown or True
76 for link in links[6:11]:
77 if link == 'NO':
78 linkDown = linkDown or True
79 return linkDown, out, err, ret
80
81 def configLinks(self, card=0):
82 c0 = "-d "+str(card)
83 c1 = "-d "+str(card+1)
84 ret1 = call([pathBase+"flxcard/flx-config", c0, "set", "TIMEOUT_CTRL_ENABLE=0"])
85 ret2 = call([pathBase+"flxcard/flx-config", c0, "set", "CR_TTC_TOHOST_TIMEOUT_ENABLE=0"])
86 ret3 = call([pathBase+"flxcard/flx-config", c0, "set", "GBT_TOHOST_FANOUT_SEL=0"])
87 ret4 = call([pathBase+"flxcard/flx-config", c0, "set", "CR_FM_PATH_ENA=0x1F"])
88 ret5 = call([pathBase+"flxcard/flx-config", c1, "set", "TIMEOUT_CTRL_ENABLE=0"])
89 ret6 = call([pathBase+"flxcard/flx-config", c1, "set", "CR_TTC_TOHOST_TIMEOUT_ENABLE=0"])
90 ret7 = call([pathBase+"flxcard/flx-config", c1, "set", "GBT_TOHOST_FANOUT_SEL=0"])
91 ret8 = call([pathBase+"flxcard/flx-config", c1, "set", "CR_FM_PATH_ENA=0x1F"])
92 return ret1, ret2, ret3, ret4, ret5, ret6, ret7, ret8
93
94 def disableLinks(self, card=0):
95 c0 = "-d "+str(card)
96 c1 = "-d "+str(card+1)
97 ret1 = call([pathBase+"flxcard/flx-config", c0, "set", "CR_FM_PATH_ENA=0"])
98 ret2 = call([pathBase+"flxcard/flx-config", c1, "set", "CR_FM_PATH_ENA=0"])
99 return ret1, ret2
100
101server.register_instance(FelixFuncs())
102
103# Run the server's main loop
104server.serve_forever()
105
106
shell_source(script)