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 |
|
---|
12 | include('scripts/CheckStates.js');
|
---|
13 |
|
---|
14 | function 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 | [ "FPGAFTM_CONTROL" ],
|
---|
40 | [ "FAD_CONTROL" ],
|
---|
41 | ];
|
---|
42 | if (!checkStates(table, 3000))
|
---|
43 | throw new Error("Either MCP, FPGAFTM_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 | if (dim.state("FTM_CONTROL").name.indexOf("Config")==0)
|
---|
58 | dim.send("FTM_CONTROL/RESET_CONFIGURE");
|
---|
59 |
|
---|
60 | console.out("Checking status of servers...");
|
---|
61 |
|
---|
62 | var table =
|
---|
63 | [
|
---|
64 | [ "MCP", [ "Idle", "Connected" ]],
|
---|
65 | [ "FTM_CONTROL", [ "Valid" ] ],
|
---|
66 | [ "FPGAFTM_CONTROL", [ "Valid" ] ],
|
---|
67 | [ "FAD_CONTROL", [ "Disengaged", "Disconnected", "Connecting", "Connected" ] ],
|
---|
68 | ];
|
---|
69 | if (!checkStates(table, 3000, true))
|
---|
70 | throw new Error("Either MCP, FTM_CONTROL, FPGAFTM_CONTROL or FAD_CONTROL not in a state in which it ought to be.");
|
---|
71 |
|
---|
72 | // FTUs must be switched off
|
---|
73 |
|
---|
74 | console.out("Disable FTUs...");
|
---|
75 |
|
---|
76 | //checkSend(["FTM_CONTROL"]);
|
---|
77 | dim.send("FTM_CONTROL/ENABLE_FTU", -1, false);
|
---|
78 | v8.sleep(1000);
|
---|
79 |
|
---|
80 | // Boards in the crates must be disconnected
|
---|
81 |
|
---|
82 | //checkSend(["FAD_CONTROL"]);
|
---|
83 |
|
---|
84 | dim.log("Disconnecting crates.");
|
---|
85 |
|
---|
86 | if (dim.state("FAD_CONTROL").name=="Connecting" || dim.state("FAD_CONTROL").name=="Connected")
|
---|
87 | for (var i=0; i<10; i++)
|
---|
88 | {
|
---|
89 | for (var j=0; j<4; j++)
|
---|
90 | if (crate[j])
|
---|
91 | {
|
---|
92 | console.out("Sending DISCONNECT "+(j*10+i));
|
---|
93 | dim.send("FAD_CONTROL/DISCONNECT", j*10+i);
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | v8.sleep(2000);
|
---|
98 | if (!checkStates([[ "FAD_CONTROL", [ "Disengaged", "Disconnected", "Connected" ] ]]))
|
---|
99 | throw new Error("FAD_CONTROL neither Disengaged, Disconnected not Connected.");
|
---|
100 |
|
---|
101 |
|
---|
102 | // Reset crates
|
---|
103 |
|
---|
104 | dim.log("Sending reset.");
|
---|
105 | dim.send("FTM_CONTROL/FAD_RESET");
|
---|
106 | /*
|
---|
107 | if (cnt==4)
|
---|
108 | dim.send("FTM_CONTROL/RESET_CAMERA");
|
---|
109 | else
|
---|
110 | {
|
---|
111 | for (var i=0; i<4; i++)
|
---|
112 | if (crate[i])
|
---|
113 | {
|
---|
114 | console.out("Sending RESET_CRATE "+i);
|
---|
115 | dim.send("FTM_CONTROL/RESET_CRATE", i);
|
---|
116 | }
|
---|
117 | }
|
---|
118 | */
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 | // We have to wait a bit
|
---|
123 |
|
---|
124 | v8.sleep(3200);
|
---|
125 |
|
---|
126 | // Reconnect all boards
|
---|
127 |
|
---|
128 | dim.log("Waiting for connection.");
|
---|
129 |
|
---|
130 | if (dim.state("FAD_CONTROL").name=="Disengaged")
|
---|
131 | {
|
---|
132 | dim.send("Waiting 38s for crates to finish reset.");
|
---|
133 | v8.sleep(38000);
|
---|
134 | dim.send("FAD_CONTROL", "START");
|
---|
135 | }
|
---|
136 | else
|
---|
137 | for (var i=0; i<10; i++)
|
---|
138 | {
|
---|
139 | v8.sleep(3200);
|
---|
140 | for (var j=0; j<4; j++)
|
---|
141 | if (crate[j])
|
---|
142 | {
|
---|
143 | console.out("Sending CONNECT "+(j*10+i));
|
---|
144 | dim.send("FAD_CONTROL/CONNECT", j*10+i);
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | // Reconnect all FTUs
|
---|
150 |
|
---|
151 | console.out("Enable FTUs...");
|
---|
152 |
|
---|
153 | v8.sleep(1000);
|
---|
154 | dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
|
---|
155 | v8.sleep(3000);
|
---|
156 | dim.send("FTM_CONTROL/PING");
|
---|
157 | v8.sleep(1000);
|
---|
158 |
|
---|
159 | dim.wait("FAD_CONTROL", "Connected", 3000);
|
---|
160 |
|
---|
161 | // Done
|
---|
162 |
|
---|
163 | dim.log("Crate reset finished.");
|
---|
164 | }
|
---|