source: trunk/FACT++/scripts/doCrateReset.js@ 16842

Last change on this file since 16842 was 16788, checked in by tbretz, 12 years ago
File size: 4.0 KB
Line 
1// ==========================================================================
2// Reset Crate
3// ==========================================================================
4
5// call it with: .js doCrateReset.js crate0=true crate3=true
6// or: DIM_CONTROL/START doCrateReset.js crate0=true crate3=true
7
8// -------------------------------------------------------------------------
9
10include('scripts/CheckStates.js');
11
12var crate =
13[
14 $['camera']==true || $['crate0']=='true',
15 $['camera']==true || $['crate1']=='true',
16 $['camera']==true || $['crate2']=='true',
17 $['camera']==true || $['crate3']=='true'
18];
19
20var camera = $['camera']=='true';
21
22var cnt = 0;
23for (var i=0; i<4; i++)
24 if (crate[i])
25 cnt++;
26
27if (cnt==0)
28{
29 console.out("No crate to reset.");
30 exit();
31}
32
33console.out("Checking availability of servers...");
34
35var table =
36[
37 [ "MCP" ],
38 [ "FTM_CONTROL" ],
39 [ "FAD_CONTROL" ],
40];
41if (!checkStates(table, 3000))
42 throw new Error("Either MCP, FTM_CONTROL or FAD_CONTROL not online.");
43
44// No data taking should be in progress
45// Trigger must be switched off
46
47checkSend(["MCP", "FAD_CONTROL", "FTM_CONTROL" ]);
48
49
50var mcp = dim.state("MCP");
51if (mcp.name=="TriggerOn" || mcp.state=="TakingData")
52 dim.send("MCP/STOP");
53if (mcp.name.substr(0,7)=="kConfig")
54 dim.send("MCP/RESET");
55if (dim.state("FTM_CONTROL").name=="TriggerOn")
56 dim.send("FTM_CONTROL/STOP_TRIGGER");
57
58/*
59var table =
60[
61 [ "MCP", [ "Idle", "Connected" ]],
62 [ "FTM_CONTROL", [ "Idle" ] ],
63];
64checkStates(table);
65*/
66
67//dim.send("FTM_CONTROL/RESET_CONFIGURE");
68//dim.send("FTM_CONTROL/STOP_TRIGGER");
69
70//if (dim.state("FAD_CONTROL").name=="RunInProgress")
71// dim.send("FAD_CONTROL/CLOSE_OPEN_FILES");
72
73//if (fadstate=="Configuring1" || fadstate=="Configuring2" || fadstate=="Configured")
74// dim.send("FAD_CONTROL/RESET_CONFIGURE");
75//v8.timeout(5000, function() { if (dim.state("FAD_CONTROL").index<5) return true; });
76
77console.out("Checking status of servers...");
78
79var table =
80[
81 [ "MCP", [ "Idle", "Connected" ]],
82 [ "FTM_CONTROL", [ "Valid" ] ],
83 [ "FAD_CONTROL", [ "Disengaged", "Disconnected", "Connecting", "Connected" ] ],
84];
85if (!checkStates(table))
86 throw new Error("Either MCP, FTM_CONTROL or FAD_CONTROL not in a state in which it ought to be.");
87
88// FTUs must be switched off
89
90console.out("Disable FTUs...");
91
92//checkSend(["FTM_CONTROL"]);
93dim.send("FTM_CONTROL/ENABLE_FTU", -1, false);
94v8.sleep(1000);
95
96// Boards in the crates must be disconnected
97
98//checkSend(["FAD_CONTROL"]);
99
100if (dim.state("FAD_CONTROL").name=="Connecting" || dim.state("FAD_CONTROL").name=="Connected")
101 for (var i=0; i<10; i++)
102 {
103 for (var j=0; j<4; j++)
104 if (crate[j])
105 {
106 console.out("Sending DISCONNECT "+(j*10+i));
107 dim.send("FAD_CONTROL/DISCONNECT", j*10+i);
108 }
109 }
110
111v8.sleep(2000);
112if (!checkStates([[ "FAD_CONTROL", [ "Disengaged", "Disconnected", "Connected" ] ]]))
113 throw new Error("FAD_CONTROL neither Disengaged, Disconnected not Connected.");
114
115
116// Reset crates
117
118if (camera)
119 dim.send("FTM_CONTROL/RESET_CAMERA");
120else
121{
122 for (var i=0; i<4; i++)
123 if (crate[i])
124 {
125 console.out("Sending RESET_CRATE "+i);
126 dim.send("FTM_CONTROL/RESET_CRATE", i);
127 }
128}
129
130// We have to wait a bit
131
132v8.sleep(3200);
133
134// Reconnect all boards
135
136if (dim.state("FAD_CONTROL").name=="Disengaged")
137{
138 dim.send("Waiting 38s for crates to finish reset.");
139 v8.sleep(38000);
140 dim.send("FAD_CONTROL", "START");
141}
142else
143 for (var i=0; i<10; i++)
144 {
145 v8.sleep(3200);
146 for (var j=0; j<4; j++)
147 if (crate[j])
148 {
149 console.out("Sending CONNECT "+(j*10+i));
150 dim.send("FAD_CONTROL/CONNECT", j*10+i);
151 }
152 }
153
154
155// Reconnect all FTUs
156
157console.out("Enable FTUs...");
158
159v8.sleep(1000);
160dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
161v8.sleep(3000);
162dim.send("FTM_CONTROL/PING");
163v8.sleep(1000);
164
165dim.wait("FAD_CONTROL", "Connected", 3000);
166
167// Done
168
169console.out("Crate reset finished.");
Note: See TracBrowser for help on using the repository browser.