source: trunk/FACT++/scripts/crateReset.js@ 17921

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