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