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

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